Chapter Contents

Previous

Next
takesocket

takesocket



Takes a Socket Descriptor from Donor Process

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTIONS
PORTABILITY
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

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

int takesocket(struct clientid *clientid, int s);


DESCRIPTION

takesocket takes a socket descriptor, s , and a pointer to a client structure, clientid , and returns a local client socket descriptor, which must be used for subsequent TCP/IP calls. s must be a connected stream socket. The donor process must have already obtained client ID for the receiving process, and must have already called givesocket . The mechanism for exchanging client IDs and the socket descriptor number is the responsibility of the two processes and is not accomplished by either the givesocket or the takesocket call.

When giving a socket, the donor may use a clientid structure that contains blanks as the subtask name. However, when taking a socket, the receiver must specify the subtask name of the donor in the client ID. This allows the donor to make the socket available to any number of subtasks while the receiver must have the actual subtask name to take the socket. The subtask name effectively acts as a key.

The donor process should not close the socket before the receiving process has completed the takesocket call. The receiving process must have a means of informing the donor that the takesocket call has completed. Using select or selectecb in the donor, frees the receiver of this responsiblility.

Note:    takesocket is only supported with non-integrated sockets. However, starting with SAS/C Release 7.00, the takesocket function is supported for integrated sockets.   [cautionend]


RETURN VALUE

If takesocket is successful, it returns a non-negative, client socket descriptor, which can be different from the donor descriptor, s . Otherwise, it returns a -1 , and sets errno to indicate the type of error.


CAUTIONS

For nonintegrated sockets, the getclientid function returns the subtaskname member of the clientid structure with a task identifier consisting of EBCDIC characters, for example, "SASCL08c" (0xE2C1E2C3D3F0F883).

For integrated sockets, starting with SAS/C Release 7.00, the getclientid function returns the subtaskname member of the clientid structure with a task identifier containing binary data, for example, 0x0000030F634E98.

The nonintegrated socket version of the getclientid function is the default version for releases prior to SAS/C Release 7.00. However, starting with SAS/C Release 7.00, programs will use integrated sockets by default if running under OS/390 Version 2 Release 5 or greater. Thus, any code that depends on subtaskname containing printable EBCDIC characters may fail.


PORTABILITY

takesocket 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 call.


EXAMPLE

Refer to the getclientid function for an example that illustrates the use of takesocket .


RELATED FUNCTIONS

getclientid , getclientpid, givesocket , givesocket_pid, takesocket_pid


Chapter Contents

Previous

Next

Top of Page

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