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 842
 					(unsigned)sigio_band,
843 843
 					sigio_fd);
844 844
 #endif
845
-			if (sigio_band&(POLL_IN|POLL_ERR)){
845
+			/* on some errors (e.g. when receving TCP RST), sigio_band will
846
+			 * be set to 0x08 (undocumented, no corresp. POLL_xx), so better
847
+			 * catch all events --andrei */
848
+			if (sigio_band/*&(POLL_IN|POLL_ERR|POLL_HUP)*/){
846 849
 				fm=get_fd_map(h, sigio_fd);
847 850
 				/* we can have queued signals generated by fds not watched
848 851
 			 	 * any more, or by fds in transition, to a child 
849 852
 				 * => ignore them */
850 853
 				if (fm->type)
851 854
 					handle_io(fm, -1);
855
+				else
856
+					LOG(L_ERR, "WARNING: io_wait_loop_sigio_rt: ignoring event"
857
+							"%x on fd %d\n", sigio_band, sigio_fd);
858
+			}else{
859
+				LOG(L_ERR, "ERROR: io_wait_loop_sigio_rt: unexpected event"
860
+							" on fd %d: %x\n", sigio_fd, sigio_band);
852 861
 			}
853 862
 		}
854 863
 	}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 94
 	int t;
95 95
 	struct linger t_linger;
96 96
 	int k;
97
+	int err;
97 98
 	
98 99
 	/* init */
99 100
 	count=0;
... ...
@@ -107,6 +109,7 @@ int main (int argc, char** argv)
107 107
 	tcp=0;
108 108
 	tcp_rst=0;
109 109
 	con_no=1;
110
+	err=0;
110 111
 
111 112
 	opterr=0;
112 113
 	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 215
 	}
216 216
 	if (!tcp) con_no=1;
217 217
 	
218
+	/* ignore sigpipe */
219
+	if (signal(SIGPIPE, SIG_IGN)==SIG_ERR){
220
+		fprintf(stderr, "failed to ignore SIGPIPE: %s\n", strerror(errno));
221
+		exit(-1);
222
+	}
223
+	
218 224
 	/* open packet file */
219 225
 	fd=open(fname, O_RDONLY);
220 226
 	if (fd<0){
... ...
@@ -277,8 +286,8 @@ int main (int argc, char** argv)
277 277
 		for (r=0; r<count; r++){
278 278
 			if ((verbose>1)&&((r%1000)==999)){  putchar('.'); fflush(stdout); }
279 279
 			if (send(sock, buf, n, 0)==-1) {
280
-				fprintf(stderr, "Error: send: %s\n",  strerror(errno));
281
-				exit(1);
280
+				fprintf(stderr, "Error(%d): send: %s\n", err, strerror(errno));
281
+				err++;;
282 282
 			}
283 283
 			if (usec){
284 284
 				t--;
... ...
@@ -296,13 +305,16 @@ int main (int argc, char** argv)
296 296
 	if (tcp){
297 297
 		printf("\n%d packets sent on %d tcp connections (%d on each of them),"
298 298
 				" %d bytes each => total %d bytes\n",
299
-				count*con_no, con_no, count, n, con_no*n*count);
299
+				count*con_no-err, con_no, count, n,
300
+				(con_no*count-err)*n);
300 301
 	}else{
301 302
 		printf("\n%d packets sent, %d bytes each => total %d bytes\n",
302
-				count, n, n*count);
303
+				count-err, n, n*(count-err));
303 304
 	}
305
+	if (err) printf("%d errors\n", err);
304 306
 	exit(0);
305 307
 
306 308
 error:
309
+	fprintf(stderr, "exiting due to error (%s)\n", strerror(errno));
307 310
 	exit(-1);
308 311
 }