JelleBouma / Johnny

Johnny is a blazingly fast HTTP server that serves files from memory
1 stars 0 forks source link

reduce calls to recv #11

Closed JelleBouma closed 1 month ago

JelleBouma commented 1 month ago

3 scenarios where we call recv more than needed:

scenario 1 (a request, but not the last one):

  1. we get an EPOLLIN event
  2. we call recv read for example 800 bytes into 1024 byte buffer
  3. we send the response
  4. now we dont need to call recv again as it will return EAGAIN, but we do (might cause race conditions with epoll events generated at the same time, although i dont think these race conditions could lead to serious problems)

scenario 2 (last request):

  1. we get an EPOLLIN | EPOLLRDHUP event, but we have not registered EPOLLRDHUP so we dont know this
  2. we call recv read for example 800 bytes into 1024 byte buffer
  3. we send the response
  4. now we dont need to call recv again as it will return 0, but we do

scenario 3 (last request, incomplete response):

  1. we get an EPOLLIN | EPOLLRDHUP event, but we have not registered EPOLLRDHUP so we dont know this
  2. we call recv read for example 800 bytes into 1024 byte buffer
  3. we send the response but get EAGAIN
  4. now we dont need to call recv again as it will return 0, but we do after we resume sending. problem here is that we need to store this information so we know that we do not have to recv