title: Is it possible to write directly from file to the socket?
body: <p>I'm interested in the basic principles of Web-servers, like Apache or Nginx, so now I'm developing my own server.</p>
  
  <p>When my server gets a request, it's searching for a file (e.g <code>index.html</code>), if it exists - read all the content to the buffer (<code>content</code>) and write it to the socket after. Here's a simplified code:</p>
  
  <pre><code>int return_file(char* content, char* fullPath) {
      file = open(fullPath, O_RDONLY);
      if (file &gt; 0) { // File was found, OK
        while ((nread = read(file, content, 2048)) &gt; 0) {}
        close(file);
        return 200;
      }
  }
  </code></pre>
  
  <p>The question is pretty simple: is it possible to avoid using buffer and write file content directly to the socket?</p>
  
  <p>Thanks for any tips :)</p>