------------------------------------------------------------ revno: 13254 revision-id: squid3@treenet.co.nz-20140119053955-f95i5e5lzmdpfc0v parent: squid3@treenet.co.nz-20140119052017-tmes617hln0tkbk7 committer: Amos Jeffries branch nick: trunk timestamp: Sat 2014-01-18 21:39:55 -0800 message: Revert rev.13253 - fuba ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20140119053955-f95i5e5lzmdpfc0v # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: 6e8332889eb7df9f7460bf76a6aca1ea162ec9a6 # timestamp: 2014-01-31 06:53:47 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20140119052017-\ # tmes617hln0tkbk7 # # Begin patch === modified file 'src/comm.cc' --- src/comm.cc 2014-01-19 05:20:17 +0000 +++ src/comm.cc 2014-01-19 05:39:55 +0000 @@ -426,28 +426,22 @@ int flags, const char *note) { - // XXX: temporary for the transition to Comm::Pointer - Comm::ConnectionPointer conn = new Comm::Connection(); - const int sock = comm_openex(sock_type, proto, conn, flags, 0, 0, note); - conn->fd = -1; // prevent Comm::Connection closing the FD on destruct - return sock; + return comm_openex(sock_type, proto, addr, flags, 0, 0, note); } void comm_open_listener(int sock_type, int proto, - const Comm::ConnectionPointer &conn, + Comm::ConnectionPointer &conn, const char *note) { /* all listener sockets require bind() */ conn->flags |= COMM_DOBIND; /* attempt native enabled port. */ - conn->fd = comm_openex(sock_type, proto, conn, conn->flags, 0, 0, note); - // XXX: remove the flags parameter to comm_openex() + conn->fd = comm_openex(sock_type, proto, conn->local, conn->flags, 0, 0, note); } -// XXX: remove this wrapper int comm_open_listener(int sock_type, int proto, @@ -455,13 +449,14 @@ int flags, const char *note) { + int sock = -1; + /* all listener sockets require bind() */ flags |= COMM_DOBIND; - // XXX: temporary for the transition to Comm::Pointer - Comm::ConnectionPointer conn = new Comm::Connection(); - const int sock = comm_openex(sock_type, proto, conn, flags, 0, 0, note); - conn->fd = -1; // prevent Comm::Connection closing the FD on destruct + /* attempt native enabled port. */ + sock = comm_openex(sock_type, proto, addr, flags, 0, 0, note); + return sock; } @@ -533,12 +528,13 @@ int comm_openex(int sock_type, int proto, - const Comm::ConnectionPointer &conn, + Ip::Address &addr, int flags, tos_t tos, nfmark_t nfmark, const char *note) { + int new_socket; struct addrinfo *AI = NULL; PROF_start(comm_open); @@ -546,28 +542,29 @@ ++ statCounter.syscalls.sock.sockets; /* Setup the socket addrinfo details for use */ - conn->local.getAddrInfo(AI); + addr.getAddrInfo(AI); AI->ai_socktype = sock_type; AI->ai_protocol = proto; - debugs(50, 3, "Attempt open " << note << " socket for: " << conn); + debugs(50, 3, "comm_openex: Attempt open socket for: " << addr ); - conn->fd = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); + new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); /* under IPv6 there is the possibility IPv6 is present but disabled. */ /* try again as IPv4-native if possible */ - if (conn->fd < 0 && Ip::EnableIpv6 && conn->local.isIPv6() && conn->local.setIPv4()) { + if ( new_socket < 0 && Ip::EnableIpv6 && addr.isIPv6() && addr.setIPv4() ) { /* attempt to open this IPv4-only. */ Ip::Address::FreeAddrInfo(AI); /* Setup the socket addrinfo details for use */ - conn->local.getAddrInfo(AI); + addr.getAddrInfo(AI); AI->ai_socktype = sock_type; AI->ai_protocol = proto; - debugs(50, 3, "Attempt fallback open " << note << " socket for: " << conn); - conn->fd = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); + debugs(50, 3, "comm_openex: Attempt fallback open socket for: " << addr ); + new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); + debugs(50, 2, HERE << "attempt open " << note << " socket on: " << addr); } - if (conn->fd < 0) { + if (new_socket < 0) { /* Increase the number of reserved fd's if calls to socket() * are failing because the open file table is full. This * limits the number of simultaneous clients */ @@ -585,7 +582,12 @@ return -1; } - debugs(50, 3, "Opened socket " << conn << " : family=" << AI->ai_family << ", type=" << AI->ai_socktype << ", protocol=" << AI->ai_protocol); + // XXX: temporary for the transition. comm_openex will eventually have a conn to play with. + Comm::ConnectionPointer conn = new Comm::Connection; + conn->local = addr; + conn->fd = new_socket; + + debugs(50, 3, "comm_openex: Opened socket " << conn << " : family=" << AI->ai_family << ", type=" << AI->ai_socktype << ", protocol=" << AI->ai_protocol ); /* set TOS if needed */ if (tos) @@ -595,26 +597,24 @@ if (nfmark) Ip::Qos::setSockNfmark(conn, nfmark); - if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && conn->local.isIPv6()) + if ( Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && addr.isIPv6() ) comm_set_v6only(conn->fd, 1); /* Windows Vista supports Dual-Sockets. BUT defaults them to V6ONLY. Turn it OFF. */ /* Other OS may have this administratively disabled for general use. Same deal. */ - if (Ip::EnableIpv6&IPV6_SPECIAL_V4MAPPING && conn->local.isIPv6()) + if ( Ip::EnableIpv6&IPV6_SPECIAL_V4MAPPING && addr.isIPv6() ) comm_set_v6only(conn->fd, 0); comm_init_opened(conn, tos, nfmark, note, AI); - conn->fd = comm_apply_flags(conn->fd, conn->local, flags, AI); - - // XXX: does AI contain the new local port number ?? - conn->local = *AI; - debugs(50, 3, "New Socket details: " << conn); + new_socket = comm_apply_flags(conn->fd, addr, flags, AI); Ip::Address::FreeAddrInfo(AI); PROF_stop(comm_open); - return conn->fd; + // XXX transition only. prevent conn from closing the new FD on function exit. + conn->fd = -1; + return new_socket; } /// update FD tables after a local or remote (IPC) comm_openex(); === modified file 'src/comm.h' --- src/comm.h 2014-01-19 05:20:17 +0000 +++ src/comm.h 2014-01-19 05:39:55 +0000 @@ -49,9 +49,9 @@ * A reconfigure is needed to reset the stored IP in most cases and attempt a port re-open. */ int comm_open_listener(int sock_type, int proto, Ip::Address &addr, int flags, const char *note); -void comm_open_listener(int sock_type, int proto, const Comm::ConnectionPointer &conn, const char *note); +void comm_open_listener(int sock_type, int proto, Comm::ConnectionPointer &conn, const char *note); -int comm_openex(int, int, const Comm::ConnectionPointer &, int, tos_t tos, nfmark_t nfmark, const char *); +int comm_openex(int, int, Ip::Address &, int, tos_t tos, nfmark_t nfmark, const char *); unsigned short comm_local_port(int fd); int comm_udp_sendto(int sock, const Ip::Address &to, const void *buf, int buflen); === modified file 'src/comm/ConnOpener.cc' --- src/comm/ConnOpener.cc 2014-01-19 05:20:17 +0000 +++ src/comm/ConnOpener.cc 2014-01-19 05:39:55 +0000 @@ -255,7 +255,7 @@ if (callback_ == NULL || callback_->canceled()) return false; - temporaryFd_ = comm_openex(SOCK_STREAM, IPPROTO_TCP, conn_, conn_->flags, conn_->tos, conn_->nfmark, host_); + temporaryFd_ = comm_openex(SOCK_STREAM, IPPROTO_TCP, conn_->local, conn_->flags, conn_->tos, conn_->nfmark, host_); if (temporaryFd_ < 0) { sendAnswer(COMM_ERR_CONNECT, 0, "Comm::ConnOpener::createFd"); return false; === modified file 'src/ftp.cc' --- src/ftp.cc 2014-01-19 05:20:17 +0000 +++ src/ftp.cc 2014-01-19 05:39:55 +0000 @@ -636,13 +636,11 @@ /* open the conn if its not already open */ if (!Comm::IsConnOpen(conn)) { - comm_open_listener(SOCK_STREAM, IPPROTO_TCP, conn, note); + conn->fd = comm_open_listener(SOCK_STREAM, IPPROTO_TCP, conn->local, conn->flags, note); if (!Comm::IsConnOpen(conn)) { debugs(5, DBG_CRITICAL, HERE << "comm_open_listener failed:" << conn->local << " error: " << errno); return; } -// XXX: for the 3.3 workaround try grabbing the IP:port from fd_table where comm should have put it. - assert(conn->local.port() != 0); debugs(9, 3, HERE << "Unconnected data socket created on " << conn); }