Browse code

- tcp sigio_rt workarround for undocumented event 0x08 (which seems to be set on some errors, like receiving a RST)

Andrei Pelinescu-Onciul authored on 09/09/2005 23:32:34
Showing 3 changed files
... ...
@@ -59,7 +59,7 @@ MAIN_NAME=ser
59 59
 VERSION = 0
60 60
 PATCHLEVEL = 10
61 61
 SUBLEVEL =   99
62
-EXTRAVERSION = -dev16-tcp
62
+EXTRAVERSION = -dev17-tcp
63 63
 
64 64
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
65 65
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -714,9 +714,23 @@ again:
714 714
 				goto error;
715 715
 			}
716 716
 		}
717
+#if 0
718
+		if (n>1){
719
+			for(r=0; r<n; r++){
720
+				LOG(L_ERR, "WARNING: ep_array[%d]= %x, %p\n",
721
+						r, h->ep_array[r].events, h->ep_array[r].data.ptr);
722
+			}
723
+		}
724
+#endif
717 725
 		for (r=0; r<n; r++){
718
-			while((handle_io((struct fd_map*)h->ep_array[r].data.ptr, -1)>0)
726
+			if (h->ep_array[r].events & (EPOLLIN|EPOLLERR|EPOLLHUP)){
727
+				while((handle_io((struct fd_map*)h->ep_array[r].data.ptr,-1)>0)
719 728
 					&& repeat);
729
+			}else{
730
+				LOG(L_ERR, "ERROR:io_wait_loop_epoll: unexpected event %x"
731
+							" on %d/%d, data=%p\n", h->ep_array[r].events,
732
+							r+1, n, h->ep_array[r].data.ptr);
733
+			}
720 734
 		}
721 735
 error:
722 736
 	return n;
... ...
@@ -842,13 +856,22 @@ again:
842 856
 					(unsigned)sigio_band,
843 857
 					sigio_fd);
844 858
 #endif
845
-			if (sigio_band&(POLL_IN|POLL_ERR)){
859
+			/* on some errors (e.g. when receving TCP RST), sigio_band will
860
+			 * be set to 0x08 (undocumented, no corresp. POLL_xx), so better
861
+			 * catch all events --andrei */
862
+			if (sigio_band/*&(POLL_IN|POLL_ERR|POLL_HUP)*/){
846 863
 				fm=get_fd_map(h, sigio_fd);
847 864
 				/* we can have queued signals generated by fds not watched
848 865
 			 	 * any more, or by fds in transition, to a child 
849 866
 				 * => ignore them */
850 867
 				if (fm->type)
851 868
 					handle_io(fm, -1);
869
+				else
870
+					LOG(L_ERR, "WARNING: io_wait_loop_sigio_rt: ignoring event"
871
+							"%x on fd %d\n", sigio_band, sigio_fd);
872
+			}else{
873
+				LOG(L_ERR, "ERROR: io_wait_loop_sigio_rt: unexpected event"
874
+							" on fd %d: %x\n", sigio_fd, sigio_band);
852 875
 			}
853 876
 		}
854 877
 	}else{
... ...
@@ -44,6 +44,7 @@
44 44
 #include <netinet/in.h>
45 45
 #include <netinet/tcp.h>
46 46
 #include <arpa/inet.h>
47
+#include <signal.h>
47 48
 
48 49
 
49 50
 static char *id="$Id$";
... ...
@@ -94,6 +95,7 @@ int main (int argc, char** argv)
94 95
 	int t;
95 96
 	struct linger t_linger;
96 97
 	int k;
98
+	int err;
97 99
 	
98 100
 	/* init */
99 101
 	count=0;
... ...
@@ -107,6 +109,7 @@ int main (int argc, char** argv)
107 109
 	tcp=0;
108 110
 	tcp_rst=0;
109 111
 	con_no=1;
112
+	err=0;
110 113
 
111 114
 	opterr=0;
112 115
 	while ((c=getopt(argc,argv, "f:c:d:p:s:t:n:rTRvhV"))!=-1){
... ...
@@ -215,6 +218,12 @@ int main (int argc, char** argv)
215 218
 	}
216 219
 	if (!tcp) con_no=1;
217 220
 	
221
+	/* ignore sigpipe */
222
+	if (signal(SIGPIPE, SIG_IGN)==SIG_ERR){
223
+		fprintf(stderr, "failed to ignore SIGPIPE: %s\n", strerror(errno));
224
+		exit(-1);
225
+	}
226
+	
218 227
 	/* open packet file */
219 228
 	fd=open(fname, O_RDONLY);
220 229
 	if (fd<0){
... ...
@@ -277,8 +286,8 @@ int main (int argc, char** argv)
277 286
 		for (r=0; r<count; r++){
278 287
 			if ((verbose>1)&&((r%1000)==999)){  putchar('.'); fflush(stdout); }
279 288
 			if (send(sock, buf, n, 0)==-1) {
280
-				fprintf(stderr, "Error: send: %s\n",  strerror(errno));
281
-				exit(1);
289
+				fprintf(stderr, "Error(%d): send: %s\n", err, strerror(errno));
290
+				err++;;
282 291
 			}
283 292
 			if (usec){
284 293
 				t--;
... ...
@@ -296,13 +305,16 @@ int main (int argc, char** argv)
296 305
 	if (tcp){
297 306
 		printf("\n%d packets sent on %d tcp connections (%d on each of them),"
298 307
 				" %d bytes each => total %d bytes\n",
299
-				count*con_no, con_no, count, n, con_no*n*count);
308
+				count*con_no-err, con_no, count, n,
309
+				(con_no*count-err)*n);
300 310
 	}else{
301 311
 		printf("\n%d packets sent, %d bytes each => total %d bytes\n",
302
-				count, n, n*count);
312
+				count-err, n, n*(count-err));
303 313
 	}
314
+	if (err) printf("%d errors\n", err);
304 315
 	exit(0);
305 316
 
306 317
 error:
318
+	fprintf(stderr, "exiting due to error (%s)\n", strerror(errno));
307 319
 	exit(-1);
308 320
 }