Hello,
I am implementing a server in C using the select function and I have
problems implementing a buffering system for holding client data until
the client socket is available for reading/writing (sendq and
receivq). What I am trying to do is "save" the data in the client's
recvq right after data is availiable for the socket and write buffered
data (sendq) to the socket when it's ready. The prog skeleton is like
this:
(The following is not complete C code, it's just an example)
unsigned char buffer[1024];
select(nfds, &readset, &writeset, NULL);
// select returns
for (i=0; i<MAX_CONNECTIONS; i++) {
if (FD_ISSET(i, &readset)) {
r = read(i,buffer,...);
// cli = client data structure
cli = (struct cli *) getclient(i);
//add data to the client's recvq
add_data(&cli->recvq, buffer, r);
if (has_complete_message(&cli->recvq)) {
parseline(cli);
// add results to the client's buffer (sendq) for writing them
later
}
}
if (FD_ISSET(i, &writeset)) {
// write queued data
}
....
}
Is there any code/lib for this purpose with functions like
add_data(..), read_data(...), get_message(..), get_len(..),
has_complete_message(..), probably using double linked list or
something similar
I have found some str alloc packages but they are not very good for
this purpose.
PS. If anyone have played with ircd's, I'm searching for something
similar to sbuf.c (bahamut) or linebuf.c (ratbox) with more "clear"
code;
Thanks for your time and sorry for my bad english.