Sample Programs

 

 

 

Connection Mode

#define GOT_CTRL

1

/* message has only a control part */

#define GOT_DATA

2

/* message

has only a data part */

#define GOT_BOTH

3

/* message

has both control and data parts */

int

 

 

get_msg(fd)

 

 

int

fd;

/* file descriptor */

{

 

 

int

flags = 0;

/* 0 ---> get any available message */

int

result = 0;

/* return value */

/*

 

 

zero first byte of control area so the caller can call check_ctrl without checking the get_msg return value; if there was only data in the message and the user was expecting control or control + data, then when he calls check_ctrl it will compare the expected primitive zero and print information about the primitive that it got.

*/

ctrl_area[0] = 0;

/* call getmsg and check for an error */ if(getmsg(fd, &ctrl_buf, &data_buf, &flags) < 0) {

printf(”error: getmsg failed, errno = %d\n”, errno); exit(1);

}

if(ctrl_buf.len > 0) { result = GOT_CTRL;

}

if(data_buf.len > 0) { result = GOT_DATA;

}

return(result);

}

/************************************************************************** check that control message is the expected message

**************************************************************************/

void

 

 

check_ctrl(ex_prim)

 

int

ex_prim;

/* the expected primitive */

{

 

 

dl_error_ack_t

*err_ack = (dl_error_ack_t *)ctrl_area;

/* did we get the expected primitive? */ if(err_ack->dl_primitive != ex_prim) {

/* did we get a control part */ if(ctrl_buf.len) {

/* yup; is it an ERROR_ACK? */

if(err_ack->dl_primitive == DL_ERROR_ACK) { /* yup; format the ERROR_ACK info */ printf(”error: expected primitive 0x%02x, ”,

ex_prim);

printf(”got DL_ERROR_ACK\n”);

printf(” dl_error_primitive = 0x%02x\n”, err_ack->dl_error_primitive);

printf(” dl_errno = 0x%02x\n”, err_ack->dl_errno);

printf(” dl_unix_errno = %d\n”,

Appendix A

145