im.pidgin.pidgin: 8548e491a5b470d5665cb1cf87a7b0caaa3c87a5
markdoliner at pidgin.im
markdoliner at pidgin.im
Sun Oct 14 06:00:34 EDT 2007
-----------------------------------------------------------------
Revision: 8548e491a5b470d5665cb1cf87a7b0caaa3c87a5
Ancestor: 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Author: markdoliner at pidgin.im
Date: 2007-10-14T09:57:32
Branch: im.pidgin.pidgin
Modified files:
libpurple/network.c libpurple/protocols/bonjour/jabber.c
libpurple/protocols/msn/directconn.c
libpurple/protocols/msn/servconn.c
libpurple/protocols/oscar/peer.c
libpurple/protocols/qq/qq_proxy.c
libpurple/protocols/qq/udp_proxy_s5.c libpurple/proxy.c
libpurple/win32/libc_interface.c
libpurple/win32/libc_interface.h
libpurple/win32/libc_internal.h
ChangeLog:
Fix all our calls to fcntl(listenfd, F_SETFL, O_NONBLOCK);
fcntl() with F_SETFL overwrites the old flags with the new ones, so
you should call fcntl() with F_GETFL, then OR that value with
O_NONBLOCK before setting the flags. We've been doing this
wrong for a long time and it hasn't seemed to hurt anything,
but I thought it would be good to fix it.
-------------- next part --------------
============================================================
--- libpurple/network.c 9114e00fc20986c4f4e604f4f65ed8b34793268f
+++ libpurple/network.c b4244caf2c0eb63fedac087389113c7f48d7aec6
@@ -263,6 +263,7 @@ purple_network_do_listen(unsigned short
purple_network_do_listen(unsigned short port, int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data)
{
int listenfd = -1;
+ int flags;
const int on = 1;
PurpleNetworkListenData *listen_data;
unsigned short actual_port;
@@ -340,7 +341,8 @@ purple_network_do_listen(unsigned short
close(listenfd);
return NULL;
}
- fcntl(listenfd, F_SETFL, O_NONBLOCK);
+ flags = fcntl(listenfd, F_GETFL);
+ fcntl(listenfd, F_SETFL, flags | O_NONBLOCK);
actual_port = purple_network_get_port_from_fd(listenfd);
============================================================
--- libpurple/protocols/bonjour/jabber.c ca14bd20d800332bae87d265e84c2af34ea6bb4e
+++ libpurple/protocols/bonjour/jabber.c 2fc323fdb93593509842bb2e199726742389f0b7
@@ -521,6 +521,7 @@ _server_socket_handler(gpointer data, in
struct sockaddr_in their_addr; /* connector's address information */
socklen_t sin_size = sizeof(struct sockaddr);
int client_socket;
+ int flags;
BonjourBuddy *bb;
char *address_text = NULL;
PurpleBuddyList *bl = purple_get_blist();
@@ -533,7 +534,8 @@ _server_socket_handler(gpointer data, in
if ((client_socket = accept(server_socket, (struct sockaddr *)&their_addr, &sin_size)) == -1)
return;
- fcntl(client_socket, F_SETFL, O_NONBLOCK);
+ flags = fcntl(client_socket, F_GETFL);
+ fcntl(client_socket, F_SETFL, flags | O_NONBLOCK);
/* Look for the buddy that has opened the conversation and fill information */
address_text = inet_ntoa(their_addr.sin_addr);
============================================================
--- libpurple/protocols/msn/directconn.c df8634bd0fd008faf6673faaf58259d90b618cf8
+++ libpurple/protocols/msn/directconn.c 9434160166bb8a8f10d1f283c298f951ae92ee39
@@ -80,6 +80,7 @@ create_listener(int port)
create_listener(int port)
{
int fd;
+ int flags;
const int on = 1;
#if 0
@@ -155,7 +156,8 @@ create_listener(int port)
return -1;
}
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ flags = fcntl(fd, F_GETFL);
+ fcntl(fd, F_SETFL, flags | O_NONBLOCK);
return fd;
}
============================================================
--- libpurple/protocols/msn/servconn.c 9f3303c3f1925736e425af99c93cf6fd22155955
+++ libpurple/protocols/msn/servconn.c 71ff602a8a0d95e0f0f24e6414e4bc5279964ef9
@@ -480,6 +480,7 @@ create_listener(int port)
create_listener(int port)
{
int fd;
+ int flags;
const int on = 1;
#if 0
@@ -555,7 +556,8 @@ create_listener(int port)
return -1;
}
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ flags = fcntl(fd, F_GETFL);
+ fcntl(fd, F_SETFL, flags | O_NONBLOCK);
return fd;
}
============================================================
--- libpurple/protocols/oscar/peer.c 41adee466bbbc9882b7592a9296b903f70e136e4
+++ libpurple/protocols/oscar/peer.c dc62688befb4ff27094c83d1a4bdb2ed6ab48777
@@ -607,6 +607,7 @@ peer_connection_listen_cb(gpointer data,
PurpleConnection *gc;
struct sockaddr addr;
socklen_t addrlen = sizeof(addr);
+ int flags;
conn = data;
od = conn->od;
@@ -633,7 +634,8 @@ peer_connection_listen_cb(gpointer data,
return;
}
- fcntl(conn->fd, F_SETFL, O_NONBLOCK);
+ flags = fcntl(conn->fd, F_GETFL);
+ fcntl(conn->fd, F_SETFL, flags | O_NONBLOCK);
purple_input_remove(conn->watcher_incoming);
peer_connection_finalize_connection(conn);
============================================================
--- libpurple/protocols/qq/qq_proxy.c 9859ce4f1dcb239747e8051f71a059be48754c59
+++ libpurple/protocols/qq/qq_proxy.c a5217211e05d16b748cc9c6245817683f2dc67b3
@@ -258,6 +258,7 @@ static gint _qq_proxy_none(struct PHB *p
static gint _qq_proxy_none(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen)
{
gint fd = -1;
+ int flags;
purple_debug(PURPLE_DEBUG_INFO, "QQ", "Using UDP without proxy\n");
fd = socket(PF_INET, SOCK_DGRAM, 0);
@@ -269,7 +270,8 @@ static gint _qq_proxy_none(struct PHB *p
}
/* we use non-blocking mode to speed up connection */
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ flags = fcntl(fd, F_GETFL);
+ fcntl(fd, F_SETFL, flags | O_NONBLOCK);
/* From Unix-socket-FAQ: http://www.faqs.org/faqs/unix-faq/socket/
*
@@ -301,7 +303,8 @@ static gint _qq_proxy_none(struct PHB *p
} /* if errno */
} else { /* connect returns 0 */
purple_debug(PURPLE_DEBUG_INFO, "QQ", "Connected.\n");
- fcntl(fd, F_SETFL, 0);
+ flags = fcntl(fd, F_GETFL);
+ fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
phb->func(phb->data, fd, NULL);
}
============================================================
--- libpurple/protocols/qq/udp_proxy_s5.c 764502ce91dd93c93cbea1d83c9e32b883452abb
+++ libpurple/protocols/qq/udp_proxy_s5.c 657927ba06ed576a4382bfaea0d6d121ef865fc5
@@ -33,6 +33,7 @@ static void _qq_s5_canread_again(gpointe
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 @@ static void _qq_s5_canread_again(gpointe
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 @@ static void _qq_s5_sendconnect(gpointer
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 @@ static void _qq_s5_sendconnect(gpointer
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 @@ static void _qq_s5_canwrite(gpointer dat
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 @@ static void _qq_s5_canwrite(gpointer dat
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, st
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 @@ gint qq_proxy_socks5(struct PHB *phb, st
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 @@ gint qq_proxy_socks5(struct PHB *phb, st
}
} 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);
}
============================================================
--- libpurple/proxy.c 49258c4d7facfe350838599f27bde8b25aa470a9
+++ libpurple/proxy.c 3ae21261d2562cb9c57319ec0e756c49e5344b9a
@@ -449,6 +449,8 @@ proxy_connect_none(PurpleProxyConnectDat
static void
proxy_connect_none(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
{
+ int flags;
+
purple_debug_info("proxy", "Connecting to %s:%d with no proxy\n",
connect_data->host, connect_data->port);
@@ -460,7 +462,8 @@ proxy_connect_none(PurpleProxyConnectDat
return;
}
- fcntl(connect_data->fd, F_SETFL, O_NONBLOCK);
+ flags = fcntl(connect_data->fd, F_GETFL);
+ fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
#ifndef _WIN32
fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
#endif
@@ -881,6 +884,8 @@ proxy_connect_http(PurpleProxyConnectDat
static void
proxy_connect_http(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
{
+ int flags;
+
purple_debug_info("proxy",
"Connecting to %s:%d via %s:%d using HTTP\n",
connect_data->host, connect_data->port,
@@ -895,14 +900,16 @@ proxy_connect_http(PurpleProxyConnectDat
return;
}
- fcntl(connect_data->fd, F_SETFL, O_NONBLOCK);
+ flags = fcntl(connect_data->fd, F_GETFL);
+ fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
#ifndef _WIN32
fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
#endif
if (connect(connect_data->fd, addr, addrlen) != 0)
{
- if ((errno == EINPROGRESS) || (errno == EINTR)) {
+ if ((errno == EINPROGRESS) || (errno == EINTR))
+ {
purple_debug_info("proxy", "Connection in progress\n");
if (connect_data->port != 80)
@@ -1036,6 +1043,8 @@ proxy_connect_socks4(PurpleProxyConnectD
static void
proxy_connect_socks4(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
{
+ int flags;
+
purple_debug_info("proxy",
"Connecting to %s:%d via %s:%d using SOCKS4\n",
connect_data->host, connect_data->port,
@@ -1050,7 +1059,8 @@ proxy_connect_socks4(PurpleProxyConnectD
return;
}
- fcntl(connect_data->fd, F_SETFL, O_NONBLOCK);
+ flags = fcntl(connect_data->fd, F_GETFL);
+ fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
#ifndef _WIN32
fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
#endif
@@ -1604,6 +1614,8 @@ proxy_connect_socks5(PurpleProxyConnectD
static void
proxy_connect_socks5(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
{
+ int flags;
+
purple_debug_info("proxy",
"Connecting to %s:%d via %s:%d using SOCKS5\n",
connect_data->host, connect_data->port,
@@ -1618,7 +1630,8 @@ proxy_connect_socks5(PurpleProxyConnectD
return;
}
- fcntl(connect_data->fd, F_SETFL, O_NONBLOCK);
+ flags = fcntl(connect_data->fd, F_GETFL);
+ fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK);
#ifndef _WIN32
fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
#endif
============================================================
--- libpurple/win32/libc_interface.c 56993eeed66ae09248b7601a4131e65205d65a3d
+++ libpurple/win32/libc_interface.c 88838e5ca5bad005e691b713d22936eddc924a10
@@ -138,12 +138,22 @@ int wpurple_sendto(int socket, const voi
/* fcntl.h */
/* This is not a full implementation of fcntl. Update as needed.. */
-int wpurple_fcntl(int socket, int command, int val) {
+int wpurple_fcntl(int socket, int command, ...) {
+
switch( command ) {
+ case F_GETFL:
+ return 0;
+
case F_SETFL:
{
+ va_list args;
+ int val;
int ret=0;
+ va_start(args, command);
+ val = va_arg(args, int);
+ va_end(args);
+
switch( val ) {
case O_NONBLOCK:
{
@@ -152,7 +162,7 @@ int wpurple_fcntl(int socket, int comman
break;
}
case 0:
- {
+ {
u_long imode=0;
ret = ioctlsocket(socket, FIONBIO, &imode);
break;
============================================================
--- libpurple/win32/libc_interface.h 4fba0fad30d958380fd050130b6163c40abb3c41
+++ libpurple/win32/libc_interface.h 5841a6d5078b45b3dac291bfa1517144d875c1d1
@@ -75,8 +75,8 @@ wpurple_ioctl( fd, command, val )
wpurple_ioctl( fd, command, val )
/* fcntl.h */
-#define fcntl( fd, command, val ) \
-wpurple_fcntl( fd, command, val )
+#define fcntl( fd, command, ... ) \
+wpurple_fcntl( fd, command, ##__VA_ARGS__ )
/* arpa/inet.h */
#define inet_aton( name, addr ) \
============================================================
--- libpurple/win32/libc_internal.h 31083fa76ac440830628c03175f1fafc26414180
+++ libpurple/win32/libc_internal.h d769d5100b0f14e8cf8339560e8d66a15737476d
@@ -49,9 +49,10 @@ char* wpurple_strerror( int errornum );
char* wpurple_strerror( int errornum );
/* fcntl.h */
-int wpurple_fcntl(int socket, int command, int val);
-#define F_SETFL 1
-#define O_NONBLOCK 1
+int wpurple_fcntl(int socket, int command, ...);
+#define F_GETFL 3
+#define F_SETFL 4
+#define O_NONBLOCK 04000
/* sys/ioctl.h */
#define SIOCGIFCONF 0x8912 /* get iface list */
More information about the Commits
mailing list