Listing 2: sendAlert constructor

sendAlert::sendAlert(char *_applicationName, int timeoutCount) : 
  theProblem(_application_name, timeoutCount)
{
  pthread_t threadId;
  sigset_t signalSet;
    
  sigemptyset(&signalSet); // Initialize signal set to contain no signals
  sigaddset(&signalSet, SIGALRM); // Add SIGALRM to the signal set
  
  // Block the SIGALRM signal from the main process thread
  sigprocmask(SIG_BLOCK, &signalSet, NULL); 
                                               
  status = 1;
  if (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) // create UDP socket
  {
    cerr << "Could not open datagram socket";
    status = 0;
    return;
  }
  memset((char *)&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = AF_INET;        
  // Set the appropriate subnet address of the server
  servAddr.sin_addr.s_addr = inet_addr("555.555.555.0");    
  servAddr.sin_port = htons(6543); // Set appropriate port of the server
  memset((char *)&cliAddr, 0, sizeof(cliAddr));
  cliAddr.sin_family = AF_INET;
  // Accept acknowledgment from server from any address in the network
  cliAddr.sin_addr.s_addr = htonl(INADDR_ANY);        
  cli_addr.sin_port = htons(0);
  // Bind socket to receive ack. from any server in network, allowing
  // flexibility with respect to placement of server in the network
  if (bind(sockfd, (struct sockaddr *)&cliAddr, sizeof(cliAddr))<0)
  {
    cerr << "Could not bind to socket";
    status = 0;
    return;
  }
  // Create the processMessageQueueThread
  if (pthread_create(&threadId, 0, processMessageQueueThread,
    (void *)NULL) != 0)
  {
    cerr << "Could not create processMessageQueueThread";
    status = 0;
    return;
  }
  // No need to wait for thread completion -- it's in an endless loop
}
//End of File