mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
ircd::net::socket: Change behavior of non-blocking read_() calls to not throw for EAGAIN.
This commit is contained in:
parent
3a9e85c294
commit
5c359f22f3
3 changed files with 39 additions and 46 deletions
|
@ -208,7 +208,6 @@ catch(const boost::system::system_error &e)
|
|||
template<class iov>
|
||||
size_t
|
||||
ircd::net::socket::read_any(iov&& bufs)
|
||||
try
|
||||
{
|
||||
assert(!blocking(*this));
|
||||
static const auto completion
|
||||
|
@ -216,39 +215,49 @@ try
|
|||
asio::transfer_all()
|
||||
};
|
||||
|
||||
boost::system::error_code ec;
|
||||
const size_t ret
|
||||
{
|
||||
asio::read(ssl, std::forward<iov>(bufs), completion)
|
||||
asio::read(ssl, std::forward<iov>(bufs), completion, ec)
|
||||
};
|
||||
|
||||
in.bytes += ret;
|
||||
++in.calls;
|
||||
return ret;
|
||||
}
|
||||
catch(const boost::system::system_error &e)
|
||||
{
|
||||
throw_system_error(e);
|
||||
|
||||
if(likely(!ec))
|
||||
return ret;
|
||||
|
||||
if(ec == boost::system::errc::resource_unavailable_try_again)
|
||||
return ret;
|
||||
|
||||
throw_system_error(ec);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
/// Non-blocking; One system call only; never throws eof;
|
||||
template<class iov>
|
||||
size_t
|
||||
ircd::net::socket::read_one(iov&& bufs)
|
||||
try
|
||||
{
|
||||
assert(!blocking(*this));
|
||||
|
||||
boost::system::error_code ec;
|
||||
const size_t ret
|
||||
{
|
||||
ssl.read_some(std::forward<iov>(bufs))
|
||||
ssl.read_some(std::forward<iov>(bufs), ec)
|
||||
};
|
||||
|
||||
in.bytes += ret;
|
||||
++in.calls;
|
||||
return ret;
|
||||
}
|
||||
catch(const boost::system::system_error &e)
|
||||
{
|
||||
throw_system_error(e);
|
||||
|
||||
if(likely(!ec))
|
||||
return ret;
|
||||
|
||||
if(ec == boost::system::errc::resource_unavailable_try_again)
|
||||
return ret;
|
||||
|
||||
throw_system_error(ec);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
/// Yields ircd::ctx until all buffers are sent.
|
||||
|
|
16
ircd/net.cc
16
ircd/net.cc
|
@ -355,7 +355,6 @@ ircd::net::discard_all(socket &socket,
|
|||
buffer, std::min(remain, sizeof(buffer))
|
||||
};
|
||||
|
||||
__builtin_prefetch(data(mb), 1, 0); // 1 = write, 0 = no cache
|
||||
remain -= read_all(socket, mb);
|
||||
}
|
||||
|
||||
|
@ -373,23 +372,18 @@ ircd::net::discard_any(socket &socket,
|
|||
{
|
||||
static char buffer[512] alignas(16);
|
||||
|
||||
size_t remain{len}; while(remain) try
|
||||
size_t remain{len}; while(remain)
|
||||
{
|
||||
const mutable_buffer mb
|
||||
{
|
||||
buffer, std::min(remain, sizeof(buffer))
|
||||
};
|
||||
|
||||
__builtin_prefetch(data(mb), 1, 0); // 1 = write, 0 = no cache
|
||||
remain -= read_one(socket, mb);
|
||||
}
|
||||
catch(const std::system_error &e)
|
||||
{
|
||||
if(e.code() == std::errc::resource_unavailable_try_again)
|
||||
if(remain <= len)
|
||||
break;
|
||||
size_t read;
|
||||
if(!(read = read_one(socket, mb)))
|
||||
break;
|
||||
|
||||
throw;
|
||||
remain -= read;
|
||||
}
|
||||
|
||||
return len - remain;
|
||||
|
|
|
@ -1922,7 +1922,14 @@ try
|
|||
{
|
||||
overrun = process_read_next(overrun, tag, done);
|
||||
}
|
||||
while(!done);
|
||||
while(!done && !empty(overrun));
|
||||
|
||||
if(!done)
|
||||
{
|
||||
// This branch represents a read of -EAGAIN.
|
||||
assert(empty(overrun));
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(peer);
|
||||
peer->handle_tag_done(*this, tag);
|
||||
|
@ -1935,25 +1942,6 @@ catch(const buffer_overrun &e)
|
|||
queue.pop_front();
|
||||
throw;
|
||||
}
|
||||
catch(const std::system_error &e)
|
||||
{
|
||||
using std::errc;
|
||||
|
||||
if(system_category(e.code())) switch(e.code().value())
|
||||
{
|
||||
case 0:
|
||||
assert(0);
|
||||
return true;
|
||||
|
||||
case int(errc::resource_unavailable_try_again):
|
||||
return false;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
/// Process one read operation for one tag
|
||||
ircd::const_buffer
|
||||
|
@ -2009,7 +1997,6 @@ ircd::server::link::read(const mutable_buffer &buf)
|
|||
assert(peer);
|
||||
peer->read_bytes += received;
|
||||
|
||||
assert(received);
|
||||
return const_buffer
|
||||
{
|
||||
data(buf), received
|
||||
|
@ -2566,6 +2553,9 @@ ircd::server::tag::read_buffer(const const_buffer &buffer,
|
|||
{
|
||||
assert(request);
|
||||
|
||||
if(empty(buffer))
|
||||
return buffer;
|
||||
|
||||
if(state.status == (http::code)0)
|
||||
return read_head(buffer, done, link);
|
||||
|
||||
|
|
Loading…
Reference in a new issue