http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/UnixNetVConnection.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc index bb46c8b..c8156e1 100644 --- a/iocore/net/UnixNetVConnection.cc +++ b/iocore/net/UnixNetVConnection.cc @@ -23,8 +23,8 @@ #include "P_Net.h" -#define STATE_VIO_OFFSET ((uintptr_t)&((NetState*)0)->vio) -#define STATE_FROM_VIO(_x) ((NetState*)(((char*)(_x)) - STATE_VIO_OFFSET)) +#define STATE_VIO_OFFSET ((uintptr_t) & ((NetState *)0)->vio) +#define STATE_FROM_VIO(_x) ((NetState *)(((char *)(_x)) - STATE_VIO_OFFSET)) #define disable_read(_vc) (_vc)->read.enabled = 0 #define disable_write(_vc) (_vc)->write.enabled = 0 @@ -32,7 +32,7 @@ #define enable_write(_vc) (_vc)->write.enabled = 1 #ifndef UIO_MAXIOV -#define NET_MAX_IOV 16 // UIO_MAXIOV shall be at least 16 1003.1g (5.4.1.1) +#define NET_MAX_IOV 16 // UIO_MAXIOV shall be at least 16 1003.1g (5.4.1.1) #else #define NET_MAX_IOV UIO_MAXIOV #endif @@ -68,7 +68,7 @@ void net_activity(UnixNetVConnection *vc, EThread *thread) { Debug("socket", "net_activity updating inactivity %" PRId64 ", NetVC=%p", vc->inactivity_timeout_in, vc); - (void) thread; + (void)thread; #ifdef INACTIVITY_TIMEOUT if (vc->inactivity_timeout && vc->inactivity_timeout_in && vc->inactivity_timeout->ethread == thread) vc->inactivity_timeout->schedule_in(vc->inactivity_timeout_in); @@ -86,7 +86,6 @@ net_activity(UnixNetVConnection *vc, EThread *thread) else vc->next_inactivity_timeout_at = 0; #endif - } // @@ -148,7 +147,7 @@ read_signal_and_update(int event, UnixNetVConnection *vc) vc->closed = 1; break; default: - Error ("Unexpected event %d for vc %p", event, vc); + Error("Unexpected event %d for vc %p", event, vc); ink_release_assert(0); break; } @@ -239,7 +238,7 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) return; } - MIOBufferAccessor & buf = s->vio.buffer; + MIOBufferAccessor &buf = s->vio.buffer; ink_assert(buf.writer()); // if there is nothing to do, disable connection @@ -295,7 +294,6 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) } // check for errors if (r <= 0) { - if (r == -EAGAIN || r == -ENOTCONN) { NET_INCREMENT_DYN_STAT(net_calls_to_read_nodata_stat); vc->read.triggered = 0; @@ -397,8 +395,8 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) if (ret == EVENT_ERROR) { vc->write.triggered = 0; write_signal_error(nh, vc, err); - } else if (ret == SSL_HANDSHAKE_WANT_READ || ret == SSL_HANDSHAKE_WANT_ACCEPT || ret == SSL_HANDSHAKE_WANT_CONNECT - || ret == SSL_HANDSHAKE_WANT_WRITE) { + } else if (ret == SSL_HANDSHAKE_WANT_READ || ret == SSL_HANDSHAKE_WANT_ACCEPT || ret == SSL_HANDSHAKE_WANT_CONNECT || + ret == SSL_HANDSHAKE_WANT_WRITE) { vc->read.triggered = 0; nh->read_ready_list.remove(vc); vc->write.triggered = 0; @@ -427,7 +425,7 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) return; } - MIOBufferAccessor & buf = s->vio.buffer; + MIOBufferAccessor &buf = s->vio.buffer; ink_assert(buf.writer()); // Calculate amount to write @@ -471,15 +469,15 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) r = total_written - wattempted + r; } // check for errors - if (r <= 0) { // if the socket was not ready,add to WaitList + if (r <= 0) { // if the socket was not ready,add to WaitList if (r == -EAGAIN || r == -ENOTCONN) { NET_INCREMENT_DYN_STAT(net_calls_to_write_nodata_stat); - if((needs & EVENTIO_WRITE) == EVENTIO_WRITE) { + if ((needs & EVENTIO_WRITE) == EVENTIO_WRITE) { vc->write.triggered = 0; nh->write_ready_list.remove(vc); write_reschedule(nh, vc); } - if((needs & EVENTIO_READ) == EVENTIO_READ) { + if ((needs & EVENTIO_READ) == EVENTIO_READ) { vc->read.triggered = 0; nh->read_ready_list.remove(vc); read_reschedule(nh, vc); @@ -535,10 +533,10 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) return; } - if((needs & EVENTIO_WRITE) == EVENTIO_WRITE) { + if ((needs & EVENTIO_WRITE) == EVENTIO_WRITE) { write_reschedule(nh, vc); } - if((needs & EVENTIO_READ) == EVENTIO_READ) { + if ((needs & EVENTIO_READ) == EVENTIO_READ) { read_reschedule(nh, vc); } return; @@ -549,18 +547,18 @@ bool UnixNetVConnection::get_data(int id, void *data) { union { - TSVIO * vio; - void * data; + TSVIO *vio; + void *data; } ptr; ptr.data = data; switch (id) { case TS_API_DATA_READ_VIO: - *ptr.vio = (TSVIO)&this->read.vio; + *ptr.vio = (TSVIO) & this->read.vio; return true; case TS_API_DATA_WRITE_VIO: - *ptr.vio = (TSVIO)&this->write.vio; + *ptr.vio = (TSVIO) & this->write.vio; return true; default: return false; @@ -577,7 +575,7 @@ UnixNetVConnection::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) read.vio._cont = c; read.vio.nbytes = nbytes; read.vio.ndone = 0; - read.vio.vc_server = (VConnection *) this; + read.vio.vc_server = (VConnection *)this; if (buf) { read.vio.buffer.writer_for(buf); if (!read.enabled) @@ -598,7 +596,7 @@ UnixNetVConnection::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader write.vio._cont = c; write.vio.nbytes = nbytes; write.vio.ndone = 0; - write.vio.vc_server = (VConnection *) this; + write.vio.vc_server = (VConnection *)this; if (reader) { ink_assert(!owner); write.vio.buffer.reader_for(reader); @@ -611,7 +609,7 @@ UnixNetVConnection::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader } void -UnixNetVConnection::do_io_close(int alerrno /* = -1 */ ) +UnixNetVConnection::do_io_close(int alerrno /* = -1 */) { disable_read(this); disable_write(this); @@ -642,21 +640,21 @@ UnixNetVConnection::do_io_shutdown(ShutdownHowTo_t howto) { switch (howto) { case IO_SHUTDOWN_READ: - socketManager.shutdown(((UnixNetVConnection *) this)->con.fd, 0); + socketManager.shutdown(((UnixNetVConnection *)this)->con.fd, 0); disable_read(this); read.vio.buffer.clear(); read.vio.nbytes = 0; f.shutdown = NET_VC_SHUTDOWN_READ; break; case IO_SHUTDOWN_WRITE: - socketManager.shutdown(((UnixNetVConnection *) this)->con.fd, 1); + socketManager.shutdown(((UnixNetVConnection *)this)->con.fd, 1); disable_write(this); write.vio.buffer.clear(); write.vio.nbytes = 0; f.shutdown = NET_VC_SHUTDOWN_WRITE; break; case IO_SHUTDOWN_READWRITE: - socketManager.shutdown(((UnixNetVConnection *) this)->con.fd, 2); + socketManager.shutdown(((UnixNetVConnection *)this)->con.fd, 2); disable_read(this); disable_write(this); read.vio.buffer.clear(); @@ -684,7 +682,7 @@ OOB_callback::retry_OOB_send(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED void UnixNetVConnection::cancel_OOB() { - UnixNetVConnection *u = (UnixNetVConnection *) this; + UnixNetVConnection *u = (UnixNetVConnection *)this; if (u->oob_ptr) { if (u->oob_ptr->trigger) { u->oob_ptr->trigger->cancel_action(); @@ -698,7 +696,7 @@ UnixNetVConnection::cancel_OOB() Action * UnixNetVConnection::send_OOB(Continuation *cont, char *buf, int len) { - UnixNetVConnection *u = (UnixNetVConnection *) this; + UnixNetVConnection *u = (UnixNetVConnection *)this; ink_assert(len > 0); ink_assert(buf); ink_assert(!u->oob_ptr); @@ -830,13 +828,11 @@ UnixNetVConnection::UnixNetVConnection() #else next_inactivity_timeout_at(0), #endif - active_timeout(NULL), nh(NULL), - id(0), flags(0), recursion(0), submit_time(0), oob_ptr(0), - from_accept_thread(false) + active_timeout(NULL), nh(NULL), id(0), flags(0), recursion(0), submit_time(0), oob_ptr(0), from_accept_thread(false) { memset(&local_addr, 0, sizeof local_addr); memset(&server_addr, 0, sizeof server_addr); - SET_HANDLER((NetVConnHandler) & UnixNetVConnection::startEvent); + SET_HANDLER((NetVConnHandler)&UnixNetVConnection::startEvent); } // Private methods @@ -871,7 +867,8 @@ UnixNetVConnection::net_read_io(NetHandler *nh, EThread *lthread) // (SSL read does not support overlapped i/o) // without duplicating all the code in write_to_net. int64_t -UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted, int64_t &total_written, MIOBufferAccessor & buf, int &needs) +UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted, int64_t &total_written, MIOBufferAccessor &buf, + int &needs) { int64_t r = 0; @@ -1003,11 +1000,11 @@ UnixNetVConnection::acceptEvent(int event, Event *e) return EVENT_DONE; } - SET_HANDLER((NetVConnHandler) & UnixNetVConnection::mainEvent); + SET_HANDLER((NetVConnHandler)&UnixNetVConnection::mainEvent); nh = get_NetHandler(thread); PollDescriptor *pd = get_PollDescriptor(thread); - if (ep.start(pd, this, EVENTIO_READ|EVENTIO_WRITE) < 0) { + if (ep.start(pd, this, EVENTIO_READ | EVENTIO_WRITE) < 0) { Debug("iocore_net", "acceptEvent : failed EventIO::start\n"); close_UnixNetVConnection(this, e->ethread); return EVENT_DONE; @@ -1039,9 +1036,8 @@ UnixNetVConnection::mainEvent(int event, Event *e) ink_assert(thread == this_ethread()); MUTEX_TRY_LOCK(hlock, get_NetHandler(thread)->mutex, e->ethread); - MUTEX_TRY_LOCK(rlock, read.vio.mutex ? (ProxyMutex *) read.vio.mutex : (ProxyMutex *) e->ethread->mutex, e->ethread); - MUTEX_TRY_LOCK(wlock, write.vio.mutex ? (ProxyMutex *) write.vio.mutex : - (ProxyMutex *) e->ethread->mutex, e->ethread); + MUTEX_TRY_LOCK(rlock, read.vio.mutex ? (ProxyMutex *)read.vio.mutex : (ProxyMutex *)e->ethread->mutex, e->ethread); + MUTEX_TRY_LOCK(wlock, write.vio.mutex ? (ProxyMutex *)write.vio.mutex : (ProxyMutex *)e->ethread->mutex, e->ethread); if (!hlock.is_locked() || !rlock.is_locked() || !wlock.is_locked() || (read.vio.mutex.m_ptr && rlock.get_mutex() != read.vio.mutex.m_ptr) || (write.vio.mutex.m_ptr && wlock.get_mutex() != write.vio.mutex.m_ptr)) { @@ -1071,8 +1067,8 @@ UnixNetVConnection::mainEvent(int event, Event *e) #else if (event == EVENT_IMMEDIATE) { /* BZ 49408 */ - //ink_assert(inactivity_timeout_in); - //ink_assert(next_inactivity_timeout_at < ink_get_hrtime()); + // ink_assert(inactivity_timeout_in); + // ink_assert(next_inactivity_timeout_at < ink_get_hrtime()); if (!inactivity_timeout_in || next_inactivity_timeout_at > ink_get_hrtime()) return EVENT_CONT; signal_event = VC_EVENT_INACTIVITY_TIMEOUT; @@ -1099,10 +1095,8 @@ UnixNetVConnection::mainEvent(int event, Event *e) return EVENT_DONE; } - if (!*signal_timeout && - !*signal_timeout_at && - !closed && write.vio.op == VIO::WRITE && - !(f.shutdown & NET_VC_SHUTDOWN_WRITE) && reader_cont != write.vio._cont && writer_cont == write.vio._cont) + if (!*signal_timeout && !*signal_timeout_at && !closed && write.vio.op == VIO::WRITE && !(f.shutdown & NET_VC_SHUTDOWN_WRITE) && + reader_cont != write.vio._cont && writer_cont == write.vio._cont) if (write_signal_and_update(signal_event, this) == EVENT_DONE) return EVENT_DONE; return EVENT_DONE; @@ -1117,7 +1111,7 @@ UnixNetVConnection::connectUp(EThread *t, int fd) thread = t; if (check_net_throttle(CONNECT, submit_time)) { check_throttle_warning(); - action_.continuation->handleEvent(NET_EVENT_OPEN_FAILED, (void *) -ENET_THROTTLING); + action_.continuation->handleEvent(NET_EVENT_OPEN_FAILED, (void *)-ENET_THROTTLING); free(t); return CONNECT_FAILURE; } @@ -1131,12 +1125,8 @@ UnixNetVConnection::connectUp(EThread *t, int fd) if (is_debug_tag_set("iocore_net")) { char addrbuf[INET6_ADDRSTRLEN]; Debug("iocore_net", "connectUp:: local_addr=%s:%d [%s]\n", - options.local_ip.isValid() - ? options.local_ip.toString(addrbuf, sizeof(addrbuf)) - : "*", - options.local_port, - NetVCOptions::toString(options.addr_binding) - ); + options.local_ip.isValid() ? options.local_ip.toString(addrbuf, sizeof(addrbuf)) : "*", options.local_port, + NetVCOptions::toString(options.addr_binding)); } // If this is getting called from the TS API, then we are wiring up a file descriptor @@ -1161,7 +1151,7 @@ UnixNetVConnection::connectUp(EThread *t, int fd) // Must connect after EventIO::Start() to avoid a race condition // when edge triggering is used. - if (ep.start(get_PollDescriptor(t), this, EVENTIO_READ|EVENTIO_WRITE) < 0) { + if (ep.start(get_PollDescriptor(t), this, EVENTIO_READ | EVENTIO_WRITE) < 0) { lerrno = errno; Debug("iocore_net", "connectUp : Failed to add to epoll list\n"); action_.continuation->handleEvent(NET_EVENT_OPEN_FAILED, (void *)0); // 0 == res @@ -1212,7 +1202,7 @@ UnixNetVConnection::free(EThread *t) read.vio.mutex.clear(); write.vio.mutex.clear(); flags = 0; - SET_CONTINUATION_HANDLER(this, (NetVConnHandler) & UnixNetVConnection::startEvent); + SET_CONTINUATION_HANDLER(this, (NetVConnHandler)&UnixNetVConnection::startEvent); nh = NULL; read.triggered = 0; write.triggered = 0;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/UnixUDPConnection.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixUDPConnection.cc b/iocore/net/UnixUDPConnection.cc index 1c6d29e..318e629 100644 --- a/iocore/net/UnixUDPConnection.cc +++ b/iocore/net/UnixUDPConnection.cc @@ -34,7 +34,7 @@ UnixUDPConnection::~UnixUDPConnection() { - UDPPacketInternal *p = (UDPPacketInternal *) ink_atomiclist_popall(&inQueue); + UDPPacketInternal *p = (UDPPacketInternal *)ink_atomiclist_popall(&inQueue); if (!tobedestroyed) tobedestroyed = 1; @@ -64,8 +64,8 @@ UnixUDPConnection::~UnixUDPConnection() int UnixUDPConnection::callbackHandler(int event, void *data) { - (void) event; - (void) data; + (void)event; + (void)data; callbackAction = NULL; if (continuation == NULL) return EVENT_CONT; @@ -73,11 +73,11 @@ UnixUDPConnection::callbackHandler(int event, void *data) if (m_errno) { if (!shouldDestroy()) continuation->handleEvent(NET_EVENT_DATAGRAM_ERROR, this); - destroy(); // don't destroy until after calling back with error + destroy(); // don't destroy until after calling back with error Release(); return EVENT_CONT; } else { - UDPPacketInternal *p = (UDPPacketInternal *) ink_atomiclist_popall(&inQueue); + UDPPacketInternal *p = (UDPPacketInternal *)ink_atomiclist_popall(&inQueue); if (p) { Debug("udpnet", "UDPConnection::callbackHandler"); UDPPacketInternal *pnext = NULL; @@ -101,10 +101,10 @@ UnixUDPConnection::callbackHandler(int event, void *data) } void -UDPConnection::bindToThread(Continuation * c) +UDPConnection::bindToThread(Continuation *c) { - UnixUDPConnection *uc = (UnixUDPConnection *) this; - //add to new connections queue for EThread. + UnixUDPConnection *uc = (UnixUDPConnection *)this; + // add to new connections queue for EThread. EThread *t = eventProcessor.assign_thread(ET_UDP); ink_assert(t); ink_assert(get_UDPNetHandler(t)); @@ -116,10 +116,10 @@ UDPConnection::bindToThread(Continuation * c) } Action * -UDPConnection::send(Continuation * c, UDPPacket * xp) +UDPConnection::send(Continuation *c, UDPPacket *xp) { - UDPPacketInternal *p = (UDPPacketInternal *) xp; - UnixUDPConnection *conn = (UnixUDPConnection *) this; + UDPPacketInternal *p = (UDPPacketInternal *)xp; + UnixUDPConnection *conn = (UnixUDPConnection *)this; if (shouldDestroy()) { ink_assert(!"freeing packet sent on dead connection"); @@ -141,7 +141,7 @@ UDPConnection::send(Continuation * c, UDPPacket * xp) void UDPConnection::Release() { - UnixUDPConnection *p = (UnixUDPConnection *) this; + UnixUDPConnection *p = (UnixUDPConnection *)this; p->ep.stop(); @@ -155,4 +155,3 @@ UDPConnection::Release() delete this; } } - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/UnixUDPNet.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixUDPNet.cc b/iocore/net/UnixUDPNet.cc index 5c6f48d..3fa449c 100644 --- a/iocore/net/UnixUDPNet.cc +++ b/iocore/net/UnixUDPNet.cc @@ -32,7 +32,7 @@ #include "P_Net.h" #include "P_UDPNet.h" -typedef int (UDPNetHandler::*UDPNetContHandler) (int, void *); +typedef int (UDPNetHandler::*UDPNetContHandler)(int, void *); inkcoreapi ClassAllocator<UDPPacketInternal> udpPacketAllocator("udpPacketAllocator"); EventType ET_UDP; @@ -62,10 +62,10 @@ int G_bwGrapherFd; sockaddr_in6 G_bwGrapherLoc; void -initialize_thread_for_udp_net(EThread * thread) +initialize_thread_for_udp_net(EThread *thread) { - new((ink_dummy_for_new *) get_UDPPollCont(thread)) PollCont(thread->mutex); - new((ink_dummy_for_new *) get_UDPNetHandler(thread)) UDPNetHandler; + new ((ink_dummy_for_new *)get_UDPPollCont(thread)) PollCont(thread->mutex); + new ((ink_dummy_for_new *)get_UDPNetHandler(thread)) UDPNetHandler; // This variable controls how often we cleanup the cancelled packets. // If it is set to 0, then cleanup never occurs. @@ -92,7 +92,7 @@ UDPNetProcessorInternal::start(int n_upd_threads, size_t stacksize) return -1; ET_UDP = eventProcessor.spawn_event_threads(n_upd_threads, "ET_UDP", stacksize); - if (ET_UDP < 0) // Probably can't happen, maybe at some point EventType should be unsigned ? + if (ET_UDP < 0) // Probably can't happen, maybe at some point EventType should be unsigned ? return -1; pollCont_offset = eventProcessor.allocate(sizeof(PollCont)); @@ -105,9 +105,9 @@ UDPNetProcessorInternal::start(int n_upd_threads, size_t stacksize) } void -UDPNetProcessorInternal::udp_read_from_net(UDPNetHandler * nh, UDPConnection * xuc) +UDPNetProcessorInternal::udp_read_from_net(UDPNetHandler *nh, UDPConnection *xuc) { - UnixUDPConnection *uc = (UnixUDPConnection *) xuc; + UnixUDPConnection *uc = (UnixUDPConnection *)xuc; // receive packet and queue onto UDPConnection. // don't call back connection at this time. @@ -121,7 +121,7 @@ UDPNetProcessorInternal::udp_read_from_net(UDPNetHandler * nh, UDPConnection * x // which gets referenced by IOBufferBlock. char buf[65536]; int buflen = sizeof(buf); - r = socketManager.recvfrom(uc->getFd(), buf, buflen, 0, (struct sockaddr *) &fromaddr, &fromlen); + r = socketManager.recvfrom(uc->getFd(), buf, buflen, 0, (struct sockaddr *)&fromaddr, &fromlen); if (r <= 0) { // error break; @@ -148,10 +148,10 @@ UDPNetProcessorInternal::udp_read_from_net(UDPNetHandler * nh, UDPConnection * x int -UDPNetProcessorInternal::udp_callback(UDPNetHandler * nh, UDPConnection * xuc, EThread * thread) +UDPNetProcessorInternal::udp_callback(UDPNetHandler *nh, UDPConnection *xuc, EThread *thread) { - (void) nh; - UnixUDPConnection *uc = (UnixUDPConnection *) xuc; + (void)nh; + UnixUDPConnection *uc = (UnixUDPConnection *)xuc; if (uc->continuation && uc->mutex) { MUTEX_TRY_LOCK_FOR(lock, uc->mutex, thread, uc->continuation); @@ -172,25 +172,27 @@ UDPNetProcessorInternal::udp_callback(UDPNetHandler * nh, UDPConnection * xuc, E } // cheesy implementation of a asynchronous read and callback for Unix -class UDPReadContinuation:public Continuation +class UDPReadContinuation : public Continuation { public: - UDPReadContinuation(Event * completionToken); + UDPReadContinuation(Event *completionToken); UDPReadContinuation(); ~UDPReadContinuation(); inline void free(void); - inline void init_token(Event * completionToken); - inline void init_read(int fd, IOBufferBlock * buf, int len, struct sockaddr *fromaddr, socklen_t *fromaddrlen); + inline void init_token(Event *completionToken); + inline void init_read(int fd, IOBufferBlock *buf, int len, struct sockaddr *fromaddr, socklen_t *fromaddrlen); - void set_timer(int seconds) + void + set_timer(int seconds) { timeout_interval = HRTIME_SECONDS(seconds); } void cancel(); - int readPollEvent(int event, Event * e); + int readPollEvent(int event, Event *e); - Action *getAction() + Action * + getAction() { return event; } @@ -198,15 +200,15 @@ public: void setupPollDescriptor(); private: - Event * event; // the completion event token created + Event *event; // the completion event token created // on behalf of the client Ptr<IOBufferBlock> readbuf; int readlen; struct sockaddr_in6 *fromaddr; socklen_t *fromaddrlen; - int fd; // fd we are reading from - int ifd; // poll fd index - ink_hrtime period; // polling period + int fd; // fd we are reading from + int ifd; // poll fd index + ink_hrtime period; // polling period ink_hrtime elapsed_time; ink_hrtime timeout_interval; }; @@ -215,9 +217,9 @@ ClassAllocator<UDPReadContinuation> udpReadContAllocator("udpReadContAllocator") #define UNINITIALIZED_EVENT_PTR (Event *)0xdeadbeef -UDPReadContinuation::UDPReadContinuation(Event * completionToken) - : Continuation(NULL), event(completionToken), readbuf(NULL), readlen(0), fromaddrlen(0), fd(-1), - ifd(-1), period(0), elapsed_time(0), timeout_interval(0) +UDPReadContinuation::UDPReadContinuation(Event *completionToken) + : Continuation(NULL), event(completionToken), readbuf(NULL), readlen(0), fromaddrlen(0), fd(-1), ifd(-1), period(0), + elapsed_time(0), timeout_interval(0) { if (completionToken->continuation) this->mutex = completionToken->continuation->mutex; @@ -226,9 +228,10 @@ UDPReadContinuation::UDPReadContinuation(Event * completionToken) } UDPReadContinuation::UDPReadContinuation() - : Continuation(NULL), event(UNINITIALIZED_EVENT_PTR), readbuf(NULL), readlen(0), fromaddrlen(0), fd(-1), - ifd(-1), period(0), elapsed_time(0), timeout_interval(0) -{ } + : Continuation(NULL), event(UNINITIALIZED_EVENT_PTR), readbuf(NULL), readlen(0), fromaddrlen(0), fd(-1), ifd(-1), period(0), + elapsed_time(0), timeout_interval(0) +{ +} inline void UDPReadContinuation::free(void) @@ -249,7 +252,7 @@ UDPReadContinuation::free(void) } inline void -UDPReadContinuation::init_token(Event * completionToken) +UDPReadContinuation::init_token(Event *completionToken) { if (completionToken->continuation) { this->mutex = completionToken->continuation->mutex; @@ -260,7 +263,7 @@ UDPReadContinuation::init_token(Event * completionToken) } inline void -UDPReadContinuation::init_read(int rfd, IOBufferBlock * buf, int len, struct sockaddr *fromaddr_, socklen_t *fromaddrlen_) +UDPReadContinuation::init_read(int rfd, IOBufferBlock *buf, int len, struct sockaddr *fromaddr_, socklen_t *fromaddrlen_) { ink_assert(rfd >= 0 && buf != NULL && fromaddr_ != NULL && fromaddrlen_ != NULL); fd = rfd; @@ -276,8 +279,7 @@ UDPReadContinuation::init_read(int rfd, IOBufferBlock * buf, int len, struct soc UDPReadContinuation::~UDPReadContinuation() { - if (event != UNINITIALIZED_EVENT_PTR) - { + if (event != UNINITIALIZED_EVENT_PTR) { ink_assert(event != NULL); completionUtil::destroy(event); event = NULL; @@ -296,7 +298,7 @@ UDPReadContinuation::setupPollDescriptor() { #if TS_USE_EPOLL Pollfd *pfd; - EThread *et = (EThread *) this_thread(); + EThread *et = (EThread *)this_thread(); PollCont *pc = get_PollCont(et); if (pc->nextPollDescriptor == NULL) { pc->nextPollDescriptor = new PollDescriptor; @@ -312,12 +314,12 @@ UDPReadContinuation::setupPollDescriptor() } int -UDPReadContinuation::readPollEvent(int event_, Event * e) +UDPReadContinuation::readPollEvent(int event_, Event *e) { - (void) event_; - (void) e; + (void)event_; + (void)e; - //PollCont *pc = get_PollCont(e->ethread); + // PollCont *pc = get_PollCont(e->ethread); Continuation *c; if (event->cancelled) { @@ -339,9 +341,10 @@ UDPReadContinuation::readPollEvent(int event_, Event * e) return EVENT_DONE; } } - //ink_assert(ifd < 0 || event_ == EVENT_INTERVAL || (event_ == EVENT_POLL && pc->pollDescriptor->nfds > ifd && pc->pollDescriptor->pfd[ifd].fd == fd)); - //if (ifd < 0 || event_ == EVENT_INTERVAL || (pc->pollDescriptor->pfd[ifd].revents & POLLIN)) { - //ink_assert(!"incomplete"); + // ink_assert(ifd < 0 || event_ == EVENT_INTERVAL || (event_ == EVENT_POLL && pc->pollDescriptor->nfds > ifd && + // pc->pollDescriptor->pfd[ifd].fd == fd)); + // if (ifd < 0 || event_ == EVENT_INTERVAL || (pc->pollDescriptor->pfd[ifd].revents & POLLIN)) { + // ink_assert(!"incomplete"); c = completionUtil::getContinuation(event); // do read socklen_t tmp_fromlen = *fromaddrlen; @@ -363,13 +366,13 @@ UDPReadContinuation::readPollEvent(int event_, Event * e) } else if (rlen < 0 && rlen != -EAGAIN) { // signal error. *fromaddrlen = tmp_fromlen; - completionUtil::setInfo(event, fd, (IOBufferBlock *) readbuf, rlen, errno); + completionUtil::setInfo(event, fd, (IOBufferBlock *)readbuf, rlen, errno); c = completionUtil::getContinuation(event); // TODO: Should we deal with the return code? c->handleEvent(NET_EVENT_DATAGRAM_READ_ERROR, event); e->cancel(); free(); - //delete this; + // delete this; return EVENT_DONE; } else { completionUtil::setThread(event, NULL); @@ -378,7 +381,7 @@ UDPReadContinuation::readPollEvent(int event_, Event * e) if (event->cancelled) { e->cancel(); free(); - //delete this; + // delete this; return EVENT_DONE; } // reestablish poll @@ -403,13 +406,10 @@ UDPReadContinuation::readPollEvent(int event_, Event * e) * return error; */ Action * -UDPNetProcessor::recvfrom_re(Continuation * cont, - void *token, - int fd, - struct sockaddr * fromaddr, socklen_t *fromaddrlen, - IOBufferBlock * buf, int len, bool useReadCont, int timeout) +UDPNetProcessor::recvfrom_re(Continuation *cont, void *token, int fd, struct sockaddr *fromaddr, socklen_t *fromaddrlen, + IOBufferBlock *buf, int len, bool useReadCont, int timeout) { - (void) useReadCont; + (void)useReadCont; ink_assert(buf->write_avail() >= len); int actual; Event *event = completionUtil::create(); @@ -451,7 +451,7 @@ UDPNetProcessor::recvfrom_re(Continuation * cont, * return error */ Action * -UDPNetProcessor::sendmsg_re(Continuation * cont, void *token, int fd, struct msghdr * msg) +UDPNetProcessor::sendmsg_re(Continuation *cont, void *token, int fd, struct msghdr *msg) { int actual; Event *event = completionUtil::create(); @@ -487,17 +487,17 @@ UDPNetProcessor::sendmsg_re(Continuation * cont, void *token, int fd, struct msg * */ Action * -UDPNetProcessor::sendto_re(Continuation * cont, void *token, int fd, struct sockaddr const* toaddr, int toaddrlen, - IOBufferBlock * buf, int len) +UDPNetProcessor::sendto_re(Continuation *cont, void *token, int fd, struct sockaddr const *toaddr, int toaddrlen, + IOBufferBlock *buf, int len) { - (void) token; + (void)token; ink_assert(buf->read_avail() >= len); int nbytes_sent = socketManager.sendto(fd, buf->start(), len, 0, toaddr, toaddrlen); if (nbytes_sent >= 0) { ink_assert(nbytes_sent == len); buf->consume(nbytes_sent); - cont->handleEvent(NET_EVENT_DATAGRAM_WRITE_COMPLETE, (void *) -1); + cont->handleEvent(NET_EVENT_DATAGRAM_WRITE_COMPLETE, (void *)-1); return ACTION_RESULT_DONE; } else { cont->handleEvent(NET_EVENT_DATAGRAM_WRITE_ERROR, (void *)(intptr_t)nbytes_sent); @@ -507,8 +507,8 @@ UDPNetProcessor::sendto_re(Continuation * cont, void *token, int fd, struct sock bool -UDPNetProcessor::CreateUDPSocket(int *resfd, sockaddr const* remote_addr, sockaddr* local_addr, - int *local_addr_len, Action ** status, int send_bufsize, int recv_bufsize) +UDPNetProcessor::CreateUDPSocket(int *resfd, sockaddr const *remote_addr, sockaddr *local_addr, int *local_addr_len, + Action **status, int send_bufsize, int recv_bufsize) { int res = 0, fd = -1; @@ -540,23 +540,18 @@ UDPNetProcessor::CreateUDPSocket(int *resfd, sockaddr const* remote_addr, sockad } *resfd = fd; *status = NULL; - Debug("udpnet", "creating a udp socket port = %d, %d---success", - ats_ip_port_host_order(remote_addr), ats_ip_port_host_order(local_addr) - ); + Debug("udpnet", "creating a udp socket port = %d, %d---success", ats_ip_port_host_order(remote_addr), + ats_ip_port_host_order(local_addr)); return true; SoftError: - Debug("udpnet", "creating a udp socket port = %d---soft failure", - ats_ip_port_host_order(local_addr) - ); + Debug("udpnet", "creating a udp socket port = %d---soft failure", ats_ip_port_host_order(local_addr)); if (fd != -1) socketManager.close(fd); *resfd = -1; *status = NULL; return false; HardError: - Debug("udpnet", "creating a udp socket port = %d---hard failure", - ats_ip_port_host_order(local_addr) - ); + Debug("udpnet", "creating a udp socket port = %d---hard failure", ats_ip_port_host_order(local_addr)); if (fd != -1) socketManager.close(fd); *resfd = -1; @@ -566,7 +561,7 @@ HardError: Action * -UDPNetProcessor::UDPBind(Continuation * cont, sockaddr const* addr, int send_bufsize, int recv_bufsize) +UDPNetProcessor::UDPBind(Continuation *cont, sockaddr const *addr, int send_bufsize, int recv_bufsize) { int res = 0; int fd = -1; @@ -584,7 +579,7 @@ UDPNetProcessor::UDPBind(Continuation * cont, sockaddr const* addr, int send_buf if (ats_is_ip_multicast(addr)) { int enable_reuseaddr = 1; - if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &enable_reuseaddr, sizeof(enable_reuseaddr)) < 0)) { + if ((res = safe_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&enable_reuseaddr, sizeof(enable_reuseaddr)) < 0)) { goto Lerror; } } @@ -621,9 +616,9 @@ Lerror: // send out all packets that need to be sent out as of time=now -UDPQueue::UDPQueue() - : last_report(0), last_service(0), packets(0), added(0) -{ } +UDPQueue::UDPQueue() : last_report(0), last_service(0), packets(0), added(0) +{ +} UDPQueue::~UDPQueue() { @@ -633,16 +628,16 @@ UDPQueue::~UDPQueue() * Driver function that aggregates packets across cont's and sends them */ void -UDPQueue::service(UDPNetHandler * nh) +UDPQueue::service(UDPNetHandler *nh) { - (void) nh; + (void)nh; ink_hrtime now = ink_get_hrtime_internal(); uint64_t timeSpent = 0; uint64_t pktSendStartTime; UDPPacketInternal *p; ink_hrtime pktSendTime; - p = (UDPPacketInternal *) ink_atomiclist_popall(&atomicQueue); + p = (UDPPacketInternal *)ink_atomiclist_popall(&atomicQueue); if (p) { UDPPacketInternal *pnext = NULL; Queue<UDPPacketInternal> stk; @@ -757,12 +752,12 @@ UDPQueue::SendUDPPacket(UDPPacketInternal *p, int32_t /* pktLen ATS_UNUSED */) msg.msg_controllen = 0; msg.msg_flags = 0; #endif - msg.msg_name = (caddr_t) & p->to; + msg.msg_name = (caddr_t)&p->to; msg.msg_namelen = sizeof(p->to); iov_len = 0; for (b = p->chain; b != NULL; b = b->next) { - iov[iov_len].iov_base = (caddr_t) b->start(); + iov[iov_len].iov_base = (caddr_t)b->start(); iov[iov_len].iov_len = b->size(); real_len += iov[iov_len].iov_len; iov_len++; @@ -773,7 +768,7 @@ UDPQueue::SendUDPPacket(UDPPacketInternal *p, int32_t /* pktLen ATS_UNUSED */) count = 0; while (1) { // stupid Linux problem: sendmsg can return EAGAIN - n =::sendmsg(p->conn->getFd(), &msg, 0); + n = ::sendmsg(p->conn->getFd(), &msg, 0); if ((n >= 0) || ((n < 0) && (errno != EAGAIN))) // send succeeded or some random error happened. break; @@ -790,7 +785,7 @@ UDPQueue::SendUDPPacket(UDPPacketInternal *p, int32_t /* pktLen ATS_UNUSED */) void -UDPQueue::send(UDPPacket * p) +UDPQueue::send(UDPPacket *p) { // XXX: maybe fastpath for immediate send? ink_atomiclist_push(&atomicQueue, p); @@ -805,25 +800,25 @@ UDPNetHandler::UDPNetHandler() ink_atomiclist_init(&udpNewConnections, "UDP Connection queue", offsetof(UnixUDPConnection, newconn_alink.next)); nextCheck = ink_get_hrtime_internal() + HRTIME_MSECONDS(1000); lastCheck = 0; - SET_HANDLER((UDPNetContHandler) & UDPNetHandler::startNetEvent); + SET_HANDLER((UDPNetContHandler)&UDPNetHandler::startNetEvent); } int -UDPNetHandler::startNetEvent(int event, Event * e) +UDPNetHandler::startNetEvent(int event, Event *e) { - (void) event; - SET_HANDLER((UDPNetContHandler) & UDPNetHandler::mainNetEvent); + (void)event; + SET_HANDLER((UDPNetContHandler)&UDPNetHandler::mainNetEvent); trigger_event = e; e->schedule_every(-HRTIME_MSECONDS(9)); return EVENT_CONT; } int -UDPNetHandler::mainNetEvent(int event, Event * e) +UDPNetHandler::mainNetEvent(int event, Event *e) { ink_assert(trigger_event == e && event == EVENT_POLL); - (void) event; - (void) e; + (void)event; + (void)e; PollCont *pc = get_UDPPollCont(e->ethread); @@ -837,9 +832,8 @@ UDPNetHandler::mainNetEvent(int event, Event * e) EventIO *temp_eptr = NULL; for (i = 0; i < pc->pollDescriptor->result; i++) { - temp_eptr = (EventIO*) get_ev_data(pc->pollDescriptor,i); - if ((get_ev_events(pc->pollDescriptor,i) & EVENTIO_READ) - && temp_eptr->type == EVENTIO_UDP_CONNECTION) { + temp_eptr = (EventIO *)get_ev_data(pc->pollDescriptor, i); + if ((get_ev_events(pc->pollDescriptor, i) & EVENTIO_READ) && temp_eptr->type == EVENTIO_UDP_CONNECTION) { uc = temp_eptr->data.uc; ink_assert(uc && uc->mutex && uc->continuation); ink_assert(uc->refcount >= 1); @@ -850,8 +844,8 @@ UDPNetHandler::mainNetEvent(int event, Event * e) udpNetInternal.udp_read_from_net(this, uc); nread++; } - } //if EPOLLIN - } //end for + } // if EPOLLIN + } // end for // remove dead UDP connections ink_hrtime now = ink_get_hrtime_internal(); @@ -861,8 +855,8 @@ UDPNetHandler::mainNetEvent(int event, Event * e) ink_assert(uc->refcount >= 1); next = uc->polling_link.next; if (uc->shouldDestroy()) { - //changed by YTS Team, yamsat - //udp_polling->remove(uc,uc->polling_link); + // changed by YTS Team, yamsat + // udp_polling->remove(uc,uc->polling_link); uc->Release(); } } @@ -873,7 +867,7 @@ UDPNetHandler::mainNetEvent(int event, Event * e) udp_callbacks.clear(); while ((uc = q.dequeue())) { ink_assert(uc->mutex && uc->continuation); - if (udpNetInternal.udp_callback(this, uc, trigger_event->ethread)) { // not successful + if (udpNetInternal.udp_callback(this, uc, trigger_event->ethread)) { // not successful // schedule on a thread of its own. ink_assert(uc->callback_link.next == NULL); ink_assert(uc->callback_link.prev == NULL); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/test_I_Net.cc ---------------------------------------------------------------------- diff --git a/iocore/net/test_I_Net.cc b/iocore/net/test_I_Net.cc index 5f54f1d..70d314d 100644 --- a/iocore/net/test_I_Net.cc +++ b/iocore/net/test_I_Net.cc @@ -55,7 +55,6 @@ reconfigure_diags() // read output routing values for (i = 0; i < DiagsLevel_Count; i++) { - c.outputs[i].to_stdout = 0; c.outputs[i].to_stderr = 1; c.outputs[i].to_syslog = 1; @@ -78,19 +77,17 @@ reconfigure_diags() if (diags->base_action_tags) diags->activate_taglist(diags->base_action_tags, DiagsTagType_Action); - //////////////////////////////////// - // change the diags config values // - //////////////////////////////////// +//////////////////////////////////// +// change the diags config values // +//////////////////////////////////// #if !defined(__GNUC__) && !defined(hpux) diags->config = c; #else - memcpy(((void *) &diags->config), ((void *) &c), sizeof(DiagsConfigState)); + memcpy(((void *)&diags->config), ((void *)&c), sizeof(DiagsConfigState)); #endif - } - static void init_diags(char *bdt, char *bat) { @@ -113,13 +110,13 @@ init_diags(char *bdt, char *bat) if (diags_log_fp == NULL) { SrcLoc loc(__FILE__, __FUNCTION__, __LINE__); - diags->print(NULL, DL_Warning, NULL, &loc, - "couldn't open diags log file '%s', " "will not log to this file", diags_logpath); + diags->print(NULL, DL_Warning, NULL, &loc, "couldn't open diags log file '%s', " + "will not log to this file", + diags_logpath); } diags->print(NULL, DL_Status, "STATUS", NULL, "opened %s", diags_logpath); reconfigure_diags(); - } /* @@ -157,9 +154,9 @@ main() eventProcessor.start(nproc); RecProcessStart(); - /* - * Reset necessary config variables - */ +/* + * Reset necessary config variables + */ #ifdef USE_SOCKS net_config_socks_server_host = "209.131.52.54"; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/test_I_UDPNet.cc ---------------------------------------------------------------------- diff --git a/iocore/net/test_I_UDPNet.cc b/iocore/net/test_I_UDPNet.cc index c3fef81..37b0952 100644 --- a/iocore/net/test_I_UDPNet.cc +++ b/iocore/net/test_I_UDPNet.cc @@ -27,7 +27,7 @@ #include "I_Net.h" #include "List.h" -//Diags stuff from test_I_Net.cc: +// Diags stuff from test_I_Net.cc: Diags *diags; #define DIAGS_LOG_FILE "diags.log" @@ -59,7 +59,6 @@ reconfigure_diags() // read output routing values for (i = 0; i < DiagsLevel_Count; i++) { - c.outputs[i].to_stdout = 0; c.outputs[i].to_stderr = 1; c.outputs[i].to_syslog = 1; @@ -82,19 +81,17 @@ reconfigure_diags() if (diags->base_action_tags) diags->activate_taglist(diags->base_action_tags, DiagsTagType_Action); - //////////////////////////////////// - // change the diags config values // - //////////////////////////////////// +//////////////////////////////////// +// change the diags config values // +//////////////////////////////////// #if !defined(__GNUC__) && !defined(hpux) diags->config = c; #else - memcpy(((void *) &diags->config), ((void *) &c), sizeof(DiagsConfigState)); + memcpy(((void *)&diags->config), ((void *)&c), sizeof(DiagsConfigState)); #endif - } - static void init_diags(char *bdt, char *bat) { @@ -117,20 +114,20 @@ init_diags(char *bdt, char *bat) if (diags_log_fp == NULL) { SrcLoc loc(__FILE__, __FUNCTION__, __LINE__); - diags->print(NULL, DL_Warning, NULL, &loc, - "couldn't open diags log file '%s', " "will not log to this file", diags_logpath); + diags->print(NULL, DL_Warning, NULL, &loc, "couldn't open diags log file '%s', " + "will not log to this file", + diags_logpath); } diags->print(NULL, DL_Status, "STATUS", NULL, "opened %s", diags_logpath); reconfigure_diags(); - } /*This implements a standard Unix echo server: just send every udp packet you get back to where it came from*/ -class EchoServer:public Continuation +class EchoServer : public Continuation { int sock_fd; UDPConnection *conn; @@ -138,10 +135,7 @@ class EchoServer:public Continuation int handlePacket(int event, void *data); public: - EchoServer() - : Continuation(new_ProxyMutex()) - { - }; + EchoServer() : Continuation(new_ProxyMutex()){}; bool Start(int port); }; @@ -167,25 +161,24 @@ int EchoServer::handlePacket(int event, void *data) { switch (event) { - - case NET_EVENT_DATAGRAM_READ_READY:{ - Queue<UDPPacket> *q = (Queue<UDPPacket> *)data; - UDPPacket *p; - - //send what ever we get back to the client - while (p = q->pop()) { - p->m_to = p->m_from; - conn->send(this, p); - } - break; + case NET_EVENT_DATAGRAM_READ_READY: { + Queue<UDPPacket> *q = (Queue<UDPPacket> *)data; + UDPPacket *p; + + // send what ever we get back to the client + while (p = q->pop()) { + p->m_to = p->m_from; + conn->send(this, p); } + break; + } case NET_EVENT_DATAGRAM_READ_ERROR: printf("got Read Error exiting\n"); _exit(1); case NET_EVENT_DATAGRAM_WRITE_ERROR: - printf("got write error: %d\n", (int) data); + printf("got write error: %d\n", (int)data); break; default: http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/test_P_Net.cc ---------------------------------------------------------------------- diff --git a/iocore/net/test_P_Net.cc b/iocore/net/test_P_Net.cc index ba402d7..87b7736 100644 --- a/iocore/net/test_P_Net.cc +++ b/iocore/net/test_P_Net.cc @@ -24,14 +24,13 @@ #include "P_Net.h" Diags *diags; -struct NetTesterSM:public Continuation -{ +struct NetTesterSM : public Continuation { VIO *read_vio; IOBufferReader *reader; NetVConnection *vc; MIOBuffer *buf; - NetTesterSM(ProxyMutex * _mutex, NetVConnection * _vc):Continuation(_mutex) + NetTesterSM(ProxyMutex *_mutex, NetVConnection *_vc) : Continuation(_mutex) { MUTEX_TRY_LOCK(lock, mutex, _vc->thread); ink_release_assert(lock); @@ -43,7 +42,8 @@ struct NetTesterSM:public Continuation } - int handle_read(int event, void *data) + int + handle_read(int event, void *data) { int r; char *str; @@ -56,7 +56,7 @@ struct NetTesterSM:public Continuation fflush(stdout); break; case VC_EVENT_READ_COMPLETE: - /* FALLSTHROUGH */ + /* FALLSTHROUGH */ case VC_EVENT_EOS: r = reader->read_avail(); str = new char[r + 10]; @@ -68,38 +68,27 @@ struct NetTesterSM:public Continuation break; default: ink_release_assert(!"unknown event"); - } return EVENT_CONT; } - - }; -struct NetTesterAccept:public Continuation -{ - - NetTesterAccept(ProxyMutex * _mutex):Continuation(_mutex) - { - SET_HANDLER(&NetTesterAccept::handle_accept); - } +struct NetTesterAccept : public Continuation { + NetTesterAccept(ProxyMutex *_mutex) : Continuation(_mutex) { SET_HANDLER(&NetTesterAccept::handle_accept); } - int handle_accept(int event, void *data) + int + handle_accept(int event, void *data) { printf("Accepted a connection\n"); fflush(stdout); - NetVConnection *vc = (NetVConnection *) data; + NetVConnection *vc = (NetVConnection *)data; new NetTesterSM(new_ProxyMutex(), vc); return EVENT_CONT; } - - }; - - int main() { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/test_P_UDPNet.cc ---------------------------------------------------------------------- diff --git a/iocore/net/test_P_UDPNet.cc b/iocore/net/test_P_UDPNet.cc index fc8fde8..751fe18 100644 --- a/iocore/net/test_P_UDPNet.cc +++ b/iocore/net/test_P_UDPNet.cc @@ -27,7 +27,7 @@ #include "P_Net.h" #include "libts.h" -//Diags stuff from test_I_Net.cc: +// Diags stuff from test_I_Net.cc: Diags *diags; #define DIAGS_LOG_FILE "diags.log" @@ -59,7 +59,6 @@ reconfigure_diags() // read output routing values for (i = 0; i < DiagsLevel_Count; i++) { - c.outputs[i].to_stdout = 0; c.outputs[i].to_stderr = 1; c.outputs[i].to_syslog = 1; @@ -82,19 +81,17 @@ reconfigure_diags() if (diags->base_action_tags) diags->activate_taglist(diags->base_action_tags, DiagsTagType_Action); - //////////////////////////////////// - // change the diags config values // - //////////////////////////////////// +//////////////////////////////////// +// change the diags config values // +//////////////////////////////////// #if !defined(__GNUC__) && !defined(hpux) diags->config = c; #else - memcpy(((void *) &diags->config), ((void *) &c), sizeof(DiagsConfigState)); + memcpy(((void *)&diags->config), ((void *)&c), sizeof(DiagsConfigState)); #endif - } - static void init_diags(char *bdt, char *bat) { @@ -117,20 +114,20 @@ init_diags(char *bdt, char *bat) if (diags_log_fp == NULL) { SrcLoc loc(__FILE__, __FUNCTION__, __LINE__); - diags->print(NULL, DL_Warning, NULL, &loc, - "couldn't open diags log file '%s', " "will not log to this file", diags_logpath); + diags->print(NULL, DL_Warning, NULL, &loc, "couldn't open diags log file '%s', " + "will not log to this file", + diags_logpath); } diags->print(NULL, DL_Status, "STATUS", NULL, "opened %s", diags_logpath); reconfigure_diags(); - } /*This implements a standard Unix echo server: just send every udp packet you get back to where it came from*/ -class EchoServer:public Continuation +class EchoServer : public Continuation { int sock_fd; UDPConnection *conn; @@ -138,10 +135,7 @@ class EchoServer:public Continuation int handlePacket(int event, void *data); public: - EchoServer() - : Continuation(new_ProxyMutex()) - { - }; + EchoServer() : Continuation(new_ProxyMutex()){}; bool Start(int port); }; @@ -167,25 +161,24 @@ int EchoServer::handlePacket(int event, void *data) { switch (event) { - - case NET_EVENT_DATAGRAM_READ_READY:{ - Queue<UDPPacket> *q = (Queue<UDPPacket> *)data; - UDPPacket *p; - - //send what ever we get back to the client - while (p = q->pop()) { - p->m_to = p->m_from; - conn->send(this, p); - } - break; + case NET_EVENT_DATAGRAM_READ_READY: { + Queue<UDPPacket> *q = (Queue<UDPPacket> *)data; + UDPPacket *p; + + // send what ever we get back to the client + while (p = q->pop()) { + p->m_to = p->m_from; + conn->send(this, p); } + break; + } case NET_EVENT_DATAGRAM_READ_ERROR: printf("got Read Error exiting\n"); _exit(1); case NET_EVENT_DATAGRAM_WRITE_ERROR: - printf("got write error: %d\n", (int) data); + printf("got write error: %d\n", (int)data); break; default: http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/net/test_certlookup.cc ---------------------------------------------------------------------- diff --git a/iocore/net/test_certlookup.cc b/iocore/net/test_certlookup.cc index 418d06a..717f287 100644 --- a/iocore/net/test_certlookup.cc +++ b/iocore/net/test_certlookup.cc @@ -26,7 +26,7 @@ #include <fstream> static IpEndpoint -make_endpoint(const char * address) +make_endpoint(const char *address) { IpEndpoint ip; @@ -34,21 +34,21 @@ make_endpoint(const char * address) return ip; } -REGRESSION_TEST(SSLCertificateLookup)(RegressionTest* t, int /* atype ATS_UNUSED */, int * pstatus) +REGRESSION_TEST(SSLCertificateLookup)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus) { - TestBox box(t, pstatus); + TestBox box(t, pstatus); SSLCertLookup lookup; - SSL_CTX * wild = SSL_CTX_new(SSLv23_server_method()); - SSL_CTX * notwild = SSL_CTX_new(SSLv23_server_method()); - SSL_CTX * b_notwild = SSL_CTX_new(SSLv23_server_method()); - SSL_CTX * foo = SSL_CTX_new(SSLv23_server_method()); - SSL_CTX * all_com = SSL_CTX_new(SSLv23_server_method()); - SSLCertContext wild_cc (wild); - SSLCertContext notwild_cc (notwild); - SSLCertContext b_notwild_cc (b_notwild); - SSLCertContext foo_cc (foo); - SSLCertContext all_com_cc (all_com); + SSL_CTX *wild = SSL_CTX_new(SSLv23_server_method()); + SSL_CTX *notwild = SSL_CTX_new(SSLv23_server_method()); + SSL_CTX *b_notwild = SSL_CTX_new(SSLv23_server_method()); + SSL_CTX *foo = SSL_CTX_new(SSLv23_server_method()); + SSL_CTX *all_com = SSL_CTX_new(SSLv23_server_method()); + SSLCertContext wild_cc(wild); + SSLCertContext notwild_cc(notwild); + SSLCertContext b_notwild_cc(b_notwild); + SSLCertContext foo_cc(foo); + SSLCertContext all_com_cc(all_com); box = REGRESSION_TEST_PASSED; @@ -92,23 +92,23 @@ REGRESSION_TEST(SSLCertificateLookup)(RegressionTest* t, int /* atype ATS_UNUSED box.check(lookup.find("www.bar.net") == NULL, "host lookup for www.bar.net"); } -REGRESSION_TEST(SSLAddressLookup)(RegressionTest* t, int /* atype ATS_UNUSED */, int * pstatus) +REGRESSION_TEST(SSLAddressLookup)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus) { - TestBox box(t, pstatus); + TestBox box(t, pstatus); SSLCertLookup lookup; struct { - SSL_CTX * ip6; - SSL_CTX * ip6p; - SSL_CTX * ip4; - SSL_CTX * ip4p; + SSL_CTX *ip6; + SSL_CTX *ip6p; + SSL_CTX *ip4; + SSL_CTX *ip4p; } context; struct { - IpEndpoint ip6; - IpEndpoint ip6p; - IpEndpoint ip4; - IpEndpoint ip4p; + IpEndpoint ip6; + IpEndpoint ip6p; + IpEndpoint ip4; + IpEndpoint ip4p; } endpoint; context.ip6 = SSL_CTX_new(SSLv23_server_method()); @@ -130,7 +130,7 @@ REGRESSION_TEST(SSLAddressLookup)(RegressionTest* t, int /* atype ATS_UNUSED */, // For each combination of address with port and address without port, make sure that we find the // the most specific match (ie. find the context with the port if it is available) ... - box.check(lookup.insert(endpoint.ip6, ip6_cc) >= 0 , "insert IPv6 address"); + box.check(lookup.insert(endpoint.ip6, ip6_cc) >= 0, "insert IPv6 address"); box.check(lookup.find(endpoint.ip6)->ctx == context.ip6, "IPv6 exact match lookup"); box.check(lookup.find(endpoint.ip6p)->ctx == context.ip6, "IPv6 exact match lookup w/ port"); @@ -148,7 +148,7 @@ REGRESSION_TEST(SSLAddressLookup)(RegressionTest* t, int /* atype ATS_UNUSED */, } static unsigned -load_hostnames_csv(const char * fname, SSLCertLookup& lookup) +load_hostnames_csv(const char *fname, SSLCertLookup &lookup) { std::fstream infile(fname, std::ios_base::in); unsigned count = 0; @@ -157,7 +157,7 @@ load_hostnames_csv(const char * fname, SSLCertLookup& lookup) // with multiple names, an it's way faster to load a lot of names // if we don't need a new context every time. - SSL_CTX * ctx = SSL_CTX_new(SSLv23_server_method()); + SSL_CTX *ctx = SSL_CTX_new(SSLv23_server_method()); SSLCertContext ctx_cc(ctx); // The input should have 2 comma-separated fields; this is the format that you get when @@ -198,12 +198,13 @@ load_hostnames_csv(const char * fname, SSLCertLookup& lookup) // of binary dependencies. We don't have session tickets in this test environment // so it's safe to do this; just a bit ugly. void -SSLReleaseContext(SSL_CTX * ctx) +SSLReleaseContext(SSL_CTX *ctx) { - SSL_CTX_free(ctx); + SSL_CTX_free(ctx); } -int main(int argc, const char ** argv) +int +main(int argc, const char **argv) { diags = new Diags(NULL, NULL, stdout); res_track_memory = 1; @@ -228,7 +229,7 @@ int main(int argc, const char ** argv) ink_freelists_dump(stdout); - // On Darwin, fail the tests if we have any memory leaks. +// On Darwin, fail the tests if we have any memory leaks. #if defined(darwin) if (system("xcrun leaks test_certlookup") != 0) { RegressionTest::final_status = REGRESSION_TEST_FAILED; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/utils/I_Machine.h ---------------------------------------------------------------------- diff --git a/iocore/utils/I_Machine.h b/iocore/utils/I_Machine.h index c2ec112..b438f62 100644 --- a/iocore/utils/I_Machine.h +++ b/iocore/utils/I_Machine.h @@ -49,17 +49,17 @@ struct Machine { typedef Machine self; ///< Self reference type. - char *hostname; // name of the internet host - int hostname_len; // size of the string pointed to by hostname + char *hostname; // name of the internet host + int hostname_len; // size of the string pointed to by hostname - IpEndpoint ip; ///< Prefered IP address of the host (network order) - IpEndpoint ip4; ///< IPv4 address if present. - IpEndpoint ip6; ///< IPv6 address if present. + IpEndpoint ip; ///< Prefered IP address of the host (network order) + IpEndpoint ip4; ///< IPv4 address if present. + IpEndpoint ip6; ///< IPv6 address if present. - ip_text_buffer ip_string; // IP address of the host as a string. + ip_text_buffer ip_string; // IP address of the host as a string. int ip_string_len; - char ip_hex_string[TS_IP6_SIZE*2 + 1]; ///< IP address as hex string + char ip_hex_string[TS_IP6_SIZE * 2 + 1]; ///< IP address as hex string int ip_hex_string_len; ~Machine(); @@ -70,17 +70,16 @@ struct Machine { @note This must be called before called @c instance so that the singleton is not @em inadvertently default initialized. */ - static self* init( - char const* name = 0, ///< Host name of the machine. - sockaddr const* addr = 0 ///< Primary IP adddress of the machine. - ); + static self *init(char const *name = 0, ///< Host name of the machine. + sockaddr const *addr = 0 ///< Primary IP adddress of the machine. + ); /// @return The global instance of this class. - static self* instance(); + static self *instance(); protected: - Machine(char const* hostname, sockaddr const* addr); + Machine(char const *hostname, sockaddr const *addr); - static self* _instance; ///< Singleton for the class. + static self *_instance; ///< Singleton for the class. }; #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/utils/I_OneWayMultiTunnel.h ---------------------------------------------------------------------- diff --git a/iocore/utils/I_OneWayMultiTunnel.h b/iocore/utils/I_OneWayMultiTunnel.h index 96afe3f..0be538c 100644 --- a/iocore/utils/I_OneWayMultiTunnel.h +++ b/iocore/utils/I_OneWayMultiTunnel.h @@ -28,13 +28,13 @@ */ -#if !defined (_I_OneWayMultiTunnel_h_) +#if !defined(_I_OneWayMultiTunnel_h_) #define _I_OneWayMultiTunnel_h_ #include "I_OneWayTunnel.h" /** Maximum number which can be tunnelled too */ -#define ONE_WAY_MULTI_TUNNEL_LIMIT 4 +#define ONE_WAY_MULTI_TUNNEL_LIMIT 4 /** A generic state machine that connects a source virtual conection to @@ -53,8 +53,7 @@ @see OneWayTunnel */ -struct OneWayMultiTunnel: public OneWayTunnel -{ +struct OneWayMultiTunnel : public OneWayTunnel { // // Public Interface // @@ -75,7 +74,7 @@ struct OneWayMultiTunnel: public OneWayTunnel */ static void OneWayMultiTunnel_free(OneWayMultiTunnel *); - OneWayMultiTunnel(); + OneWayMultiTunnel(); // Use One of the following init functions to start the tunnel. @@ -109,11 +108,10 @@ struct OneWayMultiTunnel: public OneWayTunnel @param water_mark for the MIOBuffer used for reading. */ - void init(VConnection * vcSource, VConnection ** vcTargets, int n_vcTargets, Continuation * aCont = NULL, int size_estimate = 0, // 0 == best guess - int64_t nbytes = TUNNEL_TILL_DONE, - bool asingle_buffer = true, - bool aclose_source = true, - bool aclose_target = true, Transform_fn manipulate_fn = NULL, int water_mark = 0); + void init(VConnection *vcSource, VConnection **vcTargets, int n_vcTargets, Continuation *aCont = NULL, + int size_estimate = 0, // 0 == best guess + int64_t nbytes = TUNNEL_TILL_DONE, bool asingle_buffer = true, bool aclose_source = true, bool aclose_target = true, + Transform_fn manipulate_fn = NULL, int water_mark = 0); /** Use this init function if both the read and the write sides have @@ -133,7 +131,7 @@ struct OneWayMultiTunnel: public OneWayTunnel end. If aCont is not specified, this should be set to true. */ - void init(Continuation * aCont, VIO * SourceVio, VIO ** TargetVios, int n_vioTargets, bool aclose_source = true, + void init(Continuation *aCont, VIO *SourceVio, VIO **TargetVios, int n_vioTargets, bool aclose_source = true, bool aclose_target = true); // @@ -142,7 +140,7 @@ struct OneWayMultiTunnel: public OneWayTunnel int startEvent(int event, void *data); virtual void reenable_all(); - virtual void close_target_vio(int result, VIO * vio = NULL); + virtual void close_target_vio(int result, VIO *vio = NULL); int n_vioTargets; VIO *vioTargets[ONE_WAY_MULTI_TUNNEL_LIMIT]; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/utils/I_OneWayTunnel.h ---------------------------------------------------------------------- diff --git a/iocore/utils/I_OneWayTunnel.h b/iocore/utils/I_OneWayTunnel.h index 8ebaf47..479d493 100644 --- a/iocore/utils/I_OneWayTunnel.h +++ b/iocore/utils/I_OneWayTunnel.h @@ -28,7 +28,7 @@ */ -#if !defined (_I_OneWayTunnel_h_) +#if !defined(_I_OneWayTunnel_h_) #define _I_OneWayTunnel_h_ #include "I_EventSystem.h" @@ -39,11 +39,11 @@ // ////////////////////////////////////////////////////////////////////////////// -#define TUNNEL_TILL_DONE INT64_MAX +#define TUNNEL_TILL_DONE INT64_MAX #define ONE_WAY_TUNNEL_CLOSE_ALL NULL -typedef void (*Transform_fn) (MIOBufferAccessor & in_buf, MIOBufferAccessor & out_buf); +typedef void (*Transform_fn)(MIOBufferAccessor &in_buf, MIOBufferAccessor &out_buf); /** A generic state machine that connects two virtual conections. A @@ -62,8 +62,7 @@ typedef void (*Transform_fn) (MIOBufferAccessor & in_buf, MIOBufferAccessor & ou connection which it may manipulate in any manner it sees fit. */ -struct OneWayTunnel: public Continuation -{ +struct OneWayTunnel : public Continuation { // // Public Interface // @@ -86,9 +85,9 @@ struct OneWayTunnel: public Continuation /** Deallocates a OneWayTunnel object. */ static void OneWayTunnel_free(OneWayTunnel *); - static void SetupTwoWayTunnel(OneWayTunnel * east, OneWayTunnel * west); - OneWayTunnel(); - virtual ~ OneWayTunnel(); + static void SetupTwoWayTunnel(OneWayTunnel *east, OneWayTunnel *west); + OneWayTunnel(); + virtual ~OneWayTunnel(); // Use One of the following init functions to start the tunnel. /** @@ -122,11 +121,8 @@ struct OneWayTunnel: public Continuation @param water_mark watermark for the MIOBuffer used for reading. */ - void init(VConnection * vcSource, VConnection * vcTarget, Continuation * aCont = NULL, int size_estimate = 0, // 0 = best guess - ProxyMutex * aMutex = NULL, - int64_t nbytes = TUNNEL_TILL_DONE, - bool asingle_buffer = true, - bool aclose_source = true, + void init(VConnection *vcSource, VConnection *vcTarget, Continuation *aCont = NULL, int size_estimate = 0, // 0 = best guess + ProxyMutex *aMutex = NULL, int64_t nbytes = TUNNEL_TILL_DONE, bool asingle_buffer = true, bool aclose_source = true, bool aclose_target = true, Transform_fn manipulate_fn = NULL, int water_mark = 0); /** @@ -152,10 +148,8 @@ struct OneWayTunnel: public Continuation @param aclose_target if true, the tunnel closes vcTarget at the end. If aCont is not specified, this should be set to true. */ - void init(VConnection * vcSource, - VConnection * vcTarget, - Continuation * aCont, - VIO * SourceVio, IOBufferReader * reader, bool aclose_source = true, bool aclose_target = true); + void init(VConnection *vcSource, VConnection *vcTarget, Continuation *aCont, VIO *SourceVio, IOBufferReader *reader, + bool aclose_source = true, bool aclose_target = true); /** Use this init function if both the read and the write sides have @@ -174,23 +168,21 @@ struct OneWayTunnel: public Continuation end. If aCont is not specified, this should be set to true. */ - void init(Continuation * aCont, - VIO * SourceVio, VIO * TargetVio, bool aclose_source = true, bool aclose_target = true); + void init(Continuation *aCont, VIO *SourceVio, VIO *TargetVio, bool aclose_source = true, bool aclose_target = true); // // Private // - OneWayTunnel(Continuation * aCont, - Transform_fn manipulate_fn = NULL, bool aclose_source = false, bool aclose_target = false); + OneWayTunnel(Continuation *aCont, Transform_fn manipulate_fn = NULL, bool aclose_source = false, bool aclose_target = false); int startEvent(int event, void *data); - virtual void transform(MIOBufferAccessor & in_buf, MIOBufferAccessor & out_buf); + virtual void transform(MIOBufferAccessor &in_buf, MIOBufferAccessor &out_buf); /** Result is -1 for any error. */ void close_source_vio(int result); - virtual void close_target_vio(int result, VIO * vio = ONE_WAY_TUNNEL_CLOSE_ALL); + virtual void close_target_vio(int result, VIO *vio = ONE_WAY_TUNNEL_CLOSE_ALL); void connection_closed(int result); @@ -215,9 +207,8 @@ struct OneWayTunnel: public Continuation bool free_vcs; private: - OneWayTunnel(const OneWayTunnel &); - OneWayTunnel & operator =(const OneWayTunnel &); - + OneWayTunnel(const OneWayTunnel &); + OneWayTunnel &operator=(const OneWayTunnel &); }; #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/utils/Machine.cc ---------------------------------------------------------------------- diff --git a/iocore/utils/Machine.cc b/iocore/utils/Machine.cc index 756d3a3..7d3ace1 100644 --- a/iocore/utils/Machine.cc +++ b/iocore/utils/Machine.cc @@ -25,29 +25,29 @@ #include "I_Machine.h" #if HAVE_IFADDRS_H -# include <ifaddrs.h> +#include <ifaddrs.h> #endif // Singleton -Machine* Machine::_instance = NULL; +Machine *Machine::_instance = NULL; -Machine* -Machine::instance() { +Machine * +Machine::instance() +{ ink_assert(_instance || !"Machine instance accessed before initialization"); return Machine::_instance; } -Machine* -Machine::init(char const* name, sockaddr const* ip) { +Machine * +Machine::init(char const *name, sockaddr const *ip) +{ ink_assert(!_instance || !"Machine instance initialized twice."); Machine::_instance = new Machine(name, ip); return Machine::_instance; } -Machine::Machine(char const* the_hostname, sockaddr const* addr) - : hostname(0), hostname_len(0) - , ip_string_len(0) - , ip_hex_string_len(0) +Machine::Machine(char const *the_hostname, sockaddr const *addr) + : hostname(0), hostname_len(0), ip_string_len(0), ip_hex_string_len(0) { char localhost[1024]; int status; // return for system calls. @@ -58,41 +58,38 @@ Machine::Machine(char const* the_hostname, sockaddr const* addr) ink_zero(ip4); ink_zero(ip6); - localhost[sizeof(localhost)-1] = 0; // ensure termination. + localhost[sizeof(localhost) - 1] = 0; // ensure termination. if (!ats_is_ip(addr)) { if (!the_hostname) { - ink_release_assert(!gethostname(localhost, sizeof(localhost)-1)); + ink_release_assert(!gethostname(localhost, sizeof(localhost) - 1)); the_hostname = localhost; } hostname = ats_strdup(the_hostname); #if HAVE_IFADDRS_H - ifaddrs* ifa_addrs = 0; - status = getifaddrs(&ifa_addrs); + ifaddrs *ifa_addrs = 0; + status = getifaddrs(&ifa_addrs); #else - int s = socket(AF_INET, SOCK_DGRAM, 0); - // This number is hard to determine, but needs to be much larger than - // you would expect. On a normal system with just two interfaces and - // one address / interface the return count is 120. Stack space is - // cheap so it's best to go big. - static const int N_REQ = 1024; - ifconf conf; - ifreq req[N_REQ]; - if (0 <= s) { - conf.ifc_len = sizeof(req); - conf.ifc_req = req; - status = ioctl(s, SIOCGIFCONF, &conf); - } else { - status = -1; - } + int s = socket(AF_INET, SOCK_DGRAM, 0); + // This number is hard to determine, but needs to be much larger than + // you would expect. On a normal system with just two interfaces and + // one address / interface the return count is 120. Stack space is + // cheap so it's best to go big. + static const int N_REQ = 1024; + ifconf conf; + ifreq req[N_REQ]; + if (0 <= s) { + conf.ifc_len = sizeof(req); + conf.ifc_req = req; + status = ioctl(s, SIOCGIFCONF, &conf); + } else { + status = -1; + } #endif if (0 != status) { - Warning("Unable to determine local host '%s' address information - %s" - , hostname - , strerror(errno) - ); + Warning("Unable to determine local host '%s' address information - %s", hostname, strerror(errno)); } else { // Loop through the interface addresses and prefer by type. enum { @@ -102,16 +99,17 @@ Machine::Machine(char const* the_hostname, sockaddr const* addr) PR, // Private. MC, // Multicast. GL // Global. - } spot_type = NA, ip4_type = NA, ip6_type = NA; - sockaddr const* ifip; + } spot_type = NA, + ip4_type = NA, ip6_type = NA; + sockaddr const *ifip; unsigned int ifflags; for ( #if HAVE_IFADDRS_H - ifaddrs* spot = ifa_addrs ; spot ; spot = spot->ifa_next + ifaddrs *spot = ifa_addrs; spot; spot = spot->ifa_next #else - ifreq* spot = req, *req_limit = req + (conf.ifc_len/sizeof(*req)) ; spot < req_limit ; ++spot + ifreq *spot = req, *req_limit = req + (conf.ifc_len / sizeof(*req)); spot < req_limit; ++spot #endif - ) { + ) { #if HAVE_IFADDRS_H ifip = spot->ifa_addr; ifflags = spot->ifa_flags; @@ -121,16 +119,25 @@ Machine::Machine(char const* the_hostname, sockaddr const* addr) // get the interface's flags struct ifreq ifr; ink_strlcpy(ifr.ifr_name, spot->ifr_name, IFNAMSIZ); - if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) ifflags = ifr.ifr_flags; - else ifflags = 0; // flags not available, default to just looking at IP + if (ioctl(s, SIOCGIFFLAGS, &ifr) == 0) + ifflags = ifr.ifr_flags; + else + ifflags = 0; // flags not available, default to just looking at IP #endif - if (!ats_is_ip(ifip)) spot_type = NA; - else if (ats_is_ip_loopback(ifip) || (IFF_LOOPBACK & ifflags)) spot_type = LO; - else if (ats_is_ip_linklocal(ifip)) spot_type = LL; - else if (ats_is_ip_private(ifip)) spot_type = PR; - else if (ats_is_ip_multicast(ifip)) spot_type = MC; - else spot_type = GL; - if (spot_type == NA) continue; // Next! + if (!ats_is_ip(ifip)) + spot_type = NA; + else if (ats_is_ip_loopback(ifip) || (IFF_LOOPBACK & ifflags)) + spot_type = LO; + else if (ats_is_ip_linklocal(ifip)) + spot_type = LL; + else if (ats_is_ip_private(ifip)) + spot_type = PR; + else if (ats_is_ip_multicast(ifip)) + spot_type = MC; + else + spot_type = GL; + if (spot_type == NA) + continue; // Next! if (ats_is_ip4(ifip)) { if (spot_type > ip4_type) { @@ -155,27 +162,23 @@ Machine::Machine(char const* the_hostname, sockaddr const* addr) else ats_ip_copy(&ip.sa, &ip6.sa); } -#if ! HAVE_IFADDRS_H +#if !HAVE_IFADDRS_H close(s); #endif } else { // address provided. ats_ip_copy(&ip, addr); - if (ats_is_ip4(addr)) ats_ip_copy(&ip4, addr); - else if (ats_is_ip6(addr)) ats_ip_copy(&ip6, addr); + if (ats_is_ip4(addr)) + ats_ip_copy(&ip4, addr); + else if (ats_is_ip6(addr)) + ats_ip_copy(&ip6, addr); - status = getnameinfo( - addr, ats_ip_size(addr), - localhost, sizeof(localhost) - 1, - 0, 0, // do not request service info - 0 // no flags. - ); + status = getnameinfo(addr, ats_ip_size(addr), localhost, sizeof(localhost) - 1, 0, 0, // do not request service info + 0 // no flags. + ); if (0 != status) { ip_text_buffer ipbuff; - Warning("Failed to find hostname for address '%s' - %s" - , ats_ip_ntop(addr, ipbuff, sizeof(ipbuff)) - , gai_strerror(status) - ); + Warning("Failed to find hostname for address '%s' - %s", ats_ip_ntop(addr, ipbuff, sizeof(ipbuff)), gai_strerror(status)); } else hostname = ats_strdup(localhost); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/utils/OneWayMultiTunnel.cc ---------------------------------------------------------------------- diff --git a/iocore/utils/OneWayMultiTunnel.cc b/iocore/utils/OneWayMultiTunnel.cc index 549f51d..fc28305 100644 --- a/iocore/utils/OneWayMultiTunnel.cc +++ b/iocore/utils/OneWayMultiTunnel.cc @@ -39,8 +39,7 @@ ClassAllocator<OneWayMultiTunnel> OneWayMultiTunnelAllocator("OneWayMultiTunnelAllocator"); -OneWayMultiTunnel::OneWayMultiTunnel(): -OneWayTunnel(), n_vioTargets(0), source_read_previously_completed(false) +OneWayMultiTunnel::OneWayMultiTunnel() : OneWayTunnel(), n_vioTargets(0), source_read_previously_completed(false) { } @@ -51,20 +50,20 @@ OneWayMultiTunnel::OneWayMultiTunnel_alloc() } void -OneWayMultiTunnel::OneWayMultiTunnel_free(OneWayMultiTunnel * pOWT) +OneWayMultiTunnel::OneWayMultiTunnel_free(OneWayMultiTunnel *pOWT) { - pOWT->mutex = NULL; OneWayMultiTunnelAllocator.free(pOWT); } void -OneWayMultiTunnel::init(VConnection * vcSource, VConnection ** vcTargets, int n_vcTargets, Continuation * aCont, int size_estimate, int64_t nbytes, bool asingle_buffer, /* = true */ - bool aclose_source, /* = false */ - bool aclose_targets, /* = false */ +OneWayMultiTunnel::init(VConnection *vcSource, VConnection **vcTargets, int n_vcTargets, Continuation *aCont, int size_estimate, + int64_t nbytes, bool asingle_buffer, /* = true */ + bool aclose_source, /* = false */ + bool aclose_targets, /* = false */ Transform_fn aManipulate_fn, int water_mark) { - mutex = aCont ? (ProxyMutex *) aCont->mutex : new_ProxyMutex(); + mutex = aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex(); cont = aCont; manipulate_fn = aManipulate_fn; close_source = aclose_source; @@ -106,15 +105,15 @@ OneWayMultiTunnel::init(VConnection * vcSource, VConnection ** vcTargets, int n_ } void -OneWayMultiTunnel::init(Continuation * aCont, - VIO * SourceVio, VIO ** TargetVios, int n_TargetVios, bool aclose_source, bool aclose_targets) +OneWayMultiTunnel::init(Continuation *aCont, VIO *SourceVio, VIO **TargetVios, int n_TargetVios, bool aclose_source, + bool aclose_targets) { - - mutex = aCont ? (ProxyMutex *) aCont->mutex : new_ProxyMutex(); + mutex = aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex(); cont = aCont; single_buffer = true; manipulate_fn = 0; - n_connections = n_TargetVios + 1;; + n_connections = n_TargetVios + 1; + ; close_source = aclose_source; close_target = aclose_targets; // The read on the source vio may have already been completed, yet @@ -136,7 +135,6 @@ OneWayMultiTunnel::init(Continuation * aCont, vioTargets[i] = TargetVios[i]; vioTargets[i]->set_continuation(this); } - } ////////////////////////////////////////////////////////////////////////////// @@ -148,7 +146,7 @@ OneWayMultiTunnel::init(Continuation * aCont, int OneWayMultiTunnel::startEvent(int event, void *data) { - VIO *vio = (VIO *) data; + VIO *vio = (VIO *)data; int ret = VC_EVENT_DONE; int result = 0; @@ -160,15 +158,14 @@ OneWayMultiTunnel::startEvent(int event, void *data) // handle the event // switch (event) { - - case VC_EVENT_READ_READY:{ // SunCC uses old scoping rules - transform(vioSource->buffer, topOutBuffer); - for (int i = 0; i < n_vioTargets; i++) - if (vioTargets[i]) - vioTargets[i]->reenable(); - ret = VC_EVENT_CONT; - break; - } + case VC_EVENT_READ_READY: { // SunCC uses old scoping rules + transform(vioSource->buffer, topOutBuffer); + for (int i = 0; i < n_vioTargets; i++) + if (vioTargets[i]) + vioTargets[i]->reenable(); + ret = VC_EVENT_CONT; + break; + } case VC_EVENT_WRITE_READY: if (vioSource) @@ -186,22 +183,22 @@ OneWayMultiTunnel::startEvent(int event, void *data) goto Lwrite_complete; Lread_complete: - case VC_EVENT_READ_COMPLETE:{// SunCC uses old scoping rules - // set write nbytes to the current buffer size - // - for (int i = 0; i < n_vioTargets; i++) - if (vioTargets[i]) { - vioTargets[i]->nbytes = vioTargets[i]->ndone + vioTargets[i]->buffer.reader()->read_avail(); - vioTargets[i]->reenable(); - } - close_source_vio(0); - ret = VC_EVENT_DONE; - break; - } + case VC_EVENT_READ_COMPLETE: { // SunCC uses old scoping rules + // set write nbytes to the current buffer size + // + for (int i = 0; i < n_vioTargets; i++) + if (vioTargets[i]) { + vioTargets[i]->nbytes = vioTargets[i]->ndone + vioTargets[i]->buffer.reader()->read_avail(); + vioTargets[i]->reenable(); + } + close_source_vio(0); + ret = VC_EVENT_DONE; + break; + } Lwrite_complete: case VC_EVENT_WRITE_COMPLETE: - close_target_vio(0, (VIO *) data); + close_target_vio(0, (VIO *)data); if ((n_connections == 0) || (n_connections == 1 && source_read_previously_completed)) goto Ldone; else if (vioSource) @@ -230,7 +227,7 @@ OneWayMultiTunnel::startEvent(int event, void *data) } void -OneWayMultiTunnel::close_target_vio(int result, VIO * vio) +OneWayMultiTunnel::close_target_vio(int result, VIO *vio) { for (int i = 0; i < n_vioTargets; i++) { VIO *v = vioTargets[i]; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/iocore/utils/OneWayTunnel.cc ---------------------------------------------------------------------- diff --git a/iocore/utils/OneWayTunnel.cc b/iocore/utils/OneWayTunnel.cc index efe5011..1be18d6 100644 --- a/iocore/utils/OneWayTunnel.cc +++ b/iocore/utils/OneWayTunnel.cc @@ -46,7 +46,7 @@ ClassAllocator<OneWayTunnel> OneWayTunnelAllocator("OneWayTunnelAllocator"); inline void -transfer_data(MIOBufferAccessor & in_buf, MIOBufferAccessor & out_buf) +transfer_data(MIOBufferAccessor &in_buf, MIOBufferAccessor &out_buf) { ink_release_assert(!"Not Implemented."); @@ -62,10 +62,9 @@ transfer_data(MIOBufferAccessor & in_buf, MIOBufferAccessor & out_buf) out_buf.writer()->fill(n); } -OneWayTunnel::OneWayTunnel():Continuation(0), -vioSource(0), vioTarget(0), cont(0), manipulate_fn(0), -n_connections(0), lerrno(0), single_buffer(0), -close_source(0), close_target(0), tunnel_till_done(0), tunnel_peer(0), free_vcs(true) +OneWayTunnel::OneWayTunnel() + : Continuation(0), vioSource(0), vioTarget(0), cont(0), manipulate_fn(0), n_connections(0), lerrno(0), single_buffer(0), + close_source(0), close_target(0), tunnel_till_done(0), tunnel_peer(0), free_vcs(true) { } @@ -76,17 +75,16 @@ OneWayTunnel::OneWayTunnel_alloc() } void -OneWayTunnel::OneWayTunnel_free(OneWayTunnel * pOWT) +OneWayTunnel::OneWayTunnel_free(OneWayTunnel *pOWT) { - pOWT->mutex = NULL; OneWayTunnelAllocator.free(pOWT); } void -OneWayTunnel::SetupTwoWayTunnel(OneWayTunnel * east, OneWayTunnel * west) +OneWayTunnel::SetupTwoWayTunnel(OneWayTunnel *east, OneWayTunnel *west) { - //make sure the both use the same mutex + // make sure the both use the same mutex ink_assert(east->mutex == west->mutex); east->tunnel_peer = west; @@ -97,31 +95,20 @@ OneWayTunnel::~OneWayTunnel() { } -OneWayTunnel::OneWayTunnel(Continuation * aCont, Transform_fn aManipulate_fn, bool aclose_source, bool aclose_target) -: -Continuation(aCont - ? (ProxyMutex *) aCont->mutex - : new_ProxyMutex()), -cont(aCont), -manipulate_fn(aManipulate_fn), -n_connections(2), -lerrno(0), -single_buffer(true), close_source(aclose_source), close_target(aclose_target), tunnel_till_done(false), free_vcs(false) +OneWayTunnel::OneWayTunnel(Continuation *aCont, Transform_fn aManipulate_fn, bool aclose_source, bool aclose_target) + : Continuation(aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex()), cont(aCont), manipulate_fn(aManipulate_fn), + n_connections(2), lerrno(0), single_buffer(true), close_source(aclose_source), close_target(aclose_target), + tunnel_till_done(false), free_vcs(false) { ink_assert(!"This form of OneWayTunnel() constructor not supported"); } void -OneWayTunnel::init(VConnection * vcSource, - VConnection * vcTarget, - Continuation * aCont, - int size_estimate, - ProxyMutex * aMutex, - int64_t nbytes, - bool asingle_buffer, - bool aclose_source, bool aclose_target, Transform_fn aManipulate_fn, int water_mark) +OneWayTunnel::init(VConnection *vcSource, VConnection *vcTarget, Continuation *aCont, int size_estimate, ProxyMutex *aMutex, + int64_t nbytes, bool asingle_buffer, bool aclose_source, bool aclose_target, Transform_fn aManipulate_fn, + int water_mark) { - mutex = aCont ? (ProxyMutex *) aCont->mutex : (aMutex ? aMutex : new_ProxyMutex()); + mutex = aCont ? (ProxyMutex *)aCont->mutex : (aMutex ? aMutex : new_ProxyMutex()); cont = aMutex ? NULL : aCont; single_buffer = asingle_buffer; manipulate_fn = aManipulate_fn; @@ -140,7 +127,7 @@ OneWayTunnel::init(VConnection * vcSource, else size_index = default_large_iobuffer_size; - Debug("one_way_tunnel", "buffer size index [%" PRId64"] [%d]\n", size_index, size_estimate); + Debug("one_way_tunnel", "buffer size index [%" PRId64 "] [%d]\n", size_index, size_estimate); // enqueue read request on vcSource. MIOBuffer *buf1 = new_MIOBuffer(size_index); @@ -161,13 +148,11 @@ OneWayTunnel::init(VConnection * vcSource, } void -OneWayTunnel::init(VConnection * vcSource, - VConnection * vcTarget, - Continuation * aCont, - VIO * SourceVio, IOBufferReader * reader, bool aclose_source, bool aclose_target) +OneWayTunnel::init(VConnection *vcSource, VConnection *vcTarget, Continuation *aCont, VIO *SourceVio, IOBufferReader *reader, + bool aclose_source, bool aclose_target) { - (void) vcSource; - mutex = aCont ? (ProxyMutex *) aCont->mutex : new_ProxyMutex(); + (void)vcSource; + mutex = aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex(); cont = aCont; single_buffer = true; manipulate_fn = 0; @@ -191,9 +176,9 @@ OneWayTunnel::init(VConnection * vcSource, } void -OneWayTunnel::init(Continuation * aCont, VIO * SourceVio, VIO * TargetVio, bool aclose_source, bool aclose_target) +OneWayTunnel::init(Continuation *aCont, VIO *SourceVio, VIO *TargetVio, bool aclose_source, bool aclose_target) { - mutex = aCont ? (ProxyMutex *) aCont->mutex : new_ProxyMutex(); + mutex = aCont ? (ProxyMutex *)aCont->mutex : new_ProxyMutex(); cont = aCont; single_buffer = true; manipulate_fn = 0; @@ -216,7 +201,7 @@ OneWayTunnel::init(Continuation * aCont, VIO * SourceVio, VIO * TargetVio, bool void -OneWayTunnel::transform(MIOBufferAccessor & in_buf, MIOBufferAccessor & out_buf) +OneWayTunnel::transform(MIOBufferAccessor &in_buf, MIOBufferAccessor &out_buf) { if (manipulate_fn) manipulate_fn(in_buf, out_buf); @@ -236,7 +221,7 @@ OneWayTunnel::transform(MIOBufferAccessor & in_buf, MIOBufferAccessor & out_buf) int OneWayTunnel::startEvent(int event, void *data) { - VIO *vio = (VIO *) data; + VIO *vio = (VIO *)data; int ret = VC_EVENT_DONE; int result = 0; @@ -251,7 +236,6 @@ OneWayTunnel::startEvent(int event, void *data) // handle the event // switch (event) { - case ONE_WAY_TUNNEL_EVENT_PEER_CLOSE: /* This event is sent out by our peer */ ink_assert(tunnel_peer); @@ -294,14 +278,14 @@ OneWayTunnel::startEvent(int event, void *data) Lerror: case VC_EVENT_ERROR: - lerrno = ((VIO *) data)->vc_server->lerrno; + lerrno = ((VIO *)data)->vc_server->lerrno; case VC_EVENT_INACTIVITY_TIMEOUT: case VC_EVENT_ACTIVE_TIMEOUT: result = -1; Ldone: case VC_EVENT_WRITE_COMPLETE: if (tunnel_peer) { - //inform the peer: + // inform the peer: tunnel_peer->startEvent(ONE_WAY_TUNNEL_EVENT_PEER_CLOSE, data); } close_source_vio(result); @@ -324,7 +308,6 @@ OneWayTunnel::startEvent(int event, void *data) void OneWayTunnel::close_source_vio(int result) { - if (vioSource) { if (last_connection() || !single_buffer) { free_MIOBuffer(vioSource->buffer.writer()); @@ -339,10 +322,9 @@ OneWayTunnel::close_source_vio(int result) } void -OneWayTunnel::close_target_vio(int result, VIO * vio) +OneWayTunnel::close_target_vio(int result, VIO *vio) { - - (void) vio; + (void)vio; if (vioTarget) { if (last_connection() || !single_buffer) { free_MIOBuffer(vioTarget->buffer.writer());
