From 8985bd0d21dbebd86b26290570a28171257115c6 Mon Sep 17 00:00:00 2001 From: Alastair Pharo Date: Thu, 5 Sep 2019 11:26:02 +1000 Subject: [PATCH] fixup! Server: rewrite to use fibers and non-blocking IO --- lib/moneta/server.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/moneta/server.rb b/lib/moneta/server.rb index 4a08684d..54dcce7a 100644 --- a/lib/moneta/server.rb +++ b/lib/moneta/server.rb @@ -82,7 +82,7 @@ def write(obj) buffer = pack(obj) until buffer.empty? begin - len = @io.sendmsg_nonblock(buffer) + len = @io.write_nonblock(buffer) buffer = buffer.byteslice(len...buffer.length) rescue IO::WaitWritable, Errno::EINTR yield_to_reactor(:write) @@ -226,6 +226,7 @@ def delete_connection(io) def close_connection(io) delete_connection(io) @connections.delete(io).resume(:close) + rescue FiberError end def resume(io) @@ -259,5 +260,14 @@ def start(options) TCPServer.open(options[:host] || '127.0.0.1', options[:port] || 9000) end end + + def stats + { + connections: @connections.length, + reading: @reads.length, + writing: @writes.length, + total: @ios.length + } + end end end