trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [trafficserver] 24/33: TS-4425: Switch iocore/net over to Ptr::get().
Date Wed, 11 May 2016 20:31:48 GMT
This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit d5b79b213188a0ab1d769ac3c17244b274d1e632
Author: James Peach <jpeach@apache.org>
AuthorDate: Sat May 7 12:46:11 2016 -0700

    TS-4425: Switch iocore/net over to Ptr::get().
---
 iocore/net/I_UDPPacket.h          |  2 +-
 iocore/net/P_CompletionUtil.h     |  2 +-
 iocore/net/P_Socks.h              |  2 +-
 iocore/net/P_UDPConnection.h      |  2 +-
 iocore/net/P_UDPIOEvent.h         | 23 ++++++++++-----
 iocore/net/P_UDPPacket.h          | 18 ++++++------
 iocore/net/P_UnixCompletionUtil.h |  2 +-
 iocore/net/Socks.cc               |  2 +-
 iocore/net/UnixNetAccept.cc       | 19 ++++++++-----
 iocore/net/UnixNetProcessor.cc    | 12 ++++----
 iocore/net/UnixNetVConnection.cc  | 60 +++++++++++++++++++++++----------------
 iocore/net/UnixUDPNet.cc          |  9 +++---
 12 files changed, 89 insertions(+), 64 deletions(-)

diff --git a/iocore/net/I_UDPPacket.h b/iocore/net/I_UDPPacket.h
index 15850f2..7b0be5f 100644
--- a/iocore/net/I_UDPPacket.h
+++ b/iocore/net/I_UDPPacket.h
@@ -49,7 +49,7 @@ public:
   void setConnection(UDPConnection *c);
   UDPConnection *getConnection();
   IOBufferBlock *getIOBlockChain();
