title: zero copy udp socket using sendfile instead of sendto
body: <p>I'm working with udp sockets in real time environment. I am currently using standard socket functions sendto() which takes relatively a lot of time. I read that it is possible to use zero copy, that, if I understand well, avoids having extra time added by copying files from user/kernel environment. However, I see that <a href="http://man7.org/linux/man-pages/man2/sendfile.2.html" rel="nofollow noreferrer">sendfile()</a> allows only to copy from one file descriptor to another. I can't see how I can use that to send UDP packets, which in my case is a buffer. So my question is: </p>
  
  <ol>
  <li>is it even possible to use sendfile() to send UDP packets ?  </li>
  <li>If so,what is the correct way of doing this ?</li>
  </ol>
  
  <p><strong>Edit</strong></p>
  
  <p>I am working on a real time platform where I have several operations plus the sending over the socket. All of these should not take more than 1ms. I tried on three machines, the first has 4 cores at 3.4GHz, the other 8 cores at 2.3GHz and the last one 4 cores at 1.4GHz. On the first one it takes less than 1µs to send a 720 bytes packet. While on the two others it is between 6 and 9µs. I'm using a linux low latency kernel, and deactivated all CPU power management features, so all the CPUs are at max frequency. </p>
  
  <p>I noticed that if the time taken by sendto() is larger than 6µs, the platform simply does not work. One other precision, I have several threads running in parallel. So maybe it is just the CPU processing other threads while the sendto() has not completed yet. I'm wondering it this is possible, to stop the sendto() while in process to do someting else. </p>
  
  <p>This is why I was trying to find other solutions to do optimization somewhere else, and I thought that using sendfile() would avoid additional times to be saved. </p>