Skip to content
  • Yorick Peterse's avatar
    Refactor connecting of sockets · 53675b7a
    Yorick Peterse authored
    This commit makes the following changes:
    
    1. We remove the InProgress constant from the VM.
    
    2. When we detect EISCONN as the result of a connect(2), we ignore it.
    
    3. We properly read SO_ERROR from a socket when connecting in order to
       determine the actual result of connect(2).
    
    4. We fix cloning of registered sockets.
    
    == Removal of InProgress
    
    Using the InProgress variant meant that the result register of
    SocketConnect would not be set when a connect is in progress. This could
    lead to unexpected results if one were to assume it was actually set.
    
    == Using SO_ERROR
    
    Socket::connect() in the VM now checks the value of SO_ERROR when a
    connect(2) is reported as blocking. On at least Windows, the result of
    connect(2) always appears to be EAGAIN/WSAEWOULDBLOCK, with the actual
    error being stored in SO_ERROR. Not checking this value could result in
    a connect getting stuck in the loop of: performing the connect ->
    reported as blocking -> retrying later on -> repeat.
    
    == Socket cloning
    
    We also fix the cloning of sockets to make sure that the "registered"
    flag is not cloned, as doing this could lead to errors when trying to
    register a socket with a network poller.
    53675b7a