Browse code

- small fix (some poll flags were not checked)

Andrei Pelinescu-Onciul authored on 27/02/2004 12:42:05
Showing 1 changed files
... ...
@@ -58,7 +58,8 @@ int tsend_stream(int fd, char* buf, unsigned int len, int timeout)
58 58
 	written=0;
59 59
 	initial_len=len;
60 60
 	pf.fd=fd;
61
-	pf.events=POLLIN;
61
+	pf.events=POLLOUT;
62
+	
62 63
 	
63 64
 again:
64 65
 	n=send(fd, buf, len,
... ...
@@ -86,7 +87,6 @@ again:
86 87
 		goto end;
87 88
 	}
88 89
 	while(1){
89
-		pf.revents=0;
90 90
 		n=poll(&pf, 1, timeout);
91 91
 		if (n<0){
92 92
 			if (errno==EINTR) continue; /* signal, ignore */
... ...
@@ -98,10 +98,17 @@ again:
98 98
 			LOG(L_ERR, "ERROR: tsend_stream: send timeout (%d)\n", timeout);
99 99
 			goto error;
100 100
 		}
101
-		if (pf.revents&POLLIN){
101
+		if (pf.revents&POLLOUT){
102 102
 			/* we can write again */
103 103
 			goto again;
104
+		}else if (pf.revents&(POLLERR|POLLHUP|POLLNVAL)){
105
+			LOG(L_ERR, "ERROR: tsend_stream: bad poll flags %x\n", 
106
+					pf.revents);
107
+			goto error;
104 108
 		}
109
+		/* if POLLIN or POLLPRI or other non-harmfull events happened,
110
+		 * continue ( although poll should never signal them since we're
111
+		 * not interested in them => we should never reach this point) */
105 112
 	}
106 113
 error:
107 114
 	return -1;
... ...
@@ -128,7 +135,7 @@ int tsend_dgram(int fd, char* buf, unsigned int len, int timeout,
128 135
 	written=0;
129 136
 	initial_len=len;
130 137
 	pf.fd=fd;
131
-	pf.events=POLLIN;
138
+	pf.events=POLLOUT;
132 139
 	
133 140
 again:
134 141
 	n=sendto(fd, buf, len, 0, to, tolen);
... ...
@@ -150,7 +157,6 @@ again:
150 157
 		goto end;
151 158
 	}
152 159
 	while(1){
153
-		pf.revents=0;
154 160
 		n=poll(&pf, 1, timeout);
155 161
 		if (n<0){
156 162
 			if (errno==EINTR) continue; /* signal, ignore */
... ...
@@ -162,10 +168,17 @@ again:
162 168
 			LOG(L_ERR, "ERROR: tsend_dgram: send timeout (%d)\n", timeout);
163 169
 			goto error;
164 170
 		}
165
-		if (pf.revents&POLLIN){
171
+		if (pf.revents&POLLOUT){
166 172
 			/* we can write again */
167 173
 			goto again;
174
+		}else if (pf.revents&(POLLERR|POLLHUP|POLLNVAL)){
175
+			LOG(L_ERR, "ERROR: tsend_dgram: bad poll flags %x\n", 
176
+					pf.revents);
177
+			goto error;
168 178
 		}
179
+		/* if POLLIN or POLLPRI or other non-harmfull events happened,
180
+		 * continue ( although poll should never signal them since we're
181
+		 * not interested in them => we should never reach this point) */
169 182
 	}
170 183
 error:
171 184
 	return -1;