Buffering client data in a Server application

C

charpour

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.
 
C

charpour

Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

Not the answer I am seeking.

What is not portable and what is off-topic?
 
K

Keith Thompson

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:
[...]

select() is not a standard C function; it's defined by POSIX. You'll
probably get better answers by posting to comp.unix.programmer. (This
assumes you're using a Unix-like system; if not, try a newsgroup that
deals with your operating system.)

(The other rewponse you got was from one of our resident trolls.
Please ignore him; he won't help you.)
 
C

CBFalconer

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:

Ignore McCormack, he is a known troll. However your query is
largely off-topic, but appears to contain some topical C
questions. I think you need to eliminate consideration of
'servers', whatever they are, and concentrate on the intermediate
storage abilities and capabilities. What is practical here will
also depend on the peak volume of data held, the access times,
etc. I could almost recommend my hashlib package, but the
processing time involved may become excessive (for automatic
expansion of the hashtable). Or it may not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top