3
votes

Context

Debian64bits.

Thought I understood socket implications but not.

Worried about the management of slow clients.

Read and fiddled with that code epoll edge triggered

Imagine two clients: A: very slow network B: very fast network.

Question

In edge triggered mode what would happen when we start reading from A and then B also sends some datas to read while we are in the read loop for A?

Will B have to wait for us to read all the datas coming from A?

Or should we create a buffer (not in the example given) to store A datas and concatenate those until the message is complete and return immediately?

Or is that buffer already managed by epoll?

The underlying is not clear to me..

1

1 Answers

3
votes

It doesn't matter if the network is slow, the reading part will stop whenever it has read all data that has reached the server so far.

There is a bug (or at least a portability issue) in it though. The code only checks for EAGAIN when reading data. It should also check for EWOULDBLOCK, since some platforms return that error code when all data has been read.

Edit:

Ok, so if i want to put the incoming datas into a database, how could i manage it? Will i be able to read the whole datas?

If you get an incomplete message you would need to store it until the entire message has been received. I would malloc a char* for each incoming connection with a message fragment.

When a message is complete, you can process it, store it in the database or whatever you desire.

Note that the beginning of the next message may already be available, so you can't stop reading until you get EWOULDBLOCK or EAGAIN.

Another way to treat the problem is to create a separate thread for each connection. Which approcah is best? Well, that would depend on the application (number of simultaneous users etc).