]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Remove last remaining legacy functions and fdc_table dregs
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 31 Dec 2009 04:07:20 +0000 (17:07 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 31 Dec 2009 04:07:20 +0000 (17:07 +1300)
src/comm.cc
src/comm/ListenStateData.cc
src/comm/ListenStateData.h

index 5a297df815c1766d49ec09d7c8fa0d4b77bbf140..349248835483bf14cba9ec885ef773f5007b1fba 100644 (file)
@@ -1522,9 +1522,6 @@ _comm_close(int fd, char const *file, int line)
         commio_finish_callback(fd, COMMIO_FD_READCB(fd), COMM_ERR_CLOSING, errno);
     }
 
-    // Listening FD need to be closed by deleting their ListenStateData object.
-    assert(Comm::CurrentListenerSockets[fd] == NULL);
-
     commCallCloseHandlers(fd);
 
     if (F->pconn.uses)
@@ -1837,9 +1834,6 @@ comm_init(void)
     fd_table =(fde *) xcalloc(Squid_MaxFD, sizeof(fde));
     fdd_table = (fd_debug_t *)xcalloc(Squid_MaxFD, sizeof(fd_debug_t));
 
-    /* make sure we have an empty listening socket map */
-    Comm::CurrentListenerSockets.clear();
-
     /* make sure the accept() socket FIFO delay queue exists */
     Comm::AcceptLimiter::Instance();
 
@@ -1871,7 +1865,6 @@ comm_exit(void)
 
     safe_free(fd_table);
     safe_free(fdd_table);
-    Comm::CurrentListenerSockets.clear();
     safe_free(commfd_table);
 }
 
index 9d8dd0693f5eed01f732812e918e1e728275b204..7fca3f673b67ce86cac41575ef232574dc2311fc 100644 (file)
 #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
  *
@@ -66,52 +48,37 @@ std::map<int, Comm::ListenStateData*> Comm::CurrentListenerSockets;
  * 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) :
@@ -122,20 +89,12 @@ Comm::ListenStateData::ListenStateData(int aFd, AsyncCall::Pointer &call, bool a
     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;
 }
@@ -251,8 +210,8 @@ Comm::ListenStateData::notify(int newfd, comm_err_t errcode, int xerrno, const C
 
 /**
  * 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)
 {
index f43997eeea71e1cfe2383328c941856eb91ebc58..a349d648b156fedd370db00bb155dc945dfb3f9f 100644 (file)
@@ -45,13 +45,9 @@ private:
 
     AsyncCall::Pointer theCallback;
     bool mayAcceptMore;
-};
-
-extern std::map<int,ListenStateData*> CurrentListenerSockets;
 
-// remaining legacy functions. TODO replace all uses with the ListenData constructor
-extern int comm_listen(int fd);
-extern ListenStateData *comm_accept(int fd, IOACB *handler, void *handler_data);
+    void setListen();
+};
 
 }; // namespace Comm