lapbDisc()
PROTOTYPE
#include <lapb.h>
int lapbDisc(uint channel, uint flags);
DESCRIPTION
lapbDisc() terminates the LAPB and/or physical connection 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. flags is either LAPB_DISC_HARD, LAPB_DISC_LINGER, LAPB_DISC_PHYS (defined in “lapb.h”), their bitwise OR, or zero.
Disconnection occurs in potentially three steps. A disconnect by the remote peer or because there are N2 resends without an acknowledgment cuts the process short. The normal progression is:
If LAPB_DISC_LINGER is set, lapbDiscI() blocks until all I-frames are acknowledged by the remote host. If linger is not used, I-frames that have been sent but not acknowledged may be lost. LAPB_DISC_LINGER has no effect if the channel is already disconnected.
A DISC command is sent to the remote host. If LAPB_DISC_HARD is set, the channel is reset immediately after the first DISC command. Otherwise, DISC commands are retransmitted at intervals of T1 tenths of a second until either an acknowledgement is received or a total of N2 commands have been sent.
If LAPB_DISC_PHYS is set, the HDLC driver’s disconnect() routine is called to physically disconnect the channel. Depending on the driver, this may result in line control signals being de-asserted and/or clock signals being stopped
If successful, lapbDisc() returns 0. Otherwise, it sets errno and returns -1.
ERROR CODES
| LAPB_BAD_FLAG | flags is not LAPB_DISC_LINGER, LAPB_DISC_PHYS, LAPB_DISC_HARD, their bitwise OR, or zero. |
| LAPB_INPROGRESS | A previous lapbDisc() call is in progress. |
| LAPB_INVALID_CHAN | channel is not a registered channel in the range from 0 to LAPB_MAX_NUM_CHANNELS - 1. |
| LAPB_UNINITIALIZED | The initialization routine lapbInit() has not been called. |
| LAPB_WOULDBLOCK | LAPB_DISC_LINGER is set and the channel is nonblocking. |
EXAMPLE
/*-----------------------------------------------------------------*/
/* Linger and then physically disconnect the channel. */
/*-----------------------------------------------------------------*/
lapbDisc(channel, LAPB_DISC_LINGER | LAPB_DISC_PHYS);