HPlogo X25/9000: X.25/9000 Programmer's Guide > Chapter 4  Sending and Receiving Data

Using Nonblocking I/O

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

Sockets are created in blocking I/O mode by default. You can specify that a socket be put in nonblocking mode with the ioctl(FIOSNBIO) call.

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

A socket descriptor for an SVC 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

Upon 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(). These differences are described below.

  • accept() returns immediately. If no connection requests are present in the listen queue, accept() returns -1 and the EWOULDBLOCK error is contained in errno. If a connection request is present in the listen queue, accept() returns a socket descriptor for the SVC.

  • connect() returns -1 immediately and the EINPROGRESS error is contained in errno. The socket may be polled with the select() call; the socket will select writable when connection establishment is complete. At that point data can be retrieved from the CALL ACCEPTED packet with ioctl(X25_RD_USER_DATA), and data can be sent and received with send() and recv() calls.

  • recv() and read() returns immediately. If there is a complete message to be received in the X.25 buffer space, the data is returned immediately. If no data is available to be received, recv() and read() return the value -1 and the EWOULDBLOCK error is contained in errno.

  • send() and write() returns immediately. If there is X.25 buffer space available, for the send() or write() buffer, the data is transferred into the X.25 buffer space and sent in the order it was received. If there is no available buffer space for the data to be transmitted, send() and write() return the value -1 and the EWOULDBLOCK error is placed in errno. In this case the call must be reissued at a later time.

  • Series 800 only: send() and write() with the D Bit Set returns immediately. When the D bit is set, the data is transmitted as described above. When the D bit confirmation arrives the X.25 subsystem sends SIGURG signal to the process and the event OOB_VC_DBIT_CONF is added to the out-of-band queue. While waiting for D bit confirmation, the process must not send any more data until confirmation is received.

  • send(MSG_OOB) returns immediately. If there is X.25 out-of-band buffer space available, the data is transferred into it and sent. If there is no available out- of-band buffer space for the data to be transmitted, send() returns the value -1 and the EWOULDBLOCK error is placed in errno. The call must be reissued at a later time. The use of send() to transmit out-of-band data is fully described in Chapter 5 “ Receiving and Transmitting Out-of-Band Information”.

When the INTERRUPT CONFIRMATION packet arrives, the subsystem sends a SIGURG signal to the process with OOB_VC_INTERRUPT_CONF in the out-of-band queue. The process must not send a second INTERRUPT packet until interrupt confirmation has been received or a reset indication has been received.

  • ioctl() returns immediately. Most ioctl() values used by X.25 are not directly related to the transmission and reception of packets. The ioctl(X25_RESET_VC) and ioctl(X25_SEND_CALL_ACEPT)cause the transmission of packets. Both of these ioctl() types cause a packet to be sent. The ioctl(X25_SEND_CALL_ACEPT) never blocks because all transmit buffers are empty when it is issued. The socket is ready for transmission and reception.

When issued in nonblocking mode, the ioctl(X25_RESET_VC) returns 0 and a RESET REQUEST packet is sent on the VC. When a RESET CONFIRMATION packet is received, X.25 sends a SIGURG signal and a OOB_VC_RESET_CONF event is added to the out-of-band queue. No data of any sort may be sent by the process until the confirmation has been received.