Skip to content
  • Richard W.M. Jones's avatar
    tests/web-server.c: Clean up handling of error paths · 26799722
    Richard W.M. Jones authored
    When processing the client request or sending a reply, previously we
    used some copy and paste code along the error path:
    
      eof = true;
      break;
    
    While effective in all but one case, setting eof was unnecessary as
    the break statement already quit the loop.
    
    Let's tidy up the error paths out of the loop properly:
    
    (1) Define a new label 'out_and_close' which is used along error paths
    to get out of the outer loop and close the socket.  In the outer code
    this is exactly equivalent to break (but clearer).  In the inner for
    loop when we're reading the request this jumps out of both loops.
    
    (2) Fix commit ea115ecb ("tests/web-server.c: Ignore errors when
    reading the request") so that it really does jump to out_and_close.
    
    (3) Make sure we jump to 'out_and_close' after sending any error
    message.  Seems safer as we may not be sure of the exact state of the
    client and socket.
    
    (4) Document the one place where we do actually need to set eof / break.
    
    Fixes: commit ea115ecb
    Thanks: Laszlo Ersek
    26799722