feat: dissociate timeouts and empty pastes
feuille was handling those two errors the same way, by sending `Timeout'd.' even if the client just sent an EOF.
This commit is contained in:
		
							parent
							
								
									6a20fa7e61
								
							
						
					
					
						commit
						24da772e56
					
				
					 2 changed files with 10 additions and 2 deletions
				
			
		|  | @ -354,9 +354,12 @@ int main(int argc, char *argv[]) | |||
|                     } | ||||
|                 } else { | ||||
|                     if (errno == EFBIG) | ||||
|                         send_response(connection, "File too big.\n"); | ||||
|                         send_response(connection, "Paste too big.\n"); | ||||
| 
 | ||||
|                     if (errno == ENOENT) | ||||
|                         send_response(connection, "Empty paste.\n"); | ||||
| 
 | ||||
|                     if (errno == EAGAIN) | ||||
|                         send_response(connection, "Timeout'd.\n"); | ||||
| 
 | ||||
|                     error("error %d while reading paste from incoming connection.", errno); | ||||
|  |  | |||
							
								
								
									
										7
									
								
								server.c
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								server.c
									
										
									
									
									
								
							|  | @ -188,6 +188,7 @@ char *read_paste(int connection) | |||
| 
 | ||||
|     /* read all data until EOF is received, or max file size is reached, or the socket timeouts... */ | ||||
|     /* each time, the data is appended to the buffer, once it's been reallocated a larger size */ | ||||
|     errno = 0; | ||||
|     long size; | ||||
|     while ((size = recv(connection, buffer + total_size, buffer_size - total_size, 0)) > 0) { | ||||
|         total_size += size; | ||||
|  | @ -216,11 +217,15 @@ char *read_paste(int connection) | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     printf("%d\n", errno); | ||||
| 
 | ||||
|     /* is the buffer empty? */ | ||||
|     if (total_size == 0) { | ||||
|         /* yup, free the buffer and return an error */ | ||||
|         if (errno != EAGAIN) | ||||
|             errno = ENOENT; | ||||
| 
 | ||||
|         free(buffer); | ||||
|         errno = ENOENT; | ||||
|         return NULL; | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Reference in a new issue
	
	 Tom MTT
						Tom MTT