Chapter Contents

Previous

Next
givesocket_pid

givesocket_pid



Gives a Socket to Another Process

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUES
CAUTION
PORTABILITY
RELATED FUNCTIONS


SYNOPSIS

#include <sys/types.h>
#include <sys/socket.h>

int givesocket_pid(int s, const struct clientpid *clientpid, pid_t pid,
                   unsigned char options);

int s;                         
struct clientpid * clientpid;  
pid_t pid;                     
unsigned char options;    

where:

int s

is the socket descriptor.

struct clientpid * clientpid

is the pointer to the clientpid structure.

pid_t pid

is the process ID from getclientpid().

unsigned char options

is the options flag.


DESCRIPTION

The givesocket_pid function is used to make a specified socket available to a takesocket_pid call issued by another process.

givesocket_pid is similar to the givesocket function. However, it uses the information in the clientpid structure returned by a call to the getclientpid function.

The socket identifier parameter, s, must contain the descriptor of the socket to be given.

The clientpid structure member domain must contain the same value as those returned by the call to getclientpid. If the domain member is 0, then a default of AF_INET is used.

The options parameter must be either binary zeros (0x00) or SO_CLOSE. If options is SO_CLOSE, then givesocket_pid will close the socket identified by the given socket descriptor(s) and return a unique socket token in the socket identifier parameter(s). This socket token must be used as the socket identifier in a call to the takesocket_pid function.


RETURN VALUES

If givesocket_pid succeeds, it returns the socket identifier (that is, either a socket descriptor or a token). Otherwise, it returns a -1 , and sets errno to indicate the error.

Note:    The clientpid structure upon return will contain the following values:
domain the domain of the socket to be taken, default = AF_INET
pid the process ID number of the client process
sid socket identifier
All other fields in the clientpid structure are set to binary zeros (0x00).

Setting the options flag to SO_CLOSE improves performance by allowing givesocket_pid to automatically close the socket rather then requiring the application to do a select and a close.

If SO_CLOSE is not used to close the socket, givesocket_pid will not close the socket, and the socket descriptor is to be used in the call to takesocket_pid.

If the given socket is not closed, it can still be used, even after the takesocket_pid has been done. The socket can be shared between the giver and taker in the same way that an inherited socket can be shared between parent and child after a fork has been issued.

If SO_CLOSE is not used to close the socket within the givesocket_pid call, but instead the caller of givesocket_pid issues the close some time later, it may be necessary to coordinate with the caller of takesocket_pid. The close itself does not interfere with takesocket_pid, but if additional sockets are accepted, given away, and closed before takesocket_pid is called, there can be several given sockets with the same descriptor waiting to be taken. This can cause unpredictable results.

To avoid this problem, a given socket can be selected, and the program can find out from select when the takesocket_pid call has been issued and it is safe to call close. However, selecting the main socket and having all given sockets wait for another connection, or for one of the given sockets to be taken, is very expensive.  [cautionend]


CAUTION

The getclientpid function is available only for integrated sockets an OS/390 Version 1 Release 3 or later.


PORTABILITY

givesocket_pid is not portable to UNIX operating systems. On UNIX operating systems, sockets are typically transferred from parent to child processes as a side effect of the fork system.


RELATED FUNCTIONS

givesocket, takesocket, getclientid, getclientpid, takesocket_pid


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.