WRITE

The WRITE macro writes data on a connected socket. The WRITE macro is similar to the SEND macro except that it does not have the control flags that can be used with SEND.

For datagram sockets, this macro writes the entire datagram, if it will fit into one TCP⁄IP buffer.

For stream sockets, the data is processed as streams of information with no boundaries separating the data. For example, if you want to send 1000 bytes of data, each call to the write macro can send 1 byte, 10 bytes, or the entire 1000 bytes. You should place the WRITE macro in a loop that cycles until all of the data has been sent.

The following requirements apply to this call:
Read syntax diagramSkip visual syntax diagram
>>-EZASMI--TYPE=WRITE--,S--=--+-number---+---------------------->
                              +-address--+   
                              +-*indaddr-+   
                              '-(reg)----'   

>--,NBYTE--=--+-number---+--,BUF--=--+-address--+--------------->
              +-address--+           +-*indaddr-+   
              +-*indaddr-+           '-(reg)----'   
              '-(reg)----'                          

>--+------------------------+--,ERRNO--=--+-address--+---------->
   '-,ALET--=--+-address--+-'             +-*indaddr-+   
               +-*indaddr-+               '-(reg)----'   
               '-(reg)----'                              

>--,RETCODE--=--+-address--+--+---------------------------+----->
                +-*indaddr-+  +-,ECB--=--+-address--+-----+   
                '-(reg)----'  |          +-*indaddr-+     |   
                              |          '-(reg)----'     |   
                              '-,REQAREA--=--+-address--+-'   
                                             +-*indaddr-+     
                                             '-(reg)----'     

>--+-------------------------+--+------------------------+-----><
   '-,ERROR--=--+-address--+-'  '-,TASK--=--+-address--+-'   
                +-*indaddr-+                +-*indaddr-+     
                '-(reg)----'                '-(reg)----'     

Keyword
Description
S
Input parameter. A value or the address of a halfword binary number specifying the socket descriptor of the socket to receive the data.
NBYTE
Input parameter. A value or the address of a fullword binary field specifying the number of bytes of data to transmit.
BUF
The address of the data being transmitted. The length of BUF must be at least as long as the value of NBYTE.
ALET
Optional input parameter. A fullword binary field containing the ALET of BUF. The default is 0 (primary address space).

If a nonzero ALET is specified, the ALET must represent a valid entry in the dispatchable unit access list (DU-AL) for the task issuing this call. Note that ALETs can be specified only for synchronous socket calls (for example, ECB/REQAREA cannot be specified). An exception to this is an ALET representing a SCOPE=COMMON data space.

ERRNO
Output parameter. A fullword binary field. If RETCODE is negative, this field contains an error number. See Socket call error return codes for information about ERRNO return codes.
RETCODE
Output parameter. A fullword binary field.
Value
Description
>0
A successful call. The value is set to the number of bytes transmitted.
0
Connection partner has closed connection.
-1
Check ERRNO for an error code.
ECB or REQAREA
Input parameter. This parameter is required if you are using APITYPE=3. It points to a 104-byte field containing:
For ECB
A 4-byte ECB posted by TCP/IP when the macro completes.
For REQAREA
A 4-byte user token (set by you) that is presented to your exit when the response to this function request is complete.
For ECB/REQAREA
The last 100 bytes is a storage field used by the interface to save the state information.
Note: This storage must not be modified until the macro function has completed and the ECB has been posted, or the asynchronous exit has been driven.
ERROR
Input parameter. The location in your program to receive control when the application programming interface (API) processing module cannot be loaded.
TASK
Input parameter. The location of the task storage area in your program.

This macro writes up to NBYTE bytes of data. If there is not enough available buffer space for the socket data to be transmitted, and the socket is in blocking mode, WRITE blocks the caller until additional buffer space is available. If the socket is in nonblocking mode, WRITE returns a -1 and sets ERRNO to 35 (EWOULDBLOCK). See FCNTL or IOCTL for a description of how to set the nonblocking mode.