HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual page 76

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

Advanced Topics for Stream Sockets
Sending and Receiving Data Asynchronously
Notification that out-of-band data has been received is also done
asynchronously; see the section "Sending and Receiving Out-of-band
Data" in this chapter for more details.
The following example sets up an asynchronous SOCK_STREAM listen
socket. This is typical of an application that needs to be notified when
connection requests arrive.
int ls;
int flag = 1;
int iohndlr();
signal (SIGIO, iohndlr); /* set up the handler */
if (ioctl (ls, FIOASYNC, &flag) == -1) {
}
flag = -getpid();/* process group negative = deliver to process */
if (ioctl (ls, SIOCSPGRP, &flag) == -1) {
}
The following example illustrates the use of process group notification.
Note that the real utility of this feature is to allow multiple processes to
receive the signal, which is not illustrated here. For example, the socket
could be of type SOCK_DGRAM; a signal here can be interpreted as the
arrival of a service-request packet. Multiple identical servers could be set
up, and the first available one could receive and process the packet.
int flag = 1;
int iohndlr();
signal (SIGIO, iohndlr);
setpgrp();
if (ioctl (s, FIOASYNC, &flag) == -1) {
perror ("can't set async on socket");
exit(1);
}
flag = getpid(); /* process group + = deliver to each process in group */
if (ioctl (s, SIOCSPGRP, &flag) == -1) {
perror ("can't set pgrp");
exit(1);
}
/* signal can come any time now */
76
/* SOCK_STREAM listen socket initialized */
/* for ioctl, to turn on async */
/* the function which handles the SIGIO */
perror ("can't set async on socket");
exit(1);
perror ("can't set pgrp");
exit(1);
/* signal can come any time now */
/* ioctl to turn on async */
/* set my processes' process group */
Chapter 3

Advertisement

Table of Contents
loading

Table of Contents