40media Buffering of stream data

Buffering of stream data

I'm trying to develop a simple IRC bot. First I want to think out a proper design for this project. One of the things I'm wondering about right now is the read mechanism. I develop this bot on a Linux system. (Fedora 12) To read from a socket I use the system call "read()". I plan to use the reading functionality in the following way (code just an example. Not something from the final product):

while (uBytesRead = read(iServerSocket, caBuffer, MAX_MESSAGE_SIZE)) {    //1. Parse the buffer and place it into a Message structure.    //2. Add the message structure to a linked list that will act as a queue of message that are to be processed. } 

This code will be run in it's own thread. I choose for this option because I wanted there to be as small of a delay between reads as possible. (writes will be implemented in the same way) This is all slightly based on assumptions, that I would like to clear up. My question is: what if you receive so much data at such a quick rate, that the reading and processing the data (in this case just parsing it) goes slower than the rate at which data comes in. I made the assumption that this data will be buffered by the system. is this a right assumption? And if so:

  1. How big is this buffer?
  2. What happens with incomming data when this buffer gets full?
  3. To make my application protected against spam, how could I best deal with it?

I hope I've explained my issue clear enough.

Thanks in advance.

Code assistance in Netbeans on Linux


No warning from gcc when function definition in linked source different from function prototype in header
IRC uses TCP sockets for networking.

Program to open large MySQL dumps
Linux/Posix TCP sockets have a data buffer for sending and another one for receiving.

Finding an available network port on the machine
You can resize the buffers with setsockopt() and SO_SNDBUF/SO_RCVBUF..
Monitor file in Java on Linux 64bits
TCP has flow control so when a receive buffer is getting full the OS will send a congestion notice.

Preventing multiple process instances on Linux
Received packets that didn't fit in the buffer will not be acknowledged by the receiver and will be eventually retransmitted by the sender..
Control Debug Level in C++ Library - Linux
So that's not to worry.

Is there a difference calling daemon(0,0) from within a program, and launching a program to be in background and redirecting it's output
What matters is what does the sender program when its socket's send buffer gets full.

Some programs will close the socket, others would just discard written data and try again, while others might buffer internally..

88 out of 100 based on 48 user ratings 298 reviews