OTRcv
Reads data sent using a connection-oriented transactionless protocol.C INTERFACE
OTResult OTRcv (EndpointRef ref, void* buf, size_t nbytes, OTFlags* flags);C++ INTERFACE
OTResult TEndpoint::Rcv(void* buf, size_t nbytes, OTFlags* flags);PARAMETERS
ref- The endpoint reference of the endpoint receiving data.
buf- A pointer to a memory location where the incoming data is to be copied. You must allocate this buffer before you call the function. If you are doing a no-copy receive, this field is a pointer to an
OTBufferpointer.nbytes- A long specifying the size of the buffer in bytes. If you are doing a no-copy receive, you must set this field to the
kNetbufDataIsOTBufferStarconstant.flags- A long bitmapped variable specifying, on return, whether the data being sent is expedited (
T_EXPEDITED) and whether more data remains to be received (T_MORE).DESCRIPTION
You call theOTRcvfunction to read data sent by the peer to which you are connected. If theOTRcvfunction succeeds, it returns an integer (OTStatus) specifying the number of bytes received. The function places the data read into the buffer referenced by thebufparameter. If the function fails, it returns a negative integer corresponding to a result code that indicates the reason for the failure. You can call this function to receive either normal or expedited data. If the data is expedited, theT_EXPEDITEDflag is set in theflagsparameter.If
T_MOREis set in theflagsparameter when the function returns, this means that the buffer you allocated is too small to contain the data to be read and that you must call theOTRcvfunction again. If you have read x bytes with the first call, the next call to theOTRcvfunction begins to read at the (x + 1) byte. Of course, if you need it, you must copy the data in the buffer to another location before calling the function again. Each call to this function that returns with theT_MOREflag set means that you must call the function again to get more data. When you have read all the data, theOTRcvfunction returns with theT_MOREflag not set. If the endpoint does not support the concept of a TSDU, theT_MOREflag is not meaningful and should be ignored. To determine whether the endpoint supports TSDUs, examine thetsdufield of theTEndpointInfostructure. A value ofT_INVALIDmeans that the endpoint does not support it.Some protocols allow you to send zero-length data to signal the end of a logical unit. In this case, if you request more than 0 bytes when calling the
OTRcvfunction, the function returns 0 bytes only to signal the end of a TSDU.If the
OTRcvfunction returns and theT_EXPEDITEDbit is set in theflagsparameter, this means that you are about to read expedited data. If the number of bytes of expedited data exceeds the number of bytes you specified in thereqCountparameter, both theT_EXPEDITEDand theT_MOREbits are set. You must call theOTRcvfunction until theT_MOREflag is not set to retrieve the rest of the expedited data.If you are calling the
OTRcvfunction repeatedly to read normal data and a call to the function returnsT_EXPEDITEDin theflagsparameter, the next call to theOTRcvfunction that returns without theT_EXPEDITEDflag set returns normal data at the place it was interrupted. It is your responsibility to remember where that was and to continue processing normal data. You can determine how much normal data you read by maintaining a running total of the number of bytes returned in theOTStatusresult.If the endpoint is in asynchronous mode or is not blocking, the function returns with the
kOTNoDataErrresult if no data is available. If you have installed a notifier, the endpoint provider calls your notifier and passesT_DATAorT_EXDATAfor thecodeparameter when there is data available. If you have not installed a notifier, you may poll for these events using theOTLookfunction. Once you receive aT_DATAorT_EXDATAevent, you should continue in a loop, calling theOTRcvfunction until it returns with thekOTNoDataErrresult.If the endpoint is in synchronous mode and is blocking, the endpoint waits for data if none is currently available. You should avoid calling the
OTRcvfunction this way because it might cause processing to hang if no data is available. If you are doing other operations in synchronous mode, you should put the endpoint in nonblocking mode before calling theOTRcvfunction.SPECIAL CONSIDERATIONS
You should be prepared for aT_DATAevent and then akOTNoDataErrerror when you call theOTRcvfunction. This seems unusual, but it can occur if you are callingOTRcvin the foreground when aT_DATAevent comes in.Whenever the
OTRcvfunction returns akOTLookErrerror, it is very important that you call theOTLookfunction. If you are in a flow-control situation on the send side, and aT_GODATAorT_GOEXDATAevent occurs that you do not clear in your notifier (by callingOTLookor by actually sending some data), then you will hang waiting. Until theT_GODATAorT_GOEXDATAare cleared, Open Transport cannot send you anotherT_DATAevent (or any other event other than aT_DISCONNECT, for that matter).The
XTI_RCVLOWAToption allows endpoints that support it to negotiate the minimum number of bytes that must have accumulated in the endpoint's internal receive buffer before the endpoint provider generates aT_DATAevent. If the endpoint you are using supports this option, you can negotiate a value using theOTOptionManagementfunction. Because you use theOTOptionManagementfunction to set this option, it affects all subsequent sends.VALID STATES
T_DATAXFER,T_OUTRELSEE ALSO
You use theOTLookfunction (page 3-85) to poll for theT_DATAorT_EXDATAevents.You use the
OTIsNonBlockingfunction, described in the reference section of the chapter "Providers" in this book, to determine the current operational mode of the endpoint. It is recommended that the endpoint be in nonblocking mode before you call theOTRcvfunction.For information on how to use this function with a TCP/IP protocol, see page 8-19 in the TCP/IP chapter.
For information on how to use this function with AppleTalk protocols, see page 13-11 in the ADSP chapter and page 15-10 in the PAP chapter.
You use the
OTOptionManagementfunction, described in the chapter "Option Management" in this book, to negotiate theXTI_RCVLOWAToption.