-  int64_t getPktLength();
+  int64_t getPktLength() const;
 
   /**
      Add IOBufferBlock (chain) to end of packet.
diff --git a/iocore/net/P_CompletionUtil.h b/iocore/net/P_CompletionUtil.h
index 5c4b9a4..03128c2 100644
--- a/iocore/net/P_CompletionUtil.h
+++ b/iocore/net/P_CompletionUtil.h
@@ -33,7 +33,7 @@ public:
   static void setContinuation(Event *e, Continuation *c);
   static void *getHandle(Event *e);
   static void setHandle(Event *e, void *handle);
-  static void setInfo(Event *e, int fd, IOBufferBlock *buf, int actual, int errno_);
+  static void setInfo(Event *e, int fd, const Ptr<IOBufferBlock> &buf, int actual,
int errno_);
   static void setInfo(Event *e, int fd, struct msghdr *msg, int actual, int errno_);
   static int getBytesTransferred(Event *e);
   static IOBufferBlock *getIOBufferBlock(Event *e);
diff --git a/iocore/net/P_Socks.h b/iocore/net/P_Socks.h
index 7cf5e24..2b7270b 100644
--- a/iocore/net/P_Socks.h
+++ b/iocore/net/P_Socks.h
@@ -140,7 +140,7 @@ struct SocksEntry : public Continuation {
   int startEvent(int event, void *data);
   int mainEvent(int event, void *data);
   void findServer();
-  void init(ProxyMutex *m, SocksNetVC *netvc, unsigned char socks_support, unsigned char
ver);
+  void init(Ptr<ProxyMutex> &m, SocksNetVC *netvc, unsigned char socks_support,
unsigned char ver);
   void free();
 
   SocksEntry()
diff --git a/iocore/net/P_UDPConnection.h b/iocore/net/P_UDPConnection.h
index 4ee94f7..677c4e7 100644
--- a/iocore/net/P_UDPConnection.h
+++ b/iocore/net/P_UDPConnection.h
@@ -156,7 +156,7 @@ TS_INLINE void
 UDPConnection::setContinuation(Continuation *c)
 {
   // it is not safe to switch among continuations that don't share locks
-  ink_assert(mutex == NULL || c->mutex == mutex);
+  ink_assert(mutex.get() == NULL || c->mutex == mutex);
   mutex = c->mutex;
   ((UDPConnectionInternal *)this)->continuation = c;
 }
diff --git a/iocore/net/P_UDPIOEvent.h b/iocore/net/P_UDPIOEvent.h
index 4daddae..d202d64 100644
--- a/iocore/net/P_UDPIOEvent.h
+++ b/iocore/net/P_UDPIOEvent.h
@@ -31,14 +31,16 @@ class UDPIOEvent : public Event
 public:
   UDPIOEvent() : fd(-1), err(0), m(0), handle(0), b(0), bytesTransferred(0){};
   ~UDPIOEvent(){};
+
   void
-  setInfo(int fd_, IOBufferBlock *b_, int bytesTransferred_, int errno_)
+  setInfo(int fd_, const Ptr<IOBufferBlock> &b_, int bytesTransferred_, int errno_)
   {
     fd = fd_;
     b = b_;
     bytesTransferred = bytesTransferred_;
     err = errno_;
   };
+
   void
   setInfo(int fd_, struct msghdr *m_, int bytesTransferred_, int errno_)
   {
@@ -47,37 +49,44 @@ public:
     bytesTransferred = bytesTransferred_;
     err = errno_;
   };
+
   void
   setHandle(void *v)
   {
     handle = v;
   }
+
   void *
   getHandle()
   {
     return handle;
   }
-  void free();
+
   int
-  getBytesTransferred()
+  getBytesTransferred() const
   {
     return bytesTransferred;
   }
+
   IOBufferBlock *
-  getIOBufferBlock()
+  getIOBufferBlock() const
   {
-    return b;
+    return b.get();
   }
+
   int
-  getError()
+  getError() const
   {
     return err;
   }
+
   Continuation *
-  getContinuation()
+  getContinuation() const
   {
     return continuation;
   }
+
+  void free();
   static void free(UDPIOEvent *e);
 
 private:
diff --git a/iocore/net/P_UDPPacket.h b/iocore/net/P_UDPPacket.h
index 8c6bd6a..9a8d60f 100644
--- a/iocore/net/P_UDPPacket.h
+++ b/iocore/net/P_UDPPacket.h
@@ -91,9 +91,9 @@ UDPPacket::append_block(IOBufferBlock *block)
 
   if (block) {
     if (p->chain) { // append to end
-      IOBufferBlock *last = p->chain;
-      while (last->next != NULL) {
-        last = last->next;
+      IOBufferBlock *last = p->chain.get();
+      while (last->next) {
+        last = last->next.get();
       }
       last->next = block;
     } else {
@@ -103,16 +103,16 @@ UDPPacket::append_block(IOBufferBlock *block)
 }
 
 TS_INLINE int64_t
-UDPPacket::getPktLength()
+UDPPacket::getPktLength() const
 {
   UDPPacketInternal *p = (UDPPacketInternal *)this;
   IOBufferBlock *b;
 
   p->pktLength = 0;
-  b = p->chain;
+  b = p->chain.get();
   while (b) {
     p->pktLength += b->read_avail();
-    b = b->next;
+    b = b->next.get();
   }
   return p->pktLength;
 }
@@ -154,7 +154,8 @@ UDPPacket::setConnection(UDPConnection *c)
 TS_INLINE IOBufferBlock *
 UDPPacket::getIOBlockChain(void)
 {
-  return ((UDPPacketInternal *)this)->chain;
+  ink_assert(dynamic_cast<UDPPacketInternal *>(this) != NULL);
+  return ((UDPPacketInternal *)this)->chain.get();
 }
 
 TS_INLINE UDPConnection *
@@ -199,8 +200,9 @@ new_UDPPacket(struct sockaddr const *to, ink_hrtime when, IOBufferBlock
*buf, in
   while (buf) {
     body = buf->clone();
     p->append_block(body);
-    buf = buf->next;
+    buf = buf->next.get();
   }
+
   return p;
 }
 
diff --git a/iocore/net/P_UnixCompletionUtil.h b/iocore/net/P_UnixCompletionUtil.h
index e9e6235..ea64d98 100644
--- a/iocore/net/P_UnixCompletionUtil.h
+++ b/iocore/net/P_UnixCompletionUtil.h
@@ -66,7 +66,7 @@ completionUtil::setHandle(Event *e, void *handle)
   u->setHandle(handle);
 }
 TS_INLINE void
-completionUtil::setInfo(Event *e, int fd, IOBufferBlock *buf, int actual, int errno_)
+completionUtil::setInfo(Event *e, int fd, const Ptr<IOBufferBlock> &buf, int actual,
int errno_)
 {
   UDPIOEvent *u = (UDPIOEvent *)e;
   u->setInfo(fd, buf, actual, errno_);
diff --git a/iocore/net/Socks.cc b/iocore/net/Socks.cc
index 792c949..b65ee09 100644
--- a/iocore/net/Socks.cc
+++ b/iocore/net/Socks.cc
@@ -41,7 +41,7 @@ socks_conf_struct *g_socks_conf_stuff = 0;
 ClassAllocator<SocksEntry> socksAllocator("socksAllocator");
 
 void
-SocksEntry::init(ProxyMutex *m, SocksNetVC *vc, unsigned char socks_support, unsigned char
ver)
+SocksEntry::init(Ptr<ProxyMutex> &m, SocksNetVC *vc, unsigned char socks_support,
unsigned char ver)
 {
   mutex = m;
   buf = new_MIOBuffer();
diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc
index 0510515..8e06ff1 100644
--- a/iocore/net/UnixNetAccept.cc
+++ b/iocore/net/UnixNetAccept.cc
@@ -84,9 +84,12 @@ net_accept(NetAccept *na, void *ep, bool blockable)
   UnixNetVConnection *vc = NULL;
   Connection con;
 
-  if (!blockable)
-    if (!MUTEX_TAKE_TRY_LOCK_FOR(na->action_->mutex, e->ethread, na->action_->continuation))
+  if (!blockable) {
+    if (!MUTEX_TAKE_TRY_LOCK(na->action_->mutex.get(), e->ethread)) {
       return 0;
+    }
+  }
+
   // do-while for accepting all the connections
   // added by YTS Team, yamsat
   do {
@@ -129,7 +132,7 @@ net_accept(NetAccept *na, void *ep, bool blockable)
 
 Ldone:
   if (!blockable)
-    MUTEX_UNTAKE_LOCK(na->action_->mutex, e->ethread);
+    MUTEX_UNTAKE_LOCK(na->action_->mutex.get(), e->ethread);
   return count;
 }
 
@@ -304,10 +307,12 @@ NetAccept::acceptEvent(int event, void *ep)
   // PollDescriptor *pd = get_PollDescriptor(e->ethread);
   ProxyMutex *m = 0;
 
-  if (action_->mutex)
-    m = action_->mutex;
-  else
-    m = mutex;
+  if (action_->mutex) {
+    m = action_->mutex.get();
+  } else {
+    m = mutex.get();
+  }
+
   MUTEX_TRY_LOCK(lock, m, e->ethread);
   if (lock.is_locked()) {
     if (action_->cancelled) {
diff --git a/iocore/net/UnixNetProcessor.cc b/iocore/net/UnixNetProcessor.cc
index e2c6268..841efc0 100644
--- a/iocore/net/UnixNetProcessor.cc
+++ b/iocore/net/UnixNetProcessor.cc
@@ -85,8 +85,7 @@ Action *
 UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions const &opt)
 {
   EventType upgraded_etype = opt.etype; // setEtype requires non-const ref.
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  ProxyMutex *mutex = this_ethread()->mutex;
   int accept_threads = opt.accept_threads; // might be changed.
   IpEndpoint accept_ip;                    // local binding address.
   char thr_name[MAX_THREAD_NAME_LENGTH];
@@ -181,6 +180,7 @@ UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions
cons
     setsockopt(na->server.fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &should_filter_int, sizeof(int));
   }
 #endif
+
 #ifdef TCP_INIT_CWND
   int tcp_init_cwnd = 0;
   REC_ReadConfigInteger(tcp_init_cwnd, "proxy.config.http.server_tcp_init_cwnd");
@@ -191,14 +191,14 @@ UnixNetProcessor::accept_internal(Continuation *cont, int fd, AcceptOptions
cons
     }
   }
 #endif
-  return na->action_;
+
+  return na->action_.get();
 }
 
 Action *
 UnixNetProcessor::connect_re_internal(Continuation *cont, sockaddr const *target, NetVCOptions
*opt)
 {
-  ProxyMutex *mutex = cont->mutex;
-  EThread *t = mutex->thread_holding;
+  EThread *t = cont->mutex->thread_holding;
   UnixNetVConnection *vc = (UnixNetVConnection *)this->allocate_vc(t);
 
   if (opt)
@@ -364,7 +364,7 @@ struct CheckConnect : public Continuation {
     }
   }
 
-  CheckConnect(ProxyMutex *m = NULL) : Continuation(m), connect_status(-1), recursion(0),
timeout(0)
+  explicit CheckConnect(Ptr<ProxyMutex> &m) : Continuation(m.get()), connect_status(-1),
recursion(0), timeout(0)
   {
     SET_HANDLER(&CheckConnect::handle_connect);
     buf = new_empty_MIOBuffer(1);
diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
index 59b30bd..899887a 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -291,7 +291,7 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
 
   // read data
   int64_t rattempted = 0, total_read = 0;
-  int niov = 0;
+  unsigned niov = 0;
   IOVec tiovec[NET_MAX_IOV];
   if (toread) {
     IOBufferBlock *b = buf.writer()->first_write_block();
@@ -311,14 +311,13 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
           if (a >= togo)
             break;
         }
-        b = b->next;
+        b = b->next.get();
       }
 
-      if (niov == 1) {
-        r = socketManager.read(vc->con.fd, tiovec[0].iov_base, tiovec[0].iov_len);
-      } else {
-        r = socketManager.readv(vc->con.fd, &tiovec[0], niov);
-      }
+      ink_assert(niov > 0);
+      ink_assert(niov < countof(tiovec));
+      r = socketManager.readv(vc->con.fd, &tiovec[0], niov);
+
       NET_INCREMENT_DYN_STAT(net_calls_to_read_stat);
 
       if (vc->origin_trace) {
@@ -390,10 +389,12 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
       Debug("iocore_net", "read_from_net, read finished - signal done");
       return;
     } else {
-      if (read_signal_and_update(VC_EVENT_READ_READY, vc) != EVENT_CONT)
+      if (read_signal_and_update(VC_EVENT_READ_READY, vc) != EVENT_CONT) {
         return;
+      }
+
       // change of lock... don't look at shared variables!
-      if (lock.get_mutex() != s->vio.mutex.m_ptr) {
+      if (lock.get_mutex() != s->vio.mutex.get()) {
         read_reschedule(nh, vc);
         return;
       }
@@ -431,7 +432,7 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
 
   MUTEX_TRY_LOCK_FOR(lock, s->vio.mutex, thread, s->vio._cont);
 
-  if (!lock.is_locked() || lock.get_mutex() != s->vio.mutex.m_ptr) {
+  if (!lock.is_locked() || lock.get_mutex() != s->vio.mutex.get()) {
     write_reschedule(nh, vc);
     return;
   }
@@ -574,12 +575,14 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
       if (write_signal_and_update(VC_EVENT_WRITE_READY, vc) != EVENT_CONT) {
         return;
       }
+
       // change of lock... don't look at shared variables!
-      if (lock.get_mutex() != s->vio.mutex.m_ptr) {
+      if (lock.get_mutex() != s->vio.mutex.get()) {
         write_reschedule(nh, vc);
         return;
       }
     }
+
     if (!buf.reader()->read_avail()) {
       write_disable(nh, vc);
       return;
@@ -950,11 +953,11 @@ UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted,
 
   // XXX Rather than dealing with the block directly, we should use the IOBufferReader API.
   int64_t offset = buf.reader()->start_offset;
-  IOBufferBlock *b = buf.reader()->block;
+  IOBufferBlock *b = buf.reader()->block.get();
 
   do {
     IOVec tiovec[NET_MAX_IOV];
-    int niov = 0;
+    unsigned niov = 0;
     int64_t total_written_last = total_written;
     while (b && niov < NET_MAX_IOV) {
       // check if we have done this block
@@ -962,15 +965,20 @@ UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted,
       l -= offset;
       if (l <= 0) {
         offset = -l;
-        b = b->next;
+        b = b->next.get();
         continue;
       }
+
       // check if to amount to write exceeds that in this buffer
       int64_t wavail = towrite - total_written;
-      if (l > wavail)
+      if (l > wavail) {
         l = wavail;
-      if (!l)
+      }
+
+      if (!l) {
         break;
+      }
+
       total_written += l;
       // build an iov entry
       tiovec[niov].iov_len = l;
@@ -978,13 +986,14 @@ UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted,
       niov++;
       // on to the next block
       offset = 0;
-      b = b->next;
+      b = b->next.get();
     }
+
     wattempted = total_written - total_written_last;
-    if (niov == 1)
-      r = socketManager.write(con.fd, tiovec[0].iov_base, tiovec[0].iov_len);
-    else
-      r = socketManager.writev(con.fd, &tiovec[0], niov);
+
+    ink_assert(niov > 0);
+    ink_assert(niov < countof(tiovec));
+    r = socketManager.writev(con.fd, &tiovec[0], niov);
 
     if (origin_trace) {
       char origin_trace_ip[INET6_ADDRSTRLEN];
@@ -1136,11 +1145,12 @@ 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 ? read.vio.mutex : e->ethread->mutex, e->ethread);
+  MUTEX_TRY_LOCK(wlock, write.vio.mutex ? write.vio.mutex : 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)) {
+      (read.vio.mutex && rlock.get_mutex() != read.vio.mutex.get()) ||
+      (write.vio.mutex && wlock.get_mutex() != write.vio.mutex.get())) {
 #ifdef INACTIVITY_TIMEOUT
     if (e == active_timeout)
 #endif
diff --git a/iocore/net/UnixUDPNet.cc b/iocore/net/UnixUDPNet.cc
index a17d46c..5370173 100644
--- a/iocore/net/UnixUDPNet.cc
+++ b/iocore/net/UnixUDPNet.cc
@@ -380,7 +380,7 @@ 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, readbuf, rlen, errno);
     c = completionUtil::getContinuation(event);
     // TODO: Should we deal with the return code?
     c->handleEvent(NET_EVENT_DATAGRAM_READ_ERROR, event);
@@ -434,7 +434,7 @@ UDPNetProcessor::recvfrom_re(Continuation *cont, void *token, int fd,
struct soc
 
   if (actual > 0) {
     completionUtil::setThread(event, this_ethread());
-    completionUtil::setInfo(event, fd, buf, actual, errno);
+    completionUtil::setInfo(event, fd, make_ptr(buf), actual, errno);
     buf->fill(actual);
     cont->handleEvent(NET_EVENT_DATAGRAM_READ_COMPLETE, event);
     completionUtil::destroy(event);
@@ -449,7 +449,7 @@ UDPNetProcessor::recvfrom_re(Continuation *cont, void *token, int fd,
struct soc
     return event;
   } else {
     completionUtil::setThread(event, this_ethread());
-    completionUtil::setInfo(event, fd, buf, actual, errno);
+    completionUtil::setInfo(event, fd, make_ptr(buf), actual, errno);
     cont->handleEvent(NET_EVENT_DATAGRAM_READ_ERROR, event);
     completionUtil::destroy(event);
     return ACTION_IO_ERROR;
@@ -749,7 +749,6 @@ sendPackets:
 void
 UDPQueue::SendUDPPacket(UDPPacketInternal *p, int32_t /* pktLen ATS_UNUSED */)
 {
-  IOBufferBlock *b;
   struct msghdr msg;
   struct iovec iov[32];
   int real_len = 0;
@@ -767,7 +766,7 @@ UDPQueue::SendUDPPacket(UDPPacketInternal *p, int32_t /* pktLen ATS_UNUSED
*/)
   msg.msg_namelen = sizeof(p->to);
   iov_len = 0;
 
-  for (b = p->chain; b != NULL; b = b->next) {
+  for (IOBufferBlock *b = p->chain.get(); b != NULL; b = b->next.get()) {
     iov[iov_len].iov_base = (caddr_t)b->start();
     iov[iov_len].iov_len = b->size();
     real_len += iov[iov_len].iov_len;

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>.

Mime
View raw message