NAME

xgetsockopt - retrieve a xio socket option

SYNOPSIS

#include <xio/socket.h>

int xgetsockopt (int s, int level, int opt, void *optval, size_t *optlen);

DESCRIPTION

Retrieves the value for the opt. The level argument specifies the protocol level at which the opt resides. For generic socket-level options use XSOCKET level. For transport-specific options use ID of the transport as the level argument (e.g. XTCP).

The value is stored in the buffer pointed to by val argument. Size of the buffer is specified by the vallen argument. If the size of the option is greater than size of the buffer, the value will be silently truncated. Otherwise, the vallen will be modified to indicate the actual length of the option.

<xio/socket.h> header defines generic xio socket options (XSOCKET level). The options are as follows:

XPF

Returns the address family constant as it was passed to xsocket().

XSOCKTYPE

Returns the protocol constant as it was passed to xsocket().

XNOBLOCK

Send/Recv on Non-blocking mode

XLINGER

Specifies how long should the socket try to send pending outbound messages after xclose() have been called, in milliseconds. Negative value means infinite linger. The type of the option is int. Default value is 1000 (1s).

XSNDBUF

Size of the send buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the send buffer. The type of this option is int. Default value is 128kB.

XRCVBUF

Size of the receive buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the receive buffer. The type of this option is int. Default value is 128kB.

XSNDTIMEO

The timeout for send operation on the socket, in milliseconds. If message cannot be sent within the specified timeout, EAGAIN error is returned. Negative value means infinite timeout. The type of the option is int. Default value is -1.

XRCVTIMEO

The timeout for recv operation on the socket, in milliseconds. If message cannot be received within the specified timeout, EAGAIN error is returned. Negative value means infinite timeout. The type of the option is int. Default value is -1.

XSOCKETKEY

Socket name for error reporting and statistics. The type of the option is string. Default value is "socket.N" where N is socket integer.

RETURN VALUE

On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

ERRORS

EBADF

The provided socket is invalid.

EINVAL

The option is unknown or option is invalid.

EXAMPLE

int linger;
size_t sz = sizeof (linger);
xgetsockopt (s, XSOCKET, XLINGER, &linger, &sz);

SEE ALSO

xsocket(3) xsetsockopt(3) xio(7)

AUTHORS

Dong Fang <yp.fangdong@gmail.com>
Martin Sustrik <sustrik@250bpm.com>