title: Effect of SO_SNDBUF
body: <p>I am unable to make sense of how and why the following code segments work :</p>
  
  <pre><code>    /* Now lets try to set the send buffer size to 5000 bytes */
      size = 5000;
      err = setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF,  &amp;size, sizeof(int));
      if (err != 0) {
          printf("Unable to set send buffer size, continuing with default size\n");
      }
  </code></pre>
  
  <p>If we check the value of the send buffer, it is indeed correctly set to 5000*2 = 10000.
  However, if we try to send more than the send buffer size, it does send all of it. For example:</p>
  
  <pre><code>    n = send(sockfd, buf, 30000, 0);
  
      /* Lets check how much us actually sent */
      printf("No. of bytes sent is %d\n", n);
  </code></pre>
  
  <p>This prints out 30000.</p>
  
  <p>How exactly did this work? Didn't the fact that the send buffer size was limited to 10000 have any effect? If it did, what exactly happened? Some kind of fragmentation?</p>
  
  <p><strong>UPDATE:</strong> What happens if the socket is in non-blocking mode? I tried the following: </p>
  
  <ol>
  <li>Changing buffer size to 10000 (5000*2) causes 16384 bytes to be sent</li>
  <li>Changing buffer size to 20000 (10000*2) causes 30000 bytes to be sent </li>
  </ol>
  
  <p>Once again, why?</p>