[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP TCP/IP Services for OpenVMS
Sockets API and System Services Programming


Previous Contents Index


shutdown()

Shuts down all or part of a bidirectional connection on a socket. This function does not allow further receives or sends, or both.

The $QIO equivalent is the IO$_DEACCESS function with the IO$M_SHUTDOWN function modifier.


Format

#include <socket.h>

int shutdown ( int s, int how) ;


Arguments

s

A socket descriptor that is in a connected state as a result of a previous call to either connect() or accept() .

how

How the socket is to be shut down. Use one of the following values:
0 Do not allow further calls to recv() on the socket.
1 Do not allow further calls to send() on the socket.
2 Do not allow further calls to both send() and recv() .

Description

This function allows communications on a socket to be shut down one direction at a time rather than all at once. You can use the shutdown() function to shut down one direction in a full-duplex (bidirectional) connection.

Related Functions

See also connect() and socket() .


Return Values

0 Successful completion.
-1 Error; errno is set to indicate the error.

Errors

EBADF The socket descriptor is invalid.
EINVAL The how argument is invalid.
ENOBUFS The system has insufficient resources to complete the call.
ENOTCONN The specified socket is not connected.
ENOTSOCK The socket descriptor is invalid.

socket()

Creates an endpoint for communication by returning a special kind of file descriptor called a socket descriptor, which is associated with a TCP/IP Services socket device channel.

The $QIO equivalent is the IO$_SETMODE function.


Format

#include <types.h>

#include <socket.h>

int socket ( int af, int type, int protocol );


Arguments

af

The address family used in later references to the socket. Addresses specified in subsequent operations using the socket are interpreted according to this family. Use one of the following:
  • AF_INET for the IPv4 address family
  • AF_INET6 for the IPv6 address family
  • TCPIP$C_AUXS
    For a network application server with the LISTEN flag enabled, you specify the TCPIP$C_AUXS address family to obtain the connected device socket created by the auxiliary server in response to incoming network traffic.

type

The socket types are:
  • SOCK_STREAM --- Provides sequenced, reliable, two-way, connection-based byte streams with an available out-of-band data transmission mechanism.
  • SOCK_DGRAM --- Provides datagram transmissions. A datagram is a connectionless, unreliable data transmission mechanism.
  • SOCK_RAW --- Provides access to internal network interfaces. Available only to users with the SYSPRV privilege.

protocol

The protocol to be used with the socket. Normally, only a single protocol exists to support a particular socket type using a given address format. However, if many protocols exist, a particular protocol must be specified with this argument. Use the protocol number that is specific to the address family.

Description

This function provides the primary mechanism for creating sockets. The type and protocol of the socket affect the way the socket behaves and how it can be used.

The operation of sockets is controlled by socket-level options, which are defined in the SOCKET.H header file and described in the setsockopt() function section of this chapter.

Use the setsockopt() and getsockopt() functions to set and get options. Options take an integer argument that should be nonzero if the option is to be enabled or zero if it is to be disabled. SO_LINGER uses a linger structure argument (see Section 3.2.7).

Related Functions

See also accept() , bind() , connect() , getsockname() , getsockopt() , socketpair() , listen() , read() , recv() , recvfrom() , recvmsg() , select() , send() , sendmsg() , sendto() , shutdown() , and write() .


Return Values

x A file descriptor that refers to the socket descriptor.
-1 Error; errno is set to indicate the error.

Errors

EACCES The process does not have sufficient privileges.
EAFNOSUPPORT The specified address family is not supported in this version of the system.
EMFILE The per-process descriptor table is full.
ENETDOWN TCP/IP Services was not started.
ENFILE No more file descriptors are available for the system.
ENOBUFS The system has insufficient resources to complete the call.
ENOMEM The system was unable to allocate kernel memory to increase the process descriptor table.
EPERM The process is attempting to open a raw socket and does not have SYSTEM privilege.
EPROTONOSUPPORT The socket in the specified address family is not supported.
EPROTOTYPE The socket type is not supported by the protocol.
ESOCKTNOSUPPORT The specified socket type is not supported in this address family.

socketpair()

Creates a pair of connected sockets.

Format

#include <sys/socket.h>

int socketpair (int domain, int type, int protocol, int socket_vector[2]);


Arguments

af

The address family in which the sockets are to be created. Use one of the following:
  • AF_INET for the IPv4 address family
  • AF_INET6 for the IPv6 address family
  • TCPIP$C_AUXS or a network application server with the LISTEN flag enabled. Specify the TCPIP$C_AUXS address family to obtain the connected device socket created by the auxiliary server in response to incoming network traffic.

type

Specifies the type of sockets to be created. The socket types are:
  • SOCK_STREAM --- Provides sequenced, reliable, two-way, connection-based byte streams with an available out-of-band data transmission mechanism.
  • SOCK_DGRAM --- Supports datagrams (connectionless, unreliable data transmission mechanism).
  • SOCK_SEQPACKET --- Provides sequenced, reliable, bidirectional, connection-mode transmission paths for records. A record can be sent using one or more output operations and received using one or more input operations, but a single operation never transfers part of more than one record.
    Use the MSG_EOR flag to determine the record boundaries.

protocol

The protocol to be used with the socket. Normally, only a single protocol exists to support a particular socket type using a given address format. However, if many protocols exist, a particular protocol must be specified with this argument. Use the protocol number that is specific to the address family.

If the protocol argument is 0, the function uses the default protocol for the specified socket type.

If the protocol argument is non-zero, the function uses the default protocol for the address family.

socket_vector

A 2-integer array to hold the file descriptors of the created socket pair.

Description

This function creates an unbound pair of connected sockets in a specified address family, of a specified type, under the protocol optionally specified by the protocol argument. The two sockets will be identical. The file descriptors used in referencing the created sockets are returned in socket_vector[0] and socket_vector[1] .

Appropriate privileges are required to use the socketpair() function or to create some sockets.

Related Functions

See also socket() .


Return Values

0 Successful completion
-1 Error; errno is set to indicate the error.

Errors

EACCES The process does not have sufficient privileges.
EAFNOSUPPORT The specified address family is not supported in this version of the system.
EMFILE The per-process descriptor table is full.
ENETDOWN TCP/IP Services was not started.
ENFILE No more file descriptors are available for the system.
ENOBUFS The system has insufficient resources to complete the call.
ENOMEM The system was unable to allocate kernel memory to increase the process descriptor table.
EPERM The process is attempting to open a raw socket and does not have SYSTEM privilege.
EPROTONOSUPPORT The socket in the specified address family is not supported.
EPROTOTYPE The socket type is not supported by the protocol.
ESOCKTNOSUPPORT The specified socket type is not supported in this address family.

write()

Writes bytes from a buffer to a file or socket.

The $QIO equivalent is the IO$_WRITEVBLK function.


Format

#include <unixio.h>

int write ( int d, void *buffer, int nbytes );


Arguments

d

A descriptor that refers to a socket or file.

buffer

The address of a buffer from which the output data is to be taken.

nbytes

The maximum number of bytes involved in the write operation.

Description

This function attempts to write a buffer of data to a socket or file.

Related Functions

See also socket() .


Return Values

x The number of bytes written to the socket or file.
-1 Error; errno is set to indicate the error.

Errors

EPIPE The socket is shut down for writing or is connection oriented, and the peer is closed or shut down for reading. In the latter case, if the socket is of type SOCK_STREAM , the SIGPIPE signal is generated to the calling process.
EWOULDBLOCK The NBIO (nonblocking) flag is set for the socket descriptor, and the process is delayed during the write operation.
EINVAL The nbytes argument is a negative value.
EAGAIN The O_NONBLOCK flag is set on this file, and the process is delayed in the write operation.
EBADF The d argument does not specify a valid file descriptor that is open for writing.
EINTR A write() function on a pipe is interrupted by a signal, and no bytes have been transferred through the pipe.
EINVAL On of the following errors occurred:
  • The STREAM or multiplexer referenced by d is linked (directly or indirectly) downstream from a multiplexer.
  • The file position pointer associated with the d argument was a negative value.
EPERM An attempt was made to write to a socket of type SOCK_STREAM that is not connected to a peer socket.
EPIPE An attempt was made to write to a pipe that has only one end open.

An attempt was made to write to a pipe or FIFO that is not opened for reading by any process. A SIGPIPE signal is sent to the process.

ERANGE An attempt was made to write to a STREAM socket where the value of nbytes is outside the specified minimum and maximum range, and the minimum value is nonzero.


Chapter 5
Using the $QIO System Service

This chapter describes how to use the $QIO system service and its data structures with TCP/IP Services.

After you create a network pseudodevice (BG:) and assign a channel to it, use the $QIO system service for I/O operations.

5.1 $QIO System Service Variations

The two variations of the $QIO system service are:

  • Queue I/O Request ($QIO) --- Completes asynchronously. It returns to the caller immediately after queuing the I/O request, without waiting for the I/O operation to complete.
  • Queue I/O Request and Wait ($QIOW) --- Completes synchronously. It returns to the caller after the I/O operation completes.

The only difference between the $QIO and $QIOW calling sequences is the service name. The system service arguments are the same.

5.2 $QIO Format

The $QIO calling sequence has the following format:


SYS$QIO [efn], chan, func, [iosb], [astadr], [astprm], [p1], [p2], [p3], [p4], [p5], [p6]

Table 5-1 describes each argument.

Table 5-1 $QIO Arguments
Argument Description
astadr AST (asynchronous system trap) service routine
astprm AST parameter to be passed
chan I/O channel
efn Event flag number
func Network pseudodevice function code and/or function modifier
iosb I/O status block
p1, p2, p3, p4, p5, p6 Function-specific I/O request parameters

5.2.1 Symbol Definition Files

Table 5-2 lists the symbol definition files for the $QIO arguments p1 through p6. Use the standard mechanism for the programming language you are using to include the appropriate symbol definition files in your program.

Table 5-2 Network Symbol Definition Files
File Name Language
TCPIP$INETDEF.H C
TCPIP$INETDEF.FOR VAX Fortran
TCPIP$INETDEF.PAS VAX PASCAL
TCPIP$INETDEF.MAR MACRO-32
TCPIP$INETDEF.PLI VAX PL/1
TCPIP$INETDEF.R32 BLISS-32
TCPIP$INETDEF.ADA VAX Ada
TCPIP$INETDEF.BAS VAX BASIC

5.3 $QIO Functions

Table 5-3 lists the $QIO function codes commonly used in a network application.

Note

The IO$_SETMODE and IO$_SETCHAR function codes are identical. All references to the IO$_SETMODE function code, its arguments, options, function modifiers, and condition values returned also apply to the IO$_SETCHAR function code, which is not explicitly described in this manual.

The IO$_SENSEMODE and IO$_SENSECHAR function codes are identical. All references to the IO$_SENSEMODE function code, its arguments, options, function modifiers, and condition values returned also apply to the IO$_SENSECHAR function code, which is not explicitly described in this manual.

Table 5-3 $QIO Function Codes
Function Description
$QIO(IO$_SETMODE) $QIO(IO$_SETCHAR) Creates the socket by setting the internet domain, protocol (socket) type, and protocol of the socket.
  Binds a name (local address and port) to the socket.
  Defines a network pseudodevice as a listener on a TCP/IP server.
  Specifies socket options.
$QIO(IO$_ACCESS) Initiates a connection request from a client to a remote host using TCP.
  Specifies the peer where you can send datagrams.
  Accepts a connection request from a TCP/IP client when used with the IO$M_ACCEPT function modifier.
$QIO(IO$_WRITEVBLK) Writes data (virtual block) from the local host to the remote host for stream sockets, datagrams, and raw IP.
$QIO(IO$_READVBLK) Reads data (virtual block) from the remote host to the local host for stream sockets, datagrams, and raw IP.
$QIO(IO$_DEACCESS) Disconnects the link established between two communication agents through an IO$_DEACCESS function.
  Shuts down the communication link when used with the IO$M_SHUTDOWN function modifier. You can shut down the receive or transmit portion of the link, or both.
$QIO(IO$_SENSECHAR)
$QIO(IO$_SENSEMODE)
Obtains socket information.


Previous Next Contents Index