From 0b5f8dd430abf196587b7b2c07d58651c36bbfac Mon Sep 17 00:00:00 2001 From: Bryan Call Date: Fri, 12 Aug 2016 11:00:11 -0700 Subject: [PATCH] TS-4732: Changing the do_io_read API so it can be called with NULL and 0 byte values. Allowing do_io_read and do_io_write to not warn on closed connection when we are only trying to disable the reads and writes for it. Removed some macros that were used in a few places (not all the time) and a couple that were not used at all. (cherry picked from commit 1975d679663453348057bb7155bdd3c17ac73880) --- iocore/net/UnixNetVConnection.cc | 26 ++++++++++---------------- proxy/http2/Http2ClientSession.h | 3 +-- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc index 441d20ee9b9..c98662f47dd 100644 --- a/iocore/net/UnixNetVConnection.cc +++ b/iocore/net/UnixNetVConnection.cc @@ -29,11 +29,6 @@ #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 -#define enable_read(_vc) (_vc)->read.enabled = 1 -#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) #else @@ -624,8 +619,7 @@ UnixNetVConnection::get_data(int id, void *data) VIO * UnixNetVConnection::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) { - ink_assert(c || 0 == nbytes); - if (closed) { + if (closed && !(c == NULL && nbytes == 0 && buf == NULL)) { Error("do_io_read invoked on closed vc %p, cont %p, nbytes %" PRId64 ", buf %p", this, c, nbytes, buf); return NULL; } @@ -641,7 +635,7 @@ UnixNetVConnection::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) read.vio.reenable(); } else { read.vio.buffer.clear(); - disable_read(this); + read.enabled = 0; } return &read.vio; } @@ -649,7 +643,7 @@ UnixNetVConnection::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) VIO * UnixNetVConnection::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *reader, bool owner) { - if (closed) { + if (closed && !(c == NULL && nbytes == 0 && reader == NULL)) { Error("do_io_write invoked on closed vc %p, cont %p, nbytes %" PRId64 ", reader %p", this, c, nbytes, reader); return NULL; } @@ -665,7 +659,7 @@ UnixNetVConnection::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader if (nbytes && !write.enabled) write.vio.reenable(); } else { - disable_write(this); + write.enabled = 0; } return &write.vio; } @@ -673,8 +667,8 @@ UnixNetVConnection::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader void UnixNetVConnection::do_io_close(int alerrno /* = -1 */) { - disable_read(this); - disable_write(this); + read.enabled = 0; + write.enabled = 0; read.vio.buffer.clear(); read.vio.nbytes = 0; read.vio.op = VIO::NONE; @@ -705,22 +699,22 @@ UnixNetVConnection::do_io_shutdown(ShutdownHowTo_t howto) switch (howto) { case IO_SHUTDOWN_READ: socketManager.shutdown(((UnixNetVConnection *)this)->con.fd, 0); - disable_read(this); + read.enabled = 0; 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); - disable_write(this); + write.enabled = 0; 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); - disable_read(this); - disable_write(this); + read.enabled = 0; + write.enabled = 0; read.vio.buffer.clear(); read.vio.nbytes = 0; write.vio.buffer.clear(); diff --git a/proxy/http2/Http2ClientSession.h b/proxy/http2/Http2ClientSession.h index a6a6d6991af..58d38595900 100644 --- a/proxy/http2/Http2ClientSession.h +++ b/proxy/http2/Http2ClientSession.h @@ -187,8 +187,7 @@ class Http2ClientSession : public ProxyClientSession, public PluginIdentity virtual void release_netvc() { - // Make sure the vio's are also released to avoid - // later surprises in inactivity timeout + // Make sure the vio's are also released to avoid later surprises in inactivity timeout if (client_vc) { client_vc->do_io_read(NULL, 0, NULL); client_vc->do_io_write(NULL, 0, NULL);