tprecv(3)-routine for receiving a message in a conversational connection
#include <atmi.h>
int tprecv(int cd, char **data, long *len, long flags, long \
*revent)
tprecv() is used to receive data sent across an open connection from another program. tprecv()'s first argument, cd, specifies on which open connection to receive data. cd is a descriptor returned from either tpconnect(3) or the TPSVCINFO parameter to the service. The second argument, data, is the address of a pointer to a buffer previously allocated by tpalloc(3c).
data must be the address of a pointer to a buffer previously allocated by tpalloc(3c) and len should point to a long that tprecv() sets to the amount of data successfully received. Upon successful return, *data points to a buffer containing the reply and *len contains the size of the buffer. FML and FML32 buffers often assume a minimum size of 4096 bytes; if the reply is larger than 4096 bytes, the size of the buffer is increased to a size large enough to accommodate the data being returned.
Buffers on the sending side that may be only partially filled (for example, FML or STRING buffers) will have only the amount that is used sent. The system may then enlarge the received data size by some arbitrary amount. This means that the receiver may receive a buffer that is smaller than what was originally allocated by the sender, yet larger than the data that was sent.
The receive buffer may grow, or it may shrink, and its address almost invariably changes, as the system swaps buffers around internally. To determine whether (and how much) a reply buffer changed in size, compare its total size before tprecv was issued with *len. See intro(3) for more information about buffer management.
If *len is 0, then no data was received and neither *data nor the buffer it points to were modified. It is an error for data, *data or len to be NULL.
tprecv() can be issued only by the program that does not have control of the connection.
Following is a list of valid flags.
TPNOCHANGE
data, then *data's buffer type changes to the received buffer's type so long as the receiver recognizes the incoming buffer type. When this flag is set, the type of the buffer pointed to by *data is not allowed to change. That is, the type and sub-type of the received buffer must match the type and subtype of the buffer pointed to by *data.
TPNOBLOCK
tprecv() does not wait for data to arrive. If data is already available to receive, then tprecv() gets the data and returns. When this flag is not specified and no data is available to receive, the caller blocks until data arrives.
TPNOTIME
TPSIGRSTRT
If an event exists for the descriptor, cd, then tprecv() will return setting tperrno to TPEEVENT. The event type is returned in revent. 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(3c), or it issued tpreturn(3c), tpcommit(3c) or tpabort() 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. The descriptor used for the connection is no longer valid.
TPEV_SENDONLY
TPEV_SVCERR
tpreturn(3c). tpreturn(3c) encountered an error that precluded the service from returning successfully. For example, bad arguments may have been passed to tpreturn(3c) or tpreturn(3c) 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 is no longer a valid descriptor. If this event occurred as part of the cd recipient's transaction, then the transaction is marked abort-only.
TPEV_SVCFAIL
tpreturn(3c) with TPFAIL or TPEXIT). If the subordinate service was in control of this connection when tpreturn(3c) was called, then it can pass an application defined return value and a typed buffer back to the originator of the connection. As part of ending the service routine, the server has torn down the connection. Thus, cd is no longer a valid descriptor. If this event occurred as part of the recipient's transaction, then the transaction is marked abort-only.
TPEV_SVCSUCC
tpreturn(3c) with TPSUCCESS). As part of ending the service routine, the server has torn down the connection. Thus, cd is no longer a valid descriptor. 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 return from tprecv() where revent is set to either TPEV_SVCSUCC or TPEV_SVCFAIL, the tpurcode global contains an application defined value that was sent as part of tpreturn(3). tprecv() returns -1 on error and sets tperrno to indicate the error condition. If a call fails with a particular tperrno value, a subsequent call to tperrordetail(3c) with no intermediate ATMI calls, may provide more detailed information about the generated error. Refer to the tperrordetail(3c) reference page for more information.
Under the following conditions, tprecv() fails and sets tperrno to:
[TPEINVAL]
tpalloc(3c) or flags are invalid).
[TPEOTYPE]
TPNOCHANGE was set in flags and the type and subtype of *data do not match the type and subtype of the incoming buffer. Regardless, neither *data, its contents nor *len are changed. If the conversation is part of the caller's current transaction, then the transaction is marked abort-only because the incoming buffer is discarded.
[TPEBADDESC]
cd is invalid.
[TPETIME]
TPNOBLOCK nor TPNOTIME were specified. In either case, neither *data nor its contents are 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]
[TPETIME] and the [TPEEVENT] return codes. While in transaction mode, if the receiving side of a conversation is blocked on tprecv and the sending side calls tpabort, then the receiving side gets a return code of [TPEVENT] with an event of TPEV_DISCONIMM. However, if the sending side calls tpabort before the receiving side calls tprecv, then the transaction may have already been removed from the GTT, which causes tprecv to fail with the [TPETIME] code.
[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 buffer when calling tpreturn(3c). The return value is available in the global variable tpurcode and the buffer is available in data.
tpalloc(3), tpconnect(3), tpdiscon(3), tperrordetail(3c), tpsend(3), tpservice(3), tpstrerrordetail(3c)