lib/kamerling/server/tcp.rb in kamerling-0.0.2 vs lib/kamerling/server/tcp.rb in kamerling-0.0.3
- old
+ new
@@ -1,19 +1,27 @@
-module Kamerling module Server class TCP < Sock
- private
+require 'socket'
+require_relative '../addr'
+require_relative 'sock'
- def handle_connection socket
- client_addr = Addr[*socket.remote_address.ip_unpack, :TCP]
- input = socket.read
- handle input, client_addr
- ensure
- socket.close
- end
+module Kamerling
+ module Server
+ class TCP < Sock
+ private
- def run_loop
- Socket.tcp_server_loop(*addr) { |socket| handle_connection socket }
- end
+ def handle_connection(socket)
+ client_addr = Addr[*socket.remote_address.ip_unpack, :TCP]
+ input = socket.read
+ handle input, client_addr
+ ensure
+ socket.close
+ end
- def wait_till_started
- loop { break if addr.connectable? }
+ def run_loop
+ Socket.tcp_server_loop(*addr) { |socket| handle_connection socket }
+ end
+
+ def wait_till_started
+ loop { break if addr.connectable? }
+ end
+ end
end
-end end end
+end