g_io_add_watch_full and line buffered input



  I am writing a gtk2 client for a mp3 jukebox that I and a few friends
are developing.  The server sends and recieves strings.  Being
linebuffered, the end of a string is signified with a newline
character.  I'm using g_io_add_watch_full() to listen for input from the
server.  It works nicely until multiple lines are sent consecutively.  
When this happens, g_io_add_watch_full() only seems to capture the first
line of input.  It is only after more data is sent that the rest of the
buffered lines are received.  If a call to usleep() is put in after each
time the server sends a message it seems to work, but I rather not have
to do this.  To read data, I use fgets.  I attempted to use read, and it
would read in all the data that was waiting in the buffer as if it
received it all at once.  Using a packet sniffer, I ensured that the
data wasn't being sent all as one data stream, but it appears as if
g_io_add_watch_full() is interpreting it as the later.

I am adding the watch by doing the following:

IO_chan = g_io_channel_unix_new(m_conn->sock);
g_io_add_watch_full(IO_chan, G_PRIORITY_HIGH, G_IO_IN|G_IO_PRI,on_input,
data, NULL);

m_conn is a structure and sock is the file descriptor  used.

The on_input callback function is structured to read in a line of text
via fgets() and then parse and manipulate the UI based on the contents
of the string.  Is there any way where g_io_add_watch_full() can catch
all of the lines of data sent to the socket regardless to how fast data
is sent?




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]