Sending and Receiving Data /* Each TX or RX packet must contain a 16 byte control header that is * used to *p ass protocol specific information to the driver. Note, API header does not *get transmitted. */ /* In this case, we loop until certain number of packets are transmitted * or an * Event occurs */ for(;;) { /* Initialize the select() variables for receiving, transmitting, and * oob/event *data */ FD_ZERO(&readset); FD_ZERO(&oobset); FD_ZERO(&writeset); FD_SET(sock,&readset); FD_SET(sock,&oobset); FD_SET(sock,&writeset); /* Select() system call can timeout due to link inactivity. This option * is not * being used in this example */ tv.tv_usec = 0; tv.tv_sec = TIMEOUT; /* The select function must be used to implement flow control. * WANPIPE socket will block if socket buffers are full. * Select system call can monitor arbitrary number of sockets */ if((err=select(sock + 1,&readset, &writeset, &oobset, &tv))){ /* Select() received a signal from the socket, * we must check which operations are allowed */ if (FD_ISSET(sock,&readset)){ /* Socket has incoming data, use recv() system call to obtain * the incoming packet */ err = recv(sock, Rx_data, sizeof(Rx_data), 0); /* Handle received data ... */ }else if (FD_ISSET(sock,&writeset)){ /*Socket buffers are not full and data can be transmitted * create a packet and use send() system call to pass data to the driver * */ err = send(sock, Tx_data, Tx_lgth + sizeof(x25api_hdr_t),0); /* Handle any errors or other any other logic ...*/ }else if (FD_ISSET(sock,&oobset)){ /*An error has occurred during X25 operation. We must receive the OOB * packet * then determine and handle the error condition*/ err = recv(sock, Rx_data, sizeof(Rx_data), MSG_OOB); /* Handle an error and any other logic ... */ } } /*End of socket() call */ }/* End of for(;;) loop */ Once data transfer is complete, a connection is terminated using the close() system call */ close(sock);