Sending And Receiving Data Asynchronously - HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual

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

Sending and Receiving Data
Asynchronously
Asynchronous sockets allow a user program to receive an SIGIO signal
when the state of the socket changes. This state change can occur, for
example, when new data arrives. Currently the user would have to issue
a select system call in order to determine if data were available. If
other processing is required of the user program, the need to call select
can complicate an application by forcing the user to implement some
form of polling, whereby all sockets are checked periodically.
Asynchronous sockets allow the user to separate socket processing from
other processing, eliminating polling altogether. select may still be
required to determine exactly why the signal is being delivered, or to
which socket the signal applies.
Generation of the SIGIO signal is protocol dependent. It mimics the
semantics of select in the sense that the signal is generated whenever
select returns true. It is generally accepted that connectionless
protocols deliver the signal whenever a new packet arrives. For
connection oriented protocols, the signal is also delivered when
connections are established or broken, as well as when additional
outgoing buffer space becomes available. Be warned that these
assertions are guidelines only; any signal handler should be robust
enough to handle signals in unexpected situations.
The delivery of the SIGIO signal is dependent upon two things. First, the
socket state must be set as asynchronous; this is done using the
FIOASYNC flag of the ioctl system call. Second, the process group
(pgrp) associated with the socket must be set; this is done using the
SIOCSPGRP flag of ioctl. The sign value of the pgrp can lead to
various signals being delivered. Specifically, if the pgrp is positive, this
implies that a signal should be delivered to the process whose PID is the
absolute value of the pgrp. If the pgrp is negative, a signal should be
delivered to the process group identified by the absolute value of the
pgrp.
Any application that chooses to use asynchronous sockets must explicitly
activate the described mechanism. The SIGIO signal is a "safe" signal in
the sense that if a process is unprepared to handle it, the default action
is to ignore it. Thus any existing applications are immune to spurious
signal delivery.
Chapter 3
75

Advertisement

Table of Contents
loading

Table of Contents