socket

Table of Contents

connect

EINTR

volatile int stop = 0;

void handler (int)
{
  stop = 1;
}

void event_loop (int sock)
{
  signal (SIGINT, handler);

  while (1) {
    if (stop) {
      printf ("do cleanup\n");
      return;
    }

    /* What if signal handler is executed at this point?
       This may be a problem, or not. 
     */

    char buf [1];
    int rc = recv (sock, buf, 1, 0);
    if (rc == -1 && errno == EINTR)
      continue;
    printf ("perform an action\n");
  }
}