What happens when we say “listen to a port”?

前端 未结 4 1952
感情败类
感情败类 2021-02-01 04:48

When we start a server application, we always need to speicify the port number it listens to. But how is this \"listening mechanism\" implemented under the hood?

My cur

4条回答
  •  故里飘歌
    2021-02-01 05:17

    1. Your description is basically correct except for the blocking part. OSes normally use interrupts to handle I/O events like arriving network packets, so there is no need to block.
    2. Yes, if too many connection attempts happen at the same time, some will get bounced. The number of connections to queue is specified when you call listen or its equivalent.
    3. No, it is not. The OS raises an event on your control socket when a connection arrives. You may choose to block while waiting for this event, or you may use some nonblocking (select, poll/epoll) or asynchronous (overlapped I/O, completion ports) mechanism.

提交回复
热议问题