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

Setting Buffer Thresholds and Sizes

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

X.25 allows programmers to fine-tune socket behavior by specifying certain characteristics such as when a socket (is writable) allows information to be written to its buffers. This is accomplished by setting the threshold values that control the size of the three socket buffers: outbound message, send, and receive.

Setting the Write Buffer Threshold

The write buffer threshold is used to determine if there is enough buffer space available to send another message without blocking the socket. If the buffer space available is greater than or equal to the write threshold, the socket will indicate writable when a select() call is issued. The ioctl(X25_WR_WTHRESHOLD) call is used to set the write threshold value.

The value specified with ioctl(X25_WR_THRESHOLD) effects send(), write(), and select(). Whenever a send() or a write() call are issued, the amount of space remaining in the send socket buffer is checked; the amount of data in the outbound queue is subtracted from the size of the send socket's buffer. This check is performed in terms of network memory units and so is subject to round-off error. If this remaining space is insufficient to accept another message of the write threshold size, the free space size for the send socket is forced to zero, and remains that way until enough data is moved to the X.25 interface. If another send() or write() call is issued during this time, the call is blocked (for nonblocking I/O, EWOULDBLOCK is returned).

The ioctl(X25_WR_WTHRESHOLD) call and its parameters are described below.

Syntax for ioctl (X25_WR_WTHRESHOLD)

The syntax for the ioctl(X25_WR_WTHRESHOLD) system call and its parameters are described below.

#include <x25/x25ioctls.h>
#include <x25/x25str.h>
int err;
int sd, thresh;
err = ioctl(sd, X25_WR_WTHRESHOLD, &thresh);
sd

A socket descriptor for an SVC socket.

X25_WR_WTHRESHOLD

Indicates that the write threshold is being changed.

thresh

Indicates the new value for the write threshold.

err

Upon successful completion, err is set to 0. Otherwise, a value of -1 is returned and errno is set to indicate the error.

Setting the Read Message Fragment Size

X.25 assumes that all VCs will read whole messages with a single read() or recv() system call. This is usually the most efficient use of the VC. A message is a set of packets that all have their M bits set to 1 (except the last packet).

Connections over most VCs do not use extremely long messages, and the maximum size of a read() or recv() buffer is usually sufficiently large. However, if at any time during the connection the application anticipates that the VC will receive messages longer than the maximum read() or recv() buffer size, it must set the read message fragment size to a value greater than 0.

The read() and recv() calls return a whole number of packets, even when a message fragment is being read. This may cause the message fragment being read to be slightly longer or shorter than the fragment size specified in the ioctl(X25_SET_FRAGMENT_SIZE) system call. The ioctl(X25_NEXT_MSG_STAT) call is used to indicate the necessary buffer size in all instances.

When reading a long message requiring several read() or recv() calls, you must use the ioctl(X25_NEXT_MSG_STAT) call to detect the end of the message. When this call returns the x25_msg_flags value with the X25_MDTF_BIT set to 0, the next read() or recv() system call will return the end of the message.

To avoid data collision problems the ioctl(X25_SET_FRAGMENT_SIZE) call should be issued before the connect() call or between the accept() and the ioctl(X25_SEND_CALL_ACEPT) calls.

The ioctl(X25_SET_FRAGMENT_SIZE) call and its parameters are described below.

Syntax for ioctl(X25_SET_FRAGMENT_SIZE)

The syntax for the ioctl(X25_SET_FRAGMENT_SIZE) system call and its parameters are described below.

#include <x25/x25ioctls.h>
#include <x25/x25str.h>
int err;
int sd, size;
err = ioctl(sd, X25_SET_FRAGMENT_SIZE, &size);
sd

A socket descriptor for a VC socket.

X25_SET_FRAGMENT_SIZE

Indicates that the inbound message fragment size is being changed.

size

Indicates the new value for the read fragment size of messages. The range is from 0 to 32,767 where 0 indicates that all messages must be read with a single system call.

err

Upon successful completion, err is set to 0. Otherwise, a value of -1 is returned and errno is set to indicate the error.

Changing the Size of Socket Buffers

You can set the message sizes for a socket using the setsockopt(2) system call. It is important for the sockets to be able to handle the largest possible message that will be sent or received over the network. The default send and receive buffer size is 4096 bytes.

If your interface receives a message larger than the receive socket buffer size, the data will be discarded, the circuit will be reset, and you will receive an OOB_VC_MSG_TOO_BIG out-of-band event.

You can increase the size of a socket's send() or recv() buffer at any time, but they can only be reduced before a connection is established.

Syntax for setsockopt()

The syntax for the setsockopt() system call and its parameters are described below.

#include <sys/types.h>
#include <sys/socket.h>
int err;
int sd, level, optname, optval, optlen;
optlen = sizeof(int);
err = setsockopt(sd, level, optname,(char*) &optval,
optlen);
sd

A socket descriptor for an SVC socket.

level

Indicates the level at which the socket takes effect. The definition SOL_SOCKET should be specified.

optname

Indicates the type of option to be modified. This can be SO_SNDBUF to change the size of the send buffer or SO_RCVBUF to change the size of the receive buffer.

optval

Indicates the new send or receive buffer sizes where the maximum size is 58,254.

optlen

Indicates the length in bytes of the optval parameter; that is, sizeof(int).

err

Upon successful completion, err is set to 0. Otherwise, a value of -1 is returned and errno is set to indicate the error.

Increasing the send socket buffet size allows a user to send more data before the user's application blocks, waiting for more buffer space. If more than one message cannot be sent without the user waiting for a reply, the programmer may want to increase the send buffer size to allow enough room to send multiple messages.

NOTE: Increasing the buffer size to send larger portions of data before the application blocks may increase throughput, but the best method of tuning performance is to experiment with various buffer sizes.

Refer to the setsockopt(2) entry in your HP-UX man pages for more information.