De-duplicate UDP socket listening dialers === modified file 'src/comm/Makefile.am' --- src/comm/Makefile.am 2011-08-17 23:59:03 +0000 +++ src/comm/Makefile.am 2012-03-24 01:15:06 +0000 @@ -23,6 +23,7 @@ ModSelectWin32.cc \ TcpAcceptor.cc \ TcpAcceptor.h \ + UdpOpenDialer.h \ Write.cc \ Write.h \ \ === added file 'src/comm/UdpOpenDialer.h' --- src/comm/UdpOpenDialer.h 1970-01-01 00:00:00 +0000 +++ src/comm/UdpOpenDialer.h 2012-03-24 00:58:29 +0000 @@ -0,0 +1,27 @@ +#ifndef SQUID_COMM_UDPOPENDIALER_H +#define SQUID_COMM_UDPOPENDIALER_H + +#include "ipc/StartListening.h" + +namespace Comm +{ + +/// dials a UDP port-opened call +class UdpOpenDialer: public CallDialer, + public Ipc::StartListeningCb +{ +public: + typedef void (*Handler)((const Comm::ConnectionPointer &conn, int errNo); + UdpOpenDialer(Handler aHandler): handler(aHandler) {} + + virtual void print(std::ostream &os) const { startPrint(os) << ')'; } + virtual bool canDial(AsyncCall &) const { return true; } + virtual void dial(AsyncCall &) { (handler)(conn, errNo); } + +public: + Handler handler; +}; + +} // namespace Comm + +#endif /* SQUID_COMM_UDPOPENDIALER_H */ === modified file 'src/htcp.cc' --- src/htcp.cc 2012-01-20 18:55:04 +0000 +++ src/htcp.cc 2012-03-24 01:04:56 +0000 @@ -39,11 +39,11 @@ #include "acl/Acl.h" #include "comm.h" #include "comm/Loops.h" +#include "comm/UdpOpenDialer.h" #include "htcp.h" #include "http.h" #include "HttpRequest.h" #include "icmp/net_db.h" -#include "ipc/StartListening.h" #include "ip/tools.h" #include "MemBuf.h" #include "SquidTime.h" @@ -52,22 +52,6 @@ #include "StoreClient.h" #include "compat/xalloc.h" -/// dials htcpIncomingConnectionOpened call -class HtcpListeningStartedDialer: public CallDialer, - public Ipc::StartListeningCb -{ -public: - typedef void (*Handler)(int errNo); - HtcpListeningStartedDialer(Handler aHandler): handler(aHandler) {} - - virtual void print(std::ostream &os) const { startPrint(os) << ')'; } - virtual bool canDial(AsyncCall &) const { return true; } - virtual void dial(AsyncCall &) { (handler)(errNo); } - -public: - Handler handler; -}; - typedef struct _Countstr Countstr; typedef struct _htcpHeader htcpHeader; @@ -246,7 +230,7 @@ RR_RESPONSE }; -static void htcpIncomingConnectionOpened(int errNo); +static void htcpIncomingConnectionOpened(const Comm::ConnectionPointer &conn, int errNo); static uint32_t msg_id_counter = 0; static Comm::ConnectionPointer htcpOutgoingConn = NULL; @@ -1507,7 +1491,7 @@ AsyncCall::Pointer call = asyncCall(31, 2, "htcpIncomingConnectionOpened", - HtcpListeningStartedDialer(&htcpIncomingConnectionOpened)); + Comm::UdpOpenDialer(&htcpIncomingConnectionOpened)); Ipc::StartListening(SOCK_DGRAM, IPPROTO_UDP, @@ -1546,17 +1530,17 @@ } static void -htcpIncomingConnectionOpened(int) +htcpIncomingConnectionOpened(const Comm::ConnectionPointer &conn, int) { - if (!Comm::IsConnOpen(htcpIncomingConn)) + if (!Comm::IsConnOpen(conn)) fatal("Cannot open HTCP Socket"); - Comm::SetSelect(htcpIncomingConn->fd, COMM_SELECT_READ, htcpRecv, NULL, 0); + Comm::SetSelect(conn->fd, COMM_SELECT_READ, htcpRecv, NULL, 0); - debugs(31, DBG_CRITICAL, "Accepting HTCP messages on " << htcpIncomingConn->local); + debugs(31, DBG_CRITICAL, "Accepting HTCP messages on " << conn->local); if (Config.Addrs.udp_outgoing.IsNoAddr()) { - htcpOutgoingConn = htcpIncomingConn; + htcpOutgoingConn = conn; debugs(31, DBG_IMPORTANT, "Sending HTCP messages from " << htcpOutgoingConn->local); } } === modified file 'src/icp_v2.cc' --- src/icp_v2.cc 2012-01-20 18:55:04 +0000 +++ src/icp_v2.cc 2012-03-24 01:05:56 +0000 @@ -38,9 +38,10 @@ #include "squid-old.h" #include "Store.h" #include "comm.h" +#include "comm/Connection.h" #include "comm/Loops.h" +#include "comm/UdpOpenDialer.h" #include "ICP.h" -#include "comm/Connection.h" #include "HttpRequest.h" #include "acl/FilledChecklist.h" #include "acl/Acl.h" @@ -52,28 +53,10 @@ #include "icmp/net_db.h" #include "ip/Address.h" #include "ip/tools.h" -#include "ipc/StartListening.h" #include "ipcache.h" #include "rfc1738.h" -/// dials icpIncomingConnectionOpened call -class IcpListeningStartedDialer: public CallDialer, - public Ipc::StartListeningCb -{ -public: - typedef void (*Handler)(int errNo); - IcpListeningStartedDialer(Handler aHandler): - handler(aHandler) {} - - virtual void print(std::ostream &os) const { startPrint(os) << ')'; } - virtual bool canDial(AsyncCall &) const { return true; } - virtual void dial(AsyncCall &) { (handler)(errNo); } - -public: - Handler handler; -}; - -static void icpIncomingConnectionOpened(int errNo); +static void icpIncomingConnectionOpened(const Comm::ConnectionPointer &conn, int errNo); /// \ingroup ServerProtocolICPInternal2 static void icpLogIcp(const Ip::Address &, log_type, int, const char *, int); @@ -696,7 +679,7 @@ AsyncCall::Pointer call = asyncCall(12, 2, "icpIncomingConnectionOpened", - IcpListeningStartedDialer(&icpIncomingConnectionOpened)); + Comm::UdpOpenDialer(&icpIncomingConnectionOpened)); Ipc::StartListening(SOCK_DGRAM, IPPROTO_UDP, @@ -732,22 +715,22 @@ } static void -icpIncomingConnectionOpened(int errNo) +icpIncomingConnectionOpened(const Comm::ConnectionPointer &conn, int errNo) { - if (!Comm::IsConnOpen(icpIncomingConn)) + if (!Comm::IsConnOpen(conn)) fatal("Cannot open ICP Port"); - Comm::SetSelect(icpIncomingConn->fd, COMM_SELECT_READ, icpHandleUdp, NULL, 0); + Comm::SetSelect(conn->fd, COMM_SELECT_READ, icpHandleUdp, NULL, 0); for (const wordlist *s = Config.mcast_group_list; s; s = s->next) - ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL); // XXX: pass the icpIncomingConn for mcastJoinGroups usage. - - debugs(12, DBG_IMPORTANT, "Accepting ICP messages on " << icpIncomingConn->local); - - fd_note(icpIncomingConn->fd, "Incoming ICP port"); + ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL); // XXX: pass the conn for mcastJoinGroups usage. + + debugs(12, DBG_IMPORTANT, "Accepting ICP messages on " << conn->local); + + fd_note(conn->fd, "Incoming ICP port"); if (Config.Addrs.udp_outgoing.IsNoAddr()) { - icpOutgoingConn = icpIncomingConn; + icpOutgoingConn = conn; debugs(12, DBG_IMPORTANT, "Sending ICP messages from " << icpOutgoingConn->local); } } === modified file 'src/snmp_core.cc' --- src/snmp_core.cc 2012-01-20 18:55:04 +0000 +++ src/snmp_core.cc 2012-03-24 01:08:14 +0000 @@ -41,28 +41,8 @@ #include "snmp_core.h" #include "snmp/Forwarder.h" - -/// dials snmpConnectionOpened call -class SnmpListeningStartedDialer: public CallDialer, - public Ipc::StartListeningCb -{ -public: - typedef void (*Handler)(const Comm::ConnectionPointer &conn, int errNo); - SnmpListeningStartedDialer(Handler aHandler): handler(aHandler) {} - - virtual void print(std::ostream &os) const { startPrint(os) << ')'; } - - virtual bool canDial(AsyncCall &) const { return true; } - virtual void dial(AsyncCall &) { (handler)(conn, errNo); } - -public: - Handler handler; -}; - - static void snmpPortOpened(const Comm::ConnectionPointer &conn, int errNo); - mib_tree_entry *mib_tree_head; mib_tree_entry *mib_tree_last; @@ -308,7 +288,7 @@ } AsyncCall::Pointer call = asyncCall(49, 2, "snmpIncomingConnectionOpened", - SnmpListeningStartedDialer(&snmpPortOpened)); + Comm::UdpOpenDialer(&snmpPortOpened)); Ipc::StartListening(SOCK_DGRAM, IPPROTO_UDP, snmpIncomingConn, Ipc::fdnInSnmpSocket, call); if (!Config.Addrs.snmp_outgoing.IsNoAddr()) { @@ -325,7 +305,7 @@ snmpOutgoingConn->local.SetIPv4(); } AsyncCall::Pointer call = asyncCall(49, 2, "snmpOutgoingConnectionOpened", - SnmpListeningStartedDialer(&snmpPortOpened)); + Comm::UdpOpenDialer(&snmpPortOpened)); Ipc::StartListening(SOCK_DGRAM, IPPROTO_UDP, snmpOutgoingConn, Ipc::fdnOutSnmpSocket, call); } else { snmpOutgoingConn = snmpIncomingConn;