websocket: Fix for use with new version of Streams
authorLucas Bajolet <r4pass@hotmail.com>
Tue, 23 Dec 2014 15:55:46 +0000 (16:55 +0100)
committerLucas Bajolet <r4pass@hotmail.com>
Mon, 12 Jan 2015 19:24:43 +0000 (14:24 -0500)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

lib/socket/socket.nit
lib/websocket/examples/websocket_server.nit
lib/websocket/websocket.nit

index 26d9937..69bd449 100644 (file)
@@ -107,7 +107,7 @@ class TCPStream
        fun ready_to_read(timeout: Int): Bool
        do
                if _buffer_pos < _buffer.length then return true
-               if eof then return false
+               if end_reached then return false
                var events = [new NativeSocketPollValues.pollin]
                return pollin(events, timeout).length != 0
        end
@@ -168,6 +168,7 @@ class TCPStream
                if closed then return
                if socket.close >= 0 then
                        closed = true
+                       end_reached = true
                end
        end
 
index 089df1b..80c9d25 100644 (file)
@@ -39,7 +39,8 @@ while not sock.listener.closed do
                sock.write(msg)
        end
        if sock.can_read(10) then
-               msg = sock.read_line
+               msg = ""
+               while sock.can_read(0) do msg += sock.read(100)
                if msg != "" then print msg
        end
 end
index ebf3f49..200c1f5 100644 (file)
@@ -132,8 +132,8 @@ class WebSocket
        # Reads an HTTP frame
        protected fun read_http_frame(buf: Buffer): String
        do
-               client.append_line_to(buf)
-               buf.chars.add('\n')
+               buf.append client.read_line
+               buf.append("\r\n")
                if buf.has_substring("\r\n\r\n", buf.length - 4) then return buf.to_s
                return read_http_frame(buf)
        end
@@ -238,7 +238,7 @@ class WebSocket
                unpad_message
        end
 
-       redef fun end_reached do return _buffer_pos >= _buffer.length and client.eof
+       redef fun end_reached do return client._buffer_pos >= client._buffer.length and client.end_reached
 
        # Is there some data available to be read ?
        fun can_read(timeout: Int): Bool do return client.ready_to_read(timeout)