473,387 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Buffering client data in a Server application

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.

Oct 10 '07 #1
7 1551
In article <11*********************@k79g2000hse.googlegroups. com>,
<ch******@yahoo.comwrote:
>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
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

--
Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language

Oct 10 '07 #2
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?

Oct 10 '07 #3
ch******@yahoo.com writes:
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.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 10 '07 #4
Thank you

Oct 10 '07 #5
In article <11**********************@19g2000hsx.googlegroups. com>,
<ch******@yahoo.comwrote:
>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?
Don't ask. Any minute now, they'll tell you.

Oct 11 '07 #6
ch******@yahoo.com wrote:
>
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.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Oct 11 '07 #7
I've made a small module for buffering but I am not sure how correct
my code is (it compiles ofc, I mean in logic).
If someone can check it please and tell his opinion.

Here is the code:
http://pastebin.com/m6a3702ad

Thank you

Oct 12 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Morgan | last post by:
Hi This is a really weird problem. We have a website that has been running for about six months with no problems. We have recently moved it to a new server with a new ISP. The server is of a...
5
by: Matt | last post by:
I think this is the basic concept in ASP server-side development. My boss told me web application is NOT client-server application. I argued with him because browser is the client, and the server...
2
by: Microsoft | last post by:
I'm about to start converting my application from a old-style monolith exe (with flat files and limited database support for sharing some of the data) to a layered .NET SQL server version. I have...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
4
by: Prince Kumar | last post by:
I joined a company recently and they have a java program which hangs (does nothing) after a while. This is no way consistent. It could succeed quite a few times and can fail a few other times....
6
by: Ken Allen | last post by:
I am relatively new to .Net and C#, but I hav ebeen programing in other languages and done some COM work for a number of years. I am attempting to understand how to map an older program...
2
by: Sam-Kiwi | last post by:
I've spent the last 6 months developing a pay-per-download website using ASP.NET Users purchase documents and then download them. The intention is that users are only charged for documents...
12
by: ShepardBerry | last post by:
This may be a dumb question, but I'm not finding anything specifically what I'm looking for. Still kind of new to .NET as well. What I'm trying to do that I know I could do in VB6.0/ASP is to...
5
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4. What is the header I need to send in order for output to be continuously sent to the client browser as opposed to it being buffered and all sent at once? Thanks, -...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.