What happens when we say "listen to a port" ?

Posted by smwikipedia on Stack Overflow See other posts from Stack Overflow or by smwikipedia
Published on 2010-12-25T11:52:34Z Indexed on 2010/12/25 11:53 UTC
Read the original article Hit count: 216

Hi,

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 current imagination is like this:

The operating system associate the port number with some buffer. The server application's responsibiligy is to monitor this buffer. If there's no data in this buffer, the server application's listen operation will just block the application.

When some data arrives from the wire, the operating system will know that check the data and see if it is targed at this port number. And then it will fill the buffer. And then OS will notify the blocked server application and the server application will get the data and continue to run.

Question is:

  • If the above scenario is correct, how could the opearting system know there's data arriving from wire? It cannot be a busy pooling. Is it some kind of interrupt-based mechanism?

  • If there's too much data arriving and the buffer is not big enough, will there be data loss?

  • Is the "listen to a port" operation really a blocking operation?

Many thanks.

© Stack Overflow or respective owner

Related posts about networking

Related posts about network-programming