title: Linux, sockets, non-blocking connect
body: <p>I want to create a non-blocking connect.
  Like this:</p>
  
  <pre><code>socket.connect(); // returns immediately
  </code></pre>
  
  <p>For this, I use another thread, an infinite loop and Linux epoll. Like this(pseudocode):</p>
  
  <pre><code>// in another thread
  {
    create_non_block_socket();
    connect();
  
    epoll_create();
    epoll_ctl(); // subscribe socket to all events
    while (true)
    {
      epoll_wait(); // wait a small time(~100 ms)
      check_socket(); // check on EPOLLOUT event
    }
  }
  </code></pre>
  
  <p>If I run a server and then a client, all it works. If I first run a client, wait a some small time, run a server, then the client doesn't connect.</p>
  
  <p>What am I doing wrong? Maybe it can be done differently?</p>