Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. bool read_from_socket(descriptor_t *dsock)
  2. {
  3.   int size;
  4.   extern int errno;
  5.   static char read_buf[MAX_PROTOCOL_BUFFER];
  6.   read_buf[0] = '\0';
  7.  
  8.   /* check for buffer overflows, and drop connection in that case */
  9.   size = 0;
  10.   if (strlen(dsock->inbuf) >= sizeof(dsock->inbuf) - 10)
  11.   {
  12.     text_to_socket(dsock, "\n\r!!!! Input Overflow !!!!\n\r");
  13.     return FALSE;
  14.   }
  15.  
  16.   /* start reading from the socket */
  17.   for (;;)
  18.   {
  19.     int sInput;
  20.  
  21.     sInput = read(dsock->control, read_buf + size,sizeof(read_buf) - 10 - size );
  22.  
  23.     if (sInput > 0)
  24.     {
  25.       size += sInput;
  26.  
  27.       if (read_buf[size-1] == '\n' || read_buf[size-1] == '\r')
  28.         break;
  29.     }
  30.     else if (sInput == 0)
  31.     {
  32.       log_string("Read_from_socket: EOF");
  33.       return FALSE;
  34.     }
  35.     else if (errno == EAGAIN)
  36.       break;
  37.     else
  38.     {
  39.       perror("Read_from_socket");
  40.       return FALSE;
  41.     }    
  42.   }
  43.   read_buf[size] = '\0';
  44.   ProtocolInput( dsock, read_buf, size, dsock->inbuf );
  45.   return TRUE;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement