Browse Source

- small fix (some poll flags were not checked)

Andrei Pelinescu-Onciul 21 years ago
parent
commit
854db58374
1 changed files with 19 additions and 6 deletions
  1. 19 6
      tsend.c

+ 19 - 6
tsend.c

@@ -58,7 +58,8 @@ int tsend_stream(int fd, char* buf, unsigned int len, int timeout)
 	written=0;
 	written=0;
 	initial_len=len;
 	initial_len=len;
 	pf.fd=fd;
 	pf.fd=fd;
-	pf.events=POLLIN;
+	pf.events=POLLOUT;
+	
 	
 	
 again:
 again:
 	n=send(fd, buf, len,
 	n=send(fd, buf, len,
@@ -86,7 +87,6 @@ again:
 		goto end;
 		goto end;
 	}
 	}
 	while(1){
 	while(1){
-		pf.revents=0;
 		n=poll(&pf, 1, timeout);
 		n=poll(&pf, 1, timeout);
 		if (n<0){
 		if (n<0){
 			if (errno==EINTR) continue; /* signal, ignore */
 			if (errno==EINTR) continue; /* signal, ignore */
@@ -98,10 +98,17 @@ again:
 			LOG(L_ERR, "ERROR: tsend_stream: send timeout (%d)\n", timeout);
 			LOG(L_ERR, "ERROR: tsend_stream: send timeout (%d)\n", timeout);
 			goto error;
 			goto error;
 		}
 		}
-		if (pf.revents&POLLIN){
+		if (pf.revents&POLLOUT){
 			/* we can write again */
 			/* we can write again */
 			goto again;
 			goto again;
+		}else if (pf.revents&(POLLERR|POLLHUP|POLLNVAL)){
+			LOG(L_ERR, "ERROR: tsend_stream: bad poll flags %x\n", 
+					pf.revents);
+			goto error;
 		}
 		}
+		/* if POLLIN or POLLPRI or other non-harmfull events happened,
+		 * continue ( although poll should never signal them since we're
+		 * not interested in them => we should never reach this point) */
 	}
 	}
 error:
 error:
 	return -1;
 	return -1;
@@ -128,7 +135,7 @@ int tsend_dgram(int fd, char* buf, unsigned int len, int timeout,
 	written=0;
 	written=0;
 	initial_len=len;
 	initial_len=len;
 	pf.fd=fd;
 	pf.fd=fd;
-	pf.events=POLLIN;
+	pf.events=POLLOUT;
 	
 	
 again:
 again:
 	n=sendto(fd, buf, len, 0, to, tolen);
 	n=sendto(fd, buf, len, 0, to, tolen);
@@ -150,7 +157,6 @@ again:
 		goto end;
 		goto end;
 	}
 	}
 	while(1){
 	while(1){
-		pf.revents=0;
 		n=poll(&pf, 1, timeout);
 		n=poll(&pf, 1, timeout);
 		if (n<0){
 		if (n<0){
 			if (errno==EINTR) continue; /* signal, ignore */
 			if (errno==EINTR) continue; /* signal, ignore */
@@ -162,10 +168,17 @@ again:
 			LOG(L_ERR, "ERROR: tsend_dgram: send timeout (%d)\n", timeout);
 			LOG(L_ERR, "ERROR: tsend_dgram: send timeout (%d)\n", timeout);
 			goto error;
 			goto error;
 		}
 		}
-		if (pf.revents&POLLIN){
+		if (pf.revents&POLLOUT){
 			/* we can write again */
 			/* we can write again */
 			goto again;
 			goto again;
+		}else if (pf.revents&(POLLERR|POLLHUP|POLLNVAL)){
+			LOG(L_ERR, "ERROR: tsend_dgram: bad poll flags %x\n", 
+					pf.revents);
+			goto error;
 		}
 		}
+		/* if POLLIN or POLLPRI or other non-harmfull events happened,
+		 * continue ( although poll should never signal them since we're
+		 * not interested in them => we should never reach this point) */
 	}
 	}
 error:
 error:
 	return -1;
 	return -1;