What is the recommended way to iterate over lines sent via a network socket?

11 views
Skip to first unread message

Finnian Reilly

unread,
Feb 13, 2018, 6:51:32 AM2/13/18
to Eiffel Users

I am wondering what the recommended way is to iterate over lines from a socket until the client closes the connection. This seems to work in practice but I am wondering if I am supposed to test with ffmpeg_socket.is_readable. Unlike FILE there is no `end_of_file' test in STREAM_SOCKET.

from until client_socket.was_error loop
   
client_socket.read_line
   
if not client_socket.was_error then
        line
:= client_socket.last_string
       
-- bla bla
   
end
end


Finnian Reilly

unread,
Feb 13, 2018, 6:54:47 AM2/13/18
to Eiffel Users

My question of course relates to EiffelNet

Finnian Reilly

unread,
Feb 15, 2018, 12:45:51 PM2/15/18
to Eiffel Users
I have been trying to answer my own question with some experiments:
from until not client_socket.is_readable loop
   
client_socket.read_line
   
..
end

However this did not work at all in the example I tried. But on examining the source for routine {SOCKET}.read_line, it does seem that calling `was_error' is the only way to detect the end of the transmission.

    read_line, readline
           
-- Read a line of characters (ended by a new_line).
       
local
            l_last_string
: like last_string
       
do
            create l_last_string
.make (512)
            read_character
           
from
           
until
                last_character
= '%N' or else was_error
            loop
                l_last_string
.extend (last_character)
                read_character
           
end
            last_string
:= l_last_string
       
end

Nothing wrong with this I guess, although it does seem a bit odd that doing something this natural is treated as an error condition.

Reply all
Reply to author
Forward
0 new messages