TPRECV-receive a message in a conversational connection
01TPSVCDEF-REC.
COPY TPSVCDEF.
01TPTYPE-REC.
COPY TPTYPE.
01DATA-REC.
COPY User data.
01TPSTATUS-REC.
COPY TPSTATUS.
CALL "TPRECV" USINGTPSVCDEF-RECTPTYPE-RECDATA-RECTPSTATUS-REC.
TPRECV is used to receive data sent across an open connection from another program. COMM-HANDLE, specifies on which open connection to receive data. COMM-HANDLE is a communications handle returned from either TPCONNECT() or TPSVCSTART(). DATA-REC specifies where the message is read into, and, on input, LEN indicates the maximum number of bytes that should be moved into DATA-REC.
Upon successful and for several event types, LEN contains the actual number of bytes moved into DATA-REC. REC-TYPE and SUB-TYPE contain the data's type and sub-type, respectively. If the message is larger than DATA-REC, then DATA-REC will contain only as many bytes as will fit in the record. The remainder of the reply is discarded and TPRECV sets TPTRUNCATE.
If LEN is 0 upon successful return, then the reply has no data portion and DATA-REC was not modified. It is an error for LEN to be 0 on input.
TPRECV can be issued only by the program that does not have control of the connection.
Following is a list of valid settings in TPSVCDEF-REC.
TPNOCHANGE
DATA-REC is not allowed to change. That is, the type and sub-type of the message received must match REC-TYPE and SUB-TYPE, respectively. Either TPNOCHANGE or TPCHANGE must be set.
TPCHANGE
REC-TYPE and SUB-TYPE, respectively, so long as the receiver recognizes the incoming record type. Either TPNOCHANGE or TPCHANGE must be set.
TPNOBLOCK
TPRECV does wait for data to arrive. If data is already available to receive, then TPRECV gets the data and returns. Either TPNOBLOCK or TPBLOCK must be set.
TPBLOCK
TPBLOCK is specified and no data is available to receive, the caller blocks until data arrives. Either TPNOBLOCK or TPBLOCK must be set.
TPNOTIME
TPNOTIME or TPTIME must be set.
TPTIME
TPNOTIME or TPTIME must be set.
TPSIGRSTRT
TPNOSIGRSTRT or TPSIGRSTRT must be set.
TPNOSIGRSTRT
TPNOSIGRSTRT or TPSIGRSTRT must be set.
If an event exists for the communications handle, COMM-HANDLE, then TPRECV will return setting TP-STATUS to TPEEVENT. The event type is returned in TPEVENT. Data can be received along with the TPEV-SVCSUCC, TPEV-SVCFAIL, and TPEV-SENDONLY events. Valid events for TPRECV are as follows.
TPEV-DISCONIMM
TPDISCON(), or an error occurred when the originator issued TPRETURN() or TPCOMMIT() with the connection still open. This event is also returned to the originator or subordinate when a connection is broken due to a communications error (for example, a server, machine, or network failure). Because this is an immediate disconnection notification (that is, abortive rather than orderly), data in transit may be lost. If the two programs were participating in the same transaction, then the transaction is marked abort-only. COMM-HANDLE is no longer valid.
TPEV-SENDONLY
TPEV-SVCERR
TPRETURN(). TPRETURN() encountered an errors that precluded the service from returning successfully. For example, bad arguments may have been passed to TPRETURN() or TPRETURN() may have been called while the service had open connections to other subordinates. Due to the nature of this event, any application defined data or return code are not available. The connection has been torn down and COMM-HANDLE is no longer valid. If this event occurred as part of the recipient's transaction, then the transaction is marked as abort-only.
TPEV-SVCFAIL
TPRETURN() with TPFAIL or TPEXIT). If the subordinate service was in control of this connection when TPRETURN() was called, then it can pass an application defined return value and a record back to the originator of the connection. As part of ending the service routine, the server has torn down the connection. Thus, COMM-HANDLE is no longer valid. If this event occurred as part of the recipient's transaction, then the transaction is marked abort-only.
TPEV-SVCSUCC
TPRETURN() with TPSUCCESS). As part of ending the service routine, the server has torn down the connection. Thus, COMM-HANDLE is no longer valid. If the recipient is in transaction mode, then it can either commit (if it is also the initiator) or abort the transaction causing the work done by the server (if also in transaction mode) to either commit or abort.
Upon successful completion, TPRECV sets TP-STATUS to [TPOK]. When TP-STATUS is set to [TPEEVENT] and TPEVENT is either TPEV-SVCSUCC or TPEV-SVCFAIL, APPL-RETURN-CODE contains an application defined value that was sent as part of TPRETURN(). If the size of the incoming message was larger then the size specified in LEN on input, TPTRUNCATE is set and only LEN amount of data was moved to DATA-REC, the remaining data is discarded.
Under the following conditions, TPRECV fails and sets TP-STATUS to (unless otherwise noted, failure does not affect the caller's transaction, if one exists):
TPEINVAL]
TPSVCDEF-REC are invalid.
TPEOTYPE]
TPNOCHANGE was set and REC-TYPE and SUB-TYPE do not match the type and sub-type of the incoming message. If the conversation is part of the caller's transaction, then the transaction is marked abort-only since the incoming message is discarded.
TPEBADDESC]
COMM-HANDLE contains an invalid communications handle.
TPETIME]
TPNOBLOCK nor TPNOTIME were specified. In either case, DATA-REC was not changed. If a transaction timeout occurred, then any attempts to send or receive messages on any connections or to start a new connection will fail with TPETIME until the transaction has been aborted.
TPEEVENT]
TPEVENT.
TPEBLOCK]
TPNOBLOCK was specified.
TPGOTSIG]
TPSIGRSTRT was not specified.
TPEPROTO]
TPRECV was called in an improper context (for example, the connection was established such that the calling program can only send data).
[TPESYSTEM]
[TPEOS]
A server can pass an application defined return value and typed record when calling TPRETURN(). The return value is available in APPL-RETURN-CODE and the record is available in DATA-REC.
TPCONNECT(), TPDISCON(), TPSEND()