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 responsibiliy 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 and then check the data and see if it is targeted at this port number. And then it will fill the corresponding 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 polling. 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.