- input.end = ntohs( plength );
- input.cur = 0;
- }
- size_t e = input.end - input.cur;
- unsigned char *p = input.buffer + input.cur;
- if ( input.end > BUFSIZE ) {
- // Oversize packets should be read and discarded
- if ( e > BUFSIZE ) {
- e = BUFSIZE;
- }
- p = input.buffer;
- }
- input.cur += read_into( 0, p, e, 1 );
- } else {
- input.end = doread( tap_fd, input.buffer, BUFSIZE );
- input.cur = input.end;
- }
- if ( input.end == input.cur ) {
- VERBOSE3OUT( "TAP/stdio input %d bytes\n", input.end );
- if ( input.end <= BUFSIZE ) {
- received_tap( input.buffer, input.end );
- }
- input.end = 0; // Ready for next packet
- }
- // End handling tap
-}
-
-// MAXFD is Finalized before multi-threading, and then remains constant.
-static int MAXFD;
-
-// This is the main packet handling loop
-static int packet_loop() {
- // A packet buffer for receiving UDP
- unsigned char buffer[ BUFSIZE ];
- int n;
- //time_t next_heartbeat = time(0);
- int cycle = 0; // which channel to check first
- while( 1 ) {
- fd_set rd_set;
- FD_ZERO( &rd_set );
- if ( mcast.fd ) {
- FD_SET( mcast.fd, &rd_set );
- }
- FD_SET( udp_fd, &rd_set );
- if ( udp6 ) {
- FD_SET( udp_fd, &rd_set );
- }
- if ( tap ) { // tap/stdio
- FD_SET( tap_fd, &rd_set );
- }
- n = select( MAXFD, &rd_set, NULL, NULL, NULL );
- VERBOSE3OUT( "select got %d\n", n );
- if ( n < 0 ) {
- if ( errno == EINTR ) {
- continue;
+ end = ntohs( plength );
+ cur = 0;
+ while ( ( e = ( end - cur ) ) != 0 ) {
+ unsigned char *p = todo->buffer + cur;
+ if ( end > BUFSIZE ) {
+ // Oversize packets should be read and discarded
+ if ( e > BUFSIZE ) {
+ e = BUFSIZE;
+ }
+ p = todo->buffer;
+ }
+ cur += read_into( 0, p, e, 1 );