Browse code

- applied Michal Matyska <michal@iptel.org> patch: fixes sercmd/libbinrpc getting stuck in infinite loop on EOF (ser shutdown). Closes SER-295.

Andrei Pelinescu-Onciul authored on 20/08/2007 10:36:37
Showing 2 changed files
... ...
@@ -451,12 +451,17 @@ static int get_reply(struct binrpc_handle *handle,
451 451
 	
452 452
 	do {		
453 453
 		n = read(handle->socket, crt, handle->buf_size - (crt-handle->buf));
454
-		if (n < 0){
454
+		if (n <= 0){
455 455
 			if (errno==EINTR)
456 456
 				continue;
457
-			snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
458
-				"get_reply: read reply failed: %s (%d)",
459
-				strerror(errno), errno);
457
+			if (n == 0)
458
+				snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
459
+					"get_reply: read unexpected EOF: received %d bytes"
460
+					" of reply", n);
461
+			else
462
+				snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
463
+					"get_reply: read reply failed: %s (%d)",
464
+					strerror(errno), errno);
460 465
 			return FATAL_ERROR;
461 466
 		}
462 467
 		if (verbose >= 3){
... ...
@@ -576,7 +576,7 @@ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size,
576 576
 	binrpc_errno=0;
577 577
 	do{
578 578
 		n=read(s, crt, (int)(msg_end-crt));
579
-		if (n<0){
579
+		if (n<=0){
580 580
 			if (errno==EINTR)
581 581
 				continue;
582 582
 			goto error_read;