Skip to content

Commit

Permalink
fixup! Server: rewrite to use fibers and non-blocking IO
Browse files Browse the repository at this point in the history
  • Loading branch information
asppsa committed Sep 5, 2019
1 parent 1428989 commit 8985bd0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/moneta/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 8985bd0

Please sign in to comment.