lapbRecv()
PROTOTYPE
#include <lapb.h>
int lapbRecv(uint channel, void *buffer);
DESCRIPTION
lapbRecv() receives a frame of data for the channel specified by channel, which must be in the range from 0 to LAPB_MAX_NUM_CHANNELS - 1 and correspond to a registered HDLC channel. buffer points to an application buffer that the I-frame data is copied to. The buffer must be at least as large as LAPB_MAX_I_FIELD (defined in “lapb.h”).
If a received I-frame is waiting or the channel is nonblocking, lapbRecv() returns immediately. Otherwise, it blocks until either an I-frame is received or the link is reset. Link reset from other than lapbDisc() does not flush the queue of received frames. Previously received frames remain queued and lapbRecv() continues to succeed until all queued I-frames have been read. Using lapbDisc() does flush the channel’s receive queue.
If successful, lapbRecv() returns the byte length of the received data. Otherwise, it sets errno and returns -1.
ERROR CODES
| LAPB_INVALID_CHAN | channel is not a registered channel in the range from 0 to LAPB_MAX_NUM_CHANNELS - 1. |
| LAPB_NOT_CONNECTED | The selected channel is not connected. |
| LAPB_UNINITIALIZED | The initialization routine lapbInit() has not been called. |
| LAPB_WOULDBLOCK | The channel is nonblocking and no received I-frames are queued. |
EXAMPLE
/*-----------------------------------------------------------------*/
/* Wait indefinitely for received frames. */
/*-----------------------------------------------------------------*/
len = lapbRecv(channel, RecvBuf);