title: Connect Timeout with Alarm()
body: <p>Since it seems that I can't find a solution to my original problem, I tried to do a little workaround. I'm simply trying to set a timeout to the <code>connect()</code> call of my TCP Socket. </p>
  
  <ol>
  <li>I want the <code>connect()</code> to be blocking but not until the usual 75 seconds timeout, I want to define my own.</li>
  <li>I have already tried <code>select()</code> which worked for the timeout but I couldn't get a connection (that was my initial problem as described <a href="https://stackoverflow.com/questions/7089128/linux-tcp-connect-with-select-fails-at-testserver">here</a> ).</li>
  </ol>
  
  <p>So now I found another way to deal with it: just do a blocking <code>connect()</code> call but interrupt it with an alarm like this :</p>
  
  <pre><code>    signal(SIGALRM, connect_alarm);
      int secs = 5;
      alarm(secs);
      if (connect(m_Socket, (struct sockaddr *)&amp;addr, sizeof(addr)) &lt; 0 )
      {
          if ( errno == EINTR )
          {
              debug_printf("Timeout");
              m_connectionStatus = STATUS_CLOSED;
              return ERR_TIMEOUT;
          }
          else
          {
              debug_printf("Other Err");
              m_connectionStatus = STATUS_CLOSED;
              return ERR_NET_SOCKET;
          }
      }
  </code></pre>
  
  <p>with</p>
  
  <pre><code>static void connect_alarm(int signo)
  {
       debug_printf("SignalHandler");
       return;
  }
  </code></pre>
  
  <p>This is the solution I found on the Internet in a thread <a href="https://stackoverflow.com/questions/933122/socket-timeout-in-c-linux">here</a> on stackoverflow. If I use this code the program starts the timer and then goes into the <code>connect()</code> call. After the 5 seconds the signal handler is fired (as seen on the console with the <code>printf()</code>), but after that the program still remains within the <code>connect()</code> function for 75 seconds. Actually every description says that the <code>connect_alarm()</code> should interrupt the <code>connect()</code> function but it seems it doesn't in my case. Is there any way to get the desired result for my problem? </p>