Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool read_from_socket(descriptor_t *dsock)
- {
- int size;
- extern int errno;
- static char read_buf[MAX_PROTOCOL_BUFFER];
- read_buf[0] = '\0';
- /* check for buffer overflows, and drop connection in that case */
- size = 0;
- if (strlen(dsock->inbuf) >= sizeof(dsock->inbuf) - 10)
- {
- text_to_socket(dsock, "\n\r!!!! Input Overflow !!!!\n\r");
- return FALSE;
- }
- /* start reading from the socket */
- for (;;)
- {
- int sInput;
- sInput = read(dsock->control, read_buf + size,sizeof(read_buf) - 10 - size );
- if (sInput > 0)
- {
- size += sInput;
- if (read_buf[size-1] == '\n' || read_buf[size-1] == '\r')
- break;
- }
- else if (sInput == 0)
- {
- log_string("Read_from_socket: EOF");
- return FALSE;
- }
- else if (errno == EAGAIN)
- break;
- else
- {
- perror("Read_from_socket");
- return FALSE;
- }
- }
- read_buf[size] = '\0';
- ProtocolInput( dsock, read_buf, size, dsock->inbuf );
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement