TS-1067 Remove the UDPWorkContinuation code
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/f8a6791b Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/f8a6791b Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/f8a6791b Branch: refs/heads/3.3.x Commit: f8a6791be894ae8b1db6ce41a31b5e9fbc7a90f2 Parents: 9bb4afb Author: Leif Hedstrom <zw...@apache.org> Authored: Tue Mar 26 08:39:06 2013 -0600 Committer: Leif Hedstrom <zw...@apache.org> Committed: Tue Apr 2 13:52:33 2013 -0600 ---------------------------------------------------------------------- iocore/net/I_UDPConnection.h | 9 +- iocore/net/I_UDPNet.h | 8 -- iocore/net/P_UDPNet.h | 34 ------- iocore/net/UnixUDPNet.cc | 199 ------------------------------------- 4 files changed, 4 insertions(+), 246 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f8a6791b/iocore/net/I_UDPConnection.h ---------------------------------------------------------------------- diff --git a/iocore/net/I_UDPConnection.h b/iocore/net/I_UDPConnection.h index ab55181..045f376 100644 --- a/iocore/net/I_UDPConnection.h +++ b/iocore/net/I_UDPConnection.h @@ -97,12 +97,11 @@ public: /** Put socket on net queue for read/write polling. - Not required for UDPConnections created with - UDPNetProcessor::UDPBind + Not required for UDPConnections created with UDPNetProcessor::UDPBind - Required for UDPNetProcessor::UDPCreatePortPairs and - UDPNetProcessor::CreateUDPSocket. They don't do bindToThread() - automatically so that the sockets can be passed to other Continuations. + Required for and UDPNetProcessor::CreateUDPSocket. They don't do + bindToThread() automatically so that the sockets can be passed to + other Continuations. */ void bindToThread(Continuation * c); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f8a6791b/iocore/net/I_UDPNet.h ---------------------------------------------------------------------- diff --git a/iocore/net/I_UDPNet.h b/iocore/net/I_UDPNet.h index d9dc38b..5497fbd 100644 --- a/iocore/net/I_UDPNet.h +++ b/iocore/net/I_UDPNet.h @@ -84,14 +84,6 @@ public: // The mess again: the complier won't let me stick UDPConnection here. void UDPClassifyConnection(Continuation * udpConn, IpAddr const& addr); - // create pairs of UDPConnections in which the first connection is - // on a even-#'ed port and the second connection is on the next - // odd-#'ed port. Create "nPairs" of such connections. - Action *UDPCreatePortPairs(Continuation *, int nPairs, - sockaddr const* local_addr, - sockaddr const* remote_addr, - int send_bufsize = 0, int recv_bufsize = 0); - // Regarding sendto_re, sendmsg_re, recvfrom_re: // * You may be called back on 'c' with completion or error status. // * 'token' is an opaque which can be used by caller to match up the I/O http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f8a6791b/iocore/net/P_UDPNet.h ---------------------------------------------------------------------- diff --git a/iocore/net/P_UDPNet.h b/iocore/net/P_UDPNet.h index 8a3cfb8..31a2492 100644 --- a/iocore/net/P_UDPNet.h +++ b/iocore/net/P_UDPNet.h @@ -386,38 +386,4 @@ struct InkPipeInfo extern InkPipeInfo G_inkPipeInfo; -class UDPWorkContinuation:public Continuation -{ -public: - UDPWorkContinuation():cont(NULL), numPairs(0), - sendbufsize(0), recvbufsize(0), udpConns(NULL), resultCode(NET_EVENT_DATAGRAM_OPEN) - { - memset(&local_ip, 0, sizeof(local_ip)); - memset(&remote_ip, 0, sizeof(remote_ip)); - }; - ~UDPWorkContinuation() { - }; - void init(Continuation * c, int num_pairs, - sockaddr const* local_ip, - sockaddr const* remote_ip, - int s_bufsize, int r_bufsize); - int StateCreatePortPairs(int event, void *data); - int StateDoCallback(int event, void *data); - - Action action; - -private: - Continuation * cont; - int numPairs; - IpEndpoint local_ip; ///< replaces myIP. - IpEndpoint remote_ip; ///< replaces destIP. - int sendbufsize, recvbufsize; - UnixUDPConnection **udpConns; - int resultCode; -}; - -typedef int (UDPWorkContinuation::*UDPWorkContinuation_Handler) (int, void *); - -inkcoreapi extern ClassAllocator<UDPWorkContinuation> udpWorkContinuationAllocator; - #endif //__P_UDPNET_H_ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f8a6791b/iocore/net/UnixUDPNet.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixUDPNet.cc b/iocore/net/UnixUDPNet.cc index 73dc0f6..79dd8da 100644 --- a/iocore/net/UnixUDPNet.cc +++ b/iocore/net/UnixUDPNet.cc @@ -35,9 +35,6 @@ typedef int (UDPNetHandler::*UDPNetContHandler) (int, void *); inkcoreapi ClassAllocator<UDPPacketInternal> udpPacketAllocator("udpPacketAllocator"); - -inkcoreapi ClassAllocator<UDPWorkContinuation> udpWorkContinuationAllocator("udpWorkContinuationAllocator"); - EventType ET_UDP; #if defined(linux) && !defined(DEBUG) @@ -514,23 +511,6 @@ UDPNetProcessor::sendto_re(Continuation * cont, } } -Action * -UDPNetProcessor::UDPCreatePortPairs( - Continuation * cont, - int nPairs, - sockaddr const* local_addr, - sockaddr const* remote_addr, - int send_bufsize, int recv_bufsize -) { - - UDPWorkContinuation *worker = udpWorkContinuationAllocator.alloc(); - // UDPWorkContinuation *worker = NEW(new UDPWorkContinuation); - - worker->init(cont, nPairs, local_addr, remote_addr, send_bufsize, recv_bufsize); - eventProcessor.schedule_imm(worker, ET_UDP); - return &(worker->action); -} - bool UDPNetProcessor::CreateUDPSocket( @@ -1135,182 +1115,3 @@ UDPNetHandler::mainNetEvent(int event, Event * e) return EVENT_CONT; } - -///////////////////////////////////////////////////////////////////// -// -// A helper continuation that creates a pair of UDP ports in a non-blocking -// way. This continuation runs on the UDP thread; a run lasts for at most 500ms. -// -///////////////////////////////////////////////////////////////////// - -void -UDPWorkContinuation::init(Continuation * c, int num_pairs, - sockaddr const* local_addr, - sockaddr const* remote_addr, - int s_bufsize, int r_bufsize -) { - mutex = c->mutex; - cont = c; - action = c; - numPairs = num_pairs; - ats_ip_copy(&local_ip, local_addr); - ats_ip_copy(&remote_ip, remote_addr); - sendbufsize = s_bufsize; - recvbufsize = r_bufsize; - udpConns = NULL; - SET_HANDLER((UDPWorkContinuation_Handler) & UDPWorkContinuation::StateCreatePortPairs); -} - -int -UDPWorkContinuation::StateCreatePortPairs(int event, void *data) -{ - NOWARN_UNUSED(event); - NOWARN_UNUSED(data); -// int res = 0; - int numUdpPorts = 2 * numPairs; - int fd1 = -1, fd2 = -1; - IpEndpoint target; - IpEndpoint myaddr1, myaddr2; - int portNum, i; -// int myaddr_len = sizeof(myaddr1); - static int lastAllocPort = 10000; - ink_hrtime startTime, endTime; - Action *status; - //epoll changes - - PollCont *pc = NULL; - //epoll changes ends here - ink_debug_assert(mutex->thread_holding == this_ethread()); - - if (action.cancelled) { - action = NULL; - mutex = NULL; - udpWorkContinuationAllocator.free(this); - return EVENT_CONT; - } - - startTime = ink_get_hrtime_internal(); - ats_ip_copy(&target, &remote_ip); - - udpConns = NEW(new UnixUDPConnection *[numUdpPorts]); - for (i = 0; i < numUdpPorts; i++) - udpConns[i] = NULL; - ink_atomic_swap(&portNum, lastAllocPort); - portNum %= 50000; - if (portNum == 0) - portNum = 10000; - - i = 0; - while (i < numUdpPorts) { - - int myaddr1_len = sizeof(myaddr1); - int myaddr2_len = sizeof(myaddr2); - ats_ip_port_cast(&target) = htons(portNum); - if (udpNet.CreateUDPSocket(&fd1, - &target.sa, - &myaddr1.sa, - &myaddr1_len, - &status, sendbufsize, recvbufsize)) { - ats_ip_port_cast(&target) = htons(portNum + 1); - if (udpNet.CreateUDPSocket(&fd2, - &target.sa, - &myaddr2.sa, - &myaddr2_len, - &status, sendbufsize, recvbufsize)) { - udpConns[i] = NEW(new UnixUDPConnection(fd1)); // new_UnixUDPConnection(fd1); - udpConns[i]->setBinding(&myaddr1.sa); - i++; - udpConns[i] = NEW(new UnixUDPConnection(fd2)); // new_UnixUDPConnection(fd2); - udpConns[i]->setBinding(&myaddr2.sa); - i++; - // remember the last alloc'ed port - ink_atomic_swap(&lastAllocPort, portNum + 2); - } else { - if (fd1 != NO_FD) - socketManager.close(fd1); - if (status == ACTION_IO_ERROR) - goto Lerror; - } - Debug("udpnet", "Created port pair with ports = %d, %d", portNum, portNum + 1); - } else if (status == ACTION_IO_ERROR) - goto Lerror; - // pick the next port pair value - portNum += 2; - // wrap around at 50K - portNum %= 50000; - if (portNum == 0) - portNum = 10000; - endTime = ink_get_hrtime_internal(); - // if we spend more than 500 ms. bail! - if (ink_hrtime_to_msec(endTime - startTime) > 500) { - status = ACTION_IO_ERROR; - goto Lerror; - } - - } - - for (i = 0; i < numUdpPorts; i++) { - udpNet.UDPClassifyConnection(udpConns[i], IpAddr(target)); - Debug("udpnet-pipe", "Adding (port = %d) to Pipe class: %d", - udpConns[i]->getPortNum(), udpConns[i]->pipe_class); - } - - // assert should *never* fire; we check for this at the begin of the func. - ink_assert(!action.cancelled); - - // Bind to threads only on a success. Currently, after you have - // bound to have a thread, the only way to remove a UDPConnection is - // to call destroy(); the thread to which the UDPConnection will - // remove the connection from a linked list and call delete. - - for (i = 0; i < numUdpPorts; i++) { - udpConns[i]->bindToThread(cont); - pc = get_UDPPollCont(udpConns[i]->ethread); - udpConns[i]->ep.start(pc->pollDescriptor, udpConns[i], EVENTIO_READ); - } - - resultCode = NET_EVENT_DATAGRAM_OPEN; - goto out; - -Lerror: - resultCode = NET_EVENT_DATAGRAM_ERROR; - for (i = 0; i < numUdpPorts; i++) - delete udpConns[i]; - delete[] udpConns; - udpConns = NULL; - -out: - SET_HANDLER((UDPWorkContinuation_Handler) & UDPWorkContinuation::StateDoCallback); - return StateDoCallback(0, NULL); -} - -int -UDPWorkContinuation::StateDoCallback(int event, void *data) -{ - NOWARN_UNUSED(event); - NOWARN_UNUSED(data); - MUTEX_TRY_LOCK(lock, action.mutex, this_ethread()); - if (!lock) { - this_ethread()->schedule_in(this, MUTEX_RETRY_DELAY); - return EVENT_CONT; - } - if (!action.cancelled) { - action.continuation->handleEvent(resultCode, udpConns); - } else { - // else action.cancelled - if (resultCode == NET_EVENT_DATAGRAM_OPEN) { - for (int i = 0; i < numPairs * 2; i++) - // don't call delete on individual connections; the udp thread will do - // that when it cleans up an fd. - udpConns[i]->destroy(); - delete[]udpConns; // I think this is OK to delete the array, what we shouldn't do is loop over - udpConns = NULL; // the conns and and do delete udpConns[i]. - } - } - - action = NULL; - mutex = NULL; - udpWorkContinuationAllocator.free(this); - - return EVENT_CONT; -}