1

Suppose that I have the following code:

import socket


listener = socket.socket()
listener.bind(('0.0.0.0', 59535))
while True:
    conn, addr = listener.accept()
    worker_thread = threading.Thread(target=client_handler, args=(conn, addr,)).start()

What will happen if new client will try to connect to our listener socket while we're creating worker thread? Will he wait for the next accept call or will it just rejected? If he'll wait, how many clients can be in that queue simultaneously by default (yeah, I know that I can set it via listen function)?

FrozenHeart
  • 19,844
  • 33
  • 126
  • 242

1 Answers1

2

There is a listen queue in the kernel, so the kernel will deal with new clients while your user space part does something else. If the listen queue in the kernel is full no more clients will be accepted, that is the connect will fail.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • 1
    Yes and one small difference is - your next 'accept' call won't block, because the socket will be ready to accept new connection – gabhijit Oct 29 '15 at 19:37
  • Thanks a lot! Maybe you can answer another question -- http://stackoverflow.com/questions/33423115/which-ports-should-be-used-for-non-iana-approved-applications – FrozenHeart Oct 29 '15 at 19:38