changeset 409:82064124324d

Fix a SIGPIPE issue when connecting to the server This change fixes a SIGPIPE when cw_nb_connect() is called too fast after make_nb_netsocket(). In this case getsockopt() reports a wrong value (no error) and the first jab_send_raw() in jconn.c gets a SIGPIPE. The delay in jabglue.c can then be removed.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 27 Aug 2005 22:20:03 +0200
parents 73433860665c
children d39ba53fc38e
files mcabber/connwrap/connwrap.c mcabber/src/jabglue.c
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/connwrap/connwrap.c	Sat Aug 27 18:59:48 2005 +0200
+++ b/mcabber/connwrap/connwrap.c	Sat Aug 27 22:20:03 2005 +0200
@@ -325,6 +325,17 @@
 	rc = connect(sockfd, serv_addr, addrlen);
     else{ /* check if the socket is connected correctly */
 	int optlen = sizeof(int), optval;
+	fd_set fds;
+	struct timeval tv;
+
+	FD_ZERO(&fds);
+	FD_SET(sockfd, &fds);
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 10000;
+
+	if (select(sockfd+1, 0, &fds, 0, &tv) < 1)
+	    return -1;
 	if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval, (socklen_t*)&optlen) || optval)
 	    return -1;
 	*state = 0;
--- a/mcabber/src/jabglue.c	Sat Aug 27 18:59:48 2005 +0200
+++ b/mcabber/src/jabglue.c	Sat Aug 27 22:20:03 2005 +0200
@@ -196,7 +196,6 @@
   }
 
   if (jc && jc->state == JCONN_STATE_CONNECTING) {
-    usleep(150000);
     jab_start(jc);
     return;
   }