Open System Services Programmer's Guide
/*
Sets socket to listen:
*/
if (listen(sock, 1) < 0)
{
perror("Listen Error");
exit(-1);
}
/*
Starts server:
*/
while(1)
{
bzero(&accept_addr, sizeof(accept_addr));
accept_fd = accept(sock, NULL, NULL);
if (accept_fd < 0)
{
perror("Accept Error");
exit(-1);
}
/*
Dispatches a thread to handle service request:
*/
if(pthread_create(&my_thread,&my_attr,&worker_thread,&accept_fd))
{
perror("pthread_create");
exit(-1);
}
} /* while */
}/* main */
Example 106 (page 436) also creates a threaded time-of-day server socket, but using $RECEIVE.
Threaded Application Programming 435










