0

In my socket server code, it is written that:

listen (socket_fd, 5);

I know this is written here for the reason of "listening connection" but I am not sure what the parameter 5 means. Also is there any syntax

 socklen_t

I tried to find it using manual command but was unable.

user3751012
  • 533
  • 1
  • 8
  • 20
  • Regarding the first question, the [**man page**](http://linux.die.net/man/2/listen) is pretty clear, It is the size of the pending connection backlog before issuing refusals. Note that is **not** *concurrent* connections. It is the backlog size of connecting clients waiting for an `accept()`. – WhozCraig Jun 21 '14 at 03:47
  • @WhozChraig, so I will allow maximum 5 pending connection in my queue, right? – user3751012 Jun 21 '14 at 03:53

2 Answers2

2

The parameter is a hint to the kernel about the size of the backlog queue. This is a queue of connections which have been completed by TCP but not yet returned as sockets by accept() in the application (because the application may be slow calling accept()). The kernel is free to adjust the hint up or down. In practice, backlogs as low as five haven't been seen for years if not decades.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

From this site, the second parameter is the backlog queue size. The listen(int fd, int size) function creates a queue for incoming connection requests. So in your example you would be able to handle five connection attempts that arrive at (or very close to) the same time.

thurizas
  • 2,473
  • 1
  • 14
  • 15
  • Or five attempts that arrive years apart, if it took you years to get around to calling `accept()` again. Time has nothing to do with it. – user207421 Jun 21 '14 at 07:26