lib/socket: Simplified API for Sockets
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 2 May 2014 19:05:30 +0000 (15:05 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Fri, 2 May 2014 19:05:30 +0000 (15:05 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

examples/socket_client.nit
examples/socket_server.nit
lib/mpd.nit
lib/socket/socket.nit

index d9ac5ff..0ba1913 100644 (file)
@@ -24,7 +24,7 @@ if args.length < 2 then
        return
 end
 
-var s = new Socket.stream_with_host(args[0], args[1].to_i)
+var s = new Socket.client(args[0], args[1].to_i)
 print "[HOST ADDRESS] : {s.address}"
 print "[HOST] : {s.host}"
 print "[PORT] : {s.port}"
index 8754ce2..aa77a75 100644 (file)
@@ -24,7 +24,7 @@ if args.is_empty then
        return
 end
 
-var socket = new Socket.stream_with_port(args[0].to_i)
+var socket = new Socket.server(args[0].to_i, 1)
 print "[PORT] : {socket.port.to_s}"
 
 var clients = new Array[Socket]
index cf9b677..9a56b95 100644 (file)
@@ -34,8 +34,7 @@ class MPDConnection
        do
                var p: nullable Socket = null
 
-               p = new Socket.stream_with_host(host, port)
-               p.connect
+               p = new Socket.client(host, port)
 
                sys.nanosleep(0,5000)
 
index 4a5129e..9824111 100644 (file)
@@ -44,7 +44,7 @@ class Socket
        redef var end_reached = false
 
        # Creates a socket connection to host `thost` on port `port`
-       init stream_with_host(thost: String, tport: Int)
+       init client(thost: String, tport: Int)
        do
                _buffer = new FlatBuffer
                _buffer_pos = 0
@@ -62,8 +62,8 @@ class Socket
                if not end_reached then end_reached = not connect
        end
 
-       # Creates a server socket on port `tport`
-       init stream_with_port(tport: Int)
+       # Creates a server socket on port `tport`, with a connection queue of size `max`
+       init server(tport: Int, max: Int)
        do
                _buffer = new FlatBuffer
                _buffer_pos = 0