HP X.25/9000 Programmer's Guide

58 Chapter4
Sending and Receiving Data
Using Nonblocking I/O
Using Nonblocking I/O
Although sockets are created in blocking I/O mode by default, you can
specify that a socket be put in nonblocking I/O mode using the
ioctl(FIOSNBIO) call as shown below. The behavior of many system
calls changes when the socket is in nonblocking mode. These differences
in behaviour are also described in this section.
The ioctl(FIOSNBIO) call
Use the ioctl(FIOSNBIO) call to set a socket to blocking or nonblocking
I/O mode.
Syntax for ioctl(FIOSNBIO)
The syntax for the ioctl(FIOSNBIO) system call and its parameters are
described below.
#include <x25/x25ioctls.h>
int err;
int sd, arg;
err = ioctl(sd, FIOSNBIO, &arg);
sd Socket descriptor for a VC socket.
FIOSNBIO Controls whether the socket is set to blocking or nonblocking I/O mode.
This is specified by the value in
arg
.
arg Specifies the socket’s operating mode. If the value in
arg
is 0, the socket
is in blocking mode. If the value in
arg
is 1, the socket is in nonblocking
mode. Sockets are in blocking mode by default.
err On successful completion,
err
is set to 0. Otherwise, a value of –1 is
returned and errno is set to indicate the error.
Nonblocking Behavior of System Calls
The behavior of many system calls changes when the socket is in
nonblocking mode. The system calls of primary importance to X.25
programmers are the accept() and connect(), send() and recv(),
read() and write(), and ioctl() calls. These differences in behavior
36960-90061.bk Page 58 Friday, November 10, 2000 3:42 PM