z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


givesocket and takesocket

z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
SC27-3660-00

In the UNIX operating system, a new process is dispatched with the fork() system call after the server has established the connection; the new process automatically inherits the socket attached to the client. In MVS™, an independent task is started using the attach() supervisor call instruction. A server can perform an attach() call for a subtask after each connection is established in a way similar to the UNIX operating system, or it can request an attach() several times when it begins execution and pass clients to tasks that exist. In either case, the server must manually give the new socket to the subtask. Because each task has its own socket table, it is not sufficient to pass only the socket number to the subtask. Socket Number 4 for Task A is not the same as socket Number 4 for Task B.

For C programs using TCP/IP Services, each task is given a unique 8-byte name. The task uses the getclientid() call to determine its unique name. The main server task passes the following arguments to the givesocket() call:
  • The socket number it wants to give
  • Its own name
  • The name of the task to which it wants to give the socket
If the server does not know the name of the subtask to receive the socket, it blanks out the name of the subtask. The first subtask calling takesocket() using the server unique name receives the socket. However, the subtask must know the main task unique name, and the number of the socket it is to receive. This information can be passed in a common work area that you define.

When takesocket() acquires the socket, it assigns a new socket number for the subtask to use, but the new socket number represents the same line of communication as the parent socket. The transferred socket can be referred to as socket Number 4 by the parent task, and as socket Number 3 by the subtask. However, both sockets represent the same connection to the TCPIP address space.

After the socket has successfully been transferred, the TCPIP address space posts an exception condition on the parent socket. The parent uses the select() call to test for this condition. After the notification, the parent task must issue close() call on its socket to deallocate the socket.

Multitasking C socket sample program contains examples of a server, a subtask, and a client. Three examples are written in C, and one example is written in System/370 assembler language.

The C sample programs are included as members of the file SEZAINST partitioned data set. The member names are:
  • MTCSRVR
  • MTCCSUB
  • MTCCLNT
For information about the JCL needed to use the multitasking facility (MTF), see IBM® C/370™ User’s Guide.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014