#include "fde.h"
#include "SquidTime.h"
-/*
- * This is not strictly needed at all.
- * It's only needed by the cachemgr interface to list the currently active sockets.
- * which could be done for HTTP/HTTPS by listing the http_port_list->listener->fd
- * BUT, FTP data connections is a bit of a problem.
- *
- * AYJ: for now the old way of doing Comm:: actions sequentially in some caller
- * requires this to anchor each of those Comm:: functions together.
- */
-std::map<int, Comm::ListenStateData*> Comm::CurrentListenerSockets;
-
-/**
- * Set of listener sockets which are known to have events pending but we
- * do not have enough sockets available to do the accept just yet.
- */
-//std::list<Comm::ListenStateData*> Comm::PendingAccepts;
-
-
/**
* New-style listen and accept routines
*
* and accept takes a callback to call when an FD has been
* accept()ed.
*/
-int
-Comm::comm_listen(int sock)
+void
+Comm::ListenStateData::setListen()
{
int x;
- if ((x = listen(sock, Squid_MaxFD >> 2)) < 0) {
- debugs(50, 0, HERE << "listen(" << (Squid_MaxFD >> 2) << ", " << sock << "): " << xstrerror());
- return x;
+ if ((x = listen(fd, Squid_MaxFD >> 2)) < 0) {
+ debugs(50, 0, HERE << "listen(FD " << fd << ", " << (Squid_MaxFD >> 2) << "): " << xstrerror());
+ errcode = x;
+ return;
}
if (Config.accept_filter && strcmp(Config.accept_filter, "none") != 0) {
#ifdef SO_ACCEPTFILTER
struct accept_filter_arg afa;
bzero(&afa, sizeof(afa));
- debugs(5, DBG_IMPORTANT, "Installing accept filter '" << Config.accept_filter << "' on FD " << sock);
+ debugs(5, DBG_IMPORTANT, "Installing accept filter '" << Config.accept_filter << "' on FD " << fd);
xstrncpy(afa.af_name, Config.accept_filter, sizeof(afa.af_name));
- x = setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa));
+ x = setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa));
if (x < 0)
debugs(5, DBG_CRITICAL, "SO_ACCEPTFILTER '" << Config.accept_filter << "': '" << xstrerror());
#elif defined(TCP_DEFER_ACCEPT)
int seconds = 30;
if (strncmp(Config.accept_filter, "data=", 5) == 0)
seconds = atoi(Config.accept_filter + 5);
- x = setsockopt(sock, IPPROTO_TCP, TCP_DEFER_ACCEPT, &seconds, sizeof(seconds));
+ x = setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &seconds, sizeof(seconds));
if (x < 0)
debugs(5, DBG_CRITICAL, "TCP_DEFER_ACCEPT '" << Config.accept_filter << "': '" << xstrerror());
#else
debugs(5, DBG_CRITICAL, "accept_filter not supported on your OS");
#endif
}
-
- return sock;
-}
-
-// TODO make this a constructor of ListenStateData...
-// better yet convert the places its used to setup AsyncCalls instead...
-Comm::ListenStateData *
-Comm::comm_accept(int fd, IOACB *handler, void *handler_data)
-{
- debugs(5, 5, HERE << "FD " << fd << " handler: " << (void*)handler);
- assert(isOpen(fd));
-
- AsyncCall::Pointer call = commCbCall(5,5, "SomeCommAcceptHandler",
- CommAcceptCbPtrFun(handler, handler_data));
-
- return new Comm::ListenStateData(fd, call, false);
}
Comm::ListenStateData::ListenStateData(int aFd, AsyncCall::Pointer &call, bool accept_many) :
assert(aFd >= 0);
debugs(5, 5, HERE << "FD " << fd << " AsyncCall: " << call);
assert(isOpen(aFd));
-
- CurrentListenerSockets[fd] = this;
-
- errcode = comm_listen(fd);
+ setListen();
commSetSelect(fd, COMM_SELECT_READ, doAccept, this, 0);
}
Comm::ListenStateData::~ListenStateData()
{
- // un-register listener before closing the FD.
- // TODO: is this the right way to remove from a std::map<> ?
- if (CurrentListenerSockets[fd])
- CurrentListenerSockets[fd] = NULL;
-
comm_close(fd);
fd = -1;
}
/**
* accept() and process
- * Wait for an incoming connection on FD. FD should be a socket returned
- * from comm_listen. */
+ * Wait for an incoming connection on FD.
+ */
int
Comm::ListenStateData::oldAccept(ConnectionDetail &details)
{