I was writing a simple server, just for fun and I realized that the third step meaning calling the listen(...) function takes two arguments. The second one being the backlog. While I don’t fully understand the meaning of this argument but I think it queues up the clients. So assuming I’m right I was wondering how the server moves up the queue or do I actually’ve to implement that?
I did find many examples online about it but they mostly contain code. I would like a more theoretical explanation.
Thanks!
Yes you are right – backlog is the supposed queue of possible connections (AFAIK it is ignored on Linux)
After you create a listening socket you call accept() on it and assuming your socket is blocking – the accept call shall not return until it pull the first client request off the queue.
So you can do something like