title: What happens when we say "listen to a port"?
body: <p>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? </p>
  
  <p>My current <em>imagination</em> is like this:</p>
  
  <p>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 <strong><em>block</em></strong> the application.</p>
  
  <p>When some data arrives from the wire, the operating system will <strong><em>know</em></strong> that and then check the data and see if it is targeted at this port number. And then it will fill the <strong><em>corresponding</em></strong> buffer. And then OS will notify the blocked server application and the server application will get the data and continue to run.</p>
  
  <p>Question is:</p>
  
  <ul>
  <li><p>If the above scenario is correct, how could the opearting system <strong><em>know</em></strong> there's data arriving from wire? It cannot be a busy polling. Is it some kind of interrupt-based mechanism?</p></li>
  <li><p>If there's too much data arriving and the buffer is not big enough,  will there be data loss?</p></li>
  <li><p>Is the "listen to a port" operation really a blocking operation?</p></li>
  </ul>
  
  <p>Many thanks.</p>