Taking sockets from the main process

As shown in Figure 1, the subtask is reactivated by the post() call issued from the main process, and immediately issues a takesocket() call to receive the socket passed from the main process. Figure 1 illustrates this process.
Figure 1. Taking sockets from the main process
*---------------------------------------------------------------------* 
* Take socket from main process                                       *  
*---------------------------------------------------------------------*
   EZASMI TYPE=TAKESOCKET,    *Takesocket                               C 
          CLIENT=TPIMCLNI,    *Main task client id structure            C
          SOCRECV=TPISSOD,    *Main task socket descriptor              C
          ERRNO=ERRNO,                                                  C
          RET CODE=RETCODE,                                             C
          ERROR=EZAERROR
   ICM    R15,15,RETCODE      *Did we do well ?
   BM     EZAERROR            *- No, deal with it. 
   STH    R15,TPISNSOD        *Server subtask socket descr.no 
*
TPIMCLNI DS    0C             *Main task client id
TPIMCDOM DC    A(0)           *Domain: AF-INET
TPIMCNAM DC    CL8' '         *Our address space name
TPIMCTSK DC    CL8' '         *Main task TCB address in EBCDIC
         DC    20X'00'        *Reserved (part of clientid)
*
TPISSOD  DC    AL2(0)         *Parent socket descr. no.
TPISNSOD DC    AL2(0)         *Subtask socket descr. no.  
In order to take a socket, the subtask must know the client ID of the task that gave the socket, and the socket descriptor used by that task. These values must be passed to the subtask from the main process before a takesocket() call can be issued.

On the takesocket() call, you specify the full client ID of the process that gave the socket, and you specify the socket descriptor number used by the process that gave the socket.

A new socket descriptor number to be used by the subtask is returned in the RETCODE when the takesocket() call is successful. As soon as your subtask has taken the socket, the main process is posted in its pending select with a pending exception activity; this means that the main process must close its socket descriptor.

In Figure 1, the client sends its request to the subtask, which processes it and sends back a reply.

Finally, the client process and the server subtask close their sockets, and the server subtask reenters wait-for-work status.