diff libpurple/protocols/qq/udp_proxy_s5.c @ 20347:04fe5601fedb

applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3 through 8548e491a5b470d5665cb1cf87a7b0caaa3c87a5
author Luke Schierer <lschiere@pidgin.im>
date Sun, 21 Oct 2007 04:46:33 +0000
parents 7a478b174ac9
children 35b4f1dc4c8d
line wrap: on
line diff
--- a/libpurple/protocols/qq/udp_proxy_s5.c	Sun Oct 21 04:44:56 2007 +0000
+++ b/libpurple/protocols/qq/udp_proxy_s5.c	Sun Oct 21 04:46:33 2007 +0000
@@ -33,6 +33,7 @@
 	struct sockaddr_in sin;
 	int len, error;
 	socklen_t errlen;
+	int flags;
 
 	purple_input_remove(phb->inpa);
 	purple_debug(PURPLE_DEBUG_INFO, "socks5 proxy", "Able to read again.\n");
@@ -89,7 +90,8 @@
 		close(phb->udpsock);
 		return;
 	}
-	fcntl(phb->udpsock, F_SETFL, 0);
+	flags = fcntl(phb->udpsock, F_GETFL);
+	fcntl(phb->udpsock, F_SETFL, flags & ~O_NONBLOCK);
 
 	if (phb->account == NULL || purple_account_get_connection(phb->account) != NULL) {
 		phb->func(phb->data, phb->udpsock, NULL);
@@ -106,6 +108,7 @@
 	struct sockaddr_in sin, ctlsin;
 	int port; 
 	socklen_t ctllen;
+	int flags;
 
 	purple_debug(PURPLE_DEBUG_INFO, "s5_sendconnect", "remote host is %s:%d\n", phb->host, phb->port);
 
@@ -133,7 +136,8 @@
 		return;
 	}
 
-	fcntl(phb->udpsock, F_SETFL, O_NONBLOCK);
+	flags = fcntl(phb->udpsock, F_GETFL);
+	fcntl(phb->udpsock, F_SETFL, flags | O_NONBLOCK);
 
 	port = g_ntohs(ctlsin.sin_port) + 1;
 	while (1) {
@@ -287,6 +291,7 @@
 	struct PHB *phb = data;
 	socklen_t len;
 	int error = ETIMEDOUT;
+	int flags;
 
 	purple_debug(PURPLE_DEBUG_INFO, "socks5 proxy", "Connected.\n");
 
@@ -306,7 +311,8 @@
 		g_free(phb);
 		return;
 	}
-	fcntl(source, F_SETFL, 0);
+	flags = fcntl(source, F_GETFL);
+	fcntl(source, F_SETFL, flags & ~O_NONBLOCK);
 
 	i = 0;
 	buf[0] = 0x05;		/* SOCKS version 5 */
@@ -343,6 +349,8 @@
 gint qq_proxy_socks5(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen)
 {
 	gint fd;
+	int flags;
+
 	purple_debug(PURPLE_DEBUG_INFO, "QQ",
 		   "Connecting to %s:%d via %s:%d using SOCKS5\n",
 		   phb->host, phb->port, purple_proxy_info_get_host(phb->gpi), purple_proxy_info_get_port(phb->gpi));
@@ -352,7 +360,8 @@
 
 	purple_debug(PURPLE_DEBUG_INFO, "QQ", "proxy_sock5 return fd=%d\n", fd);
 
-	fcntl(fd, F_SETFL, O_NONBLOCK);
+	flags = fcntl(fd, F_GETFL);
+	fcntl(fd, F_SETFL, flags | O_NONBLOCK);
 	if (connect(fd, addr, addrlen) < 0) {
 		if ((errno == EINPROGRESS) || (errno == EINTR)) {
 			purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Connect in asynchronous mode.\n");
@@ -363,7 +372,8 @@
 		}
 	} else {
 		purple_debug(PURPLE_DEBUG_MISC, "QQ", "Connect in blocking mode.\n");
-		fcntl(fd, F_SETFL, 0);
+		flags = fcntl(fd, F_GETFL);
+		fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
 		_qq_s5_canwrite(phb, fd, PURPLE_INPUT_WRITE);
 	}