diff options
author | Evan Schoenberg <evands@pidgin.im> | 2007-02-23 05:17:20 +0000 |
---|---|---|
committer | Evan Schoenberg <evands@pidgin.im> | 2007-02-23 05:17:20 +0000 |
commit | 06256b5996190daecd799cb7aa97c667520bdd7f (patch) | |
tree | 86c752fbf6cd0b7d3c541033b4a6b995eb112ac1 /libpurple/proxy.c | |
parent | 11d2691d30e3ee88cf2fa852ad89f5cac7078d92 (diff) | |
download | pidgin-06256b5996190daecd799cb7aa97c667520bdd7f.tar.gz |
Added a new GaimEventLoopUiOps item, input_get_error(). This function allows the UI to return the current error status on a socket/input. If the UI does not implement it (as Pidgin and gntgaim do not, since glib's handling of sockets is sane), it is just a wrapper around getsockopt(). Implemented or not, its return values should match those of getsockopt() with a level of SOL_SOCKET and an option of SO_ERROR. For curious souls, Adium will be using this to provide a working version of getsockopt(); the CoreFoundation CFSocket class which is used for socket read/write calls getsockopt() with SO_ERROR itself, thereby clearing the error flag [as documented in getsockopt()'s behavior], so depending upon it for determining if an error occurred leads to significant misbehavior.
Diffstat (limited to 'libpurple/proxy.c')
-rw-r--r-- | libpurple/proxy.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/libpurple/proxy.c b/libpurple/proxy.c index f4eeac9dba..1010781569 100644 --- a/libpurple/proxy.c +++ b/libpurple/proxy.c @@ -386,14 +386,14 @@ static void socket_ready_cb(gpointer data, gint source, GaimInputCondition cond) { GaimProxyConnectData *connect_data = data; - socklen_t len; int error = 0; int ret; - gaim_debug_info("proxy", "Connected.\n"); + gaim_debug_info("proxy", "Connected to %s:%d.\n", + connect_data->host, connect_data->port); /* - * getsockopt after a non-blocking connect returns -1 if something is + * gaim_input_get_error after a non-blocking connect returns -1 if something is * really messed up (bad descriptor, usually). Otherwise, it returns 0 and * error holds what connect would have returned if it blocked until now. * Thus, error == 0 is success, error == EINPROGRESS means "try again", @@ -403,17 +403,21 @@ socket_ready_cb(gpointer data, gint source, GaimInputCondition cond) * be overly optimistic sometimes. select is just a hint that you might be * able to do something.) */ - len = sizeof(error); - ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len); + ret = gaim_input_get_error(connect_data->fd, &error); - if (ret == 0 && error == EINPROGRESS) + if (ret == 0 && error == EINPROGRESS) { /* No worries - we'll be called again later */ /* TODO: Does this ever happen? */ + gaim_debug_info("proxy", "(ret == 0 && error == EINPROGRESS)"); return; + } if (ret != 0 || error != 0) { if (ret != 0) error = errno; + gaim_debug_info("proxy", "Error connecting to %s:%d (%s).\n", + connect_data->host, connect_data->port, strerror(error)); + gaim_proxy_connect_data_disconnect(connect_data, strerror(error)); return; } @@ -466,14 +470,12 @@ proxy_connect_none(GaimProxyConnectData *connect_data, struct sockaddr *addr, so /* * The connection happened IMMEDIATELY... strange, but whatever. */ - socklen_t len; int error = ETIMEDOUT; int ret; gaim_debug_info("proxy", "Connected immediately.\n"); - len = sizeof(error); - ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len); + ret = gaim_input_get_error(connect_data->fd, &error); if ((ret != 0) || (error != 0)) { if (ret != 0) @@ -783,22 +785,21 @@ http_canwrite(gpointer data, gint source, GaimInputCondition cond) { GString *request; GaimProxyConnectData *connect_data; - socklen_t len; int error = ETIMEDOUT; int ret; - gaim_debug_info("proxy", "Connected.\n"); - connect_data = data; + gaim_debug_info("proxy", "Connected to %s:%d.\n", + connect_data->host, connect_data->port); + if (connect_data->inpa > 0) { gaim_input_remove(connect_data->inpa); connect_data->inpa = 0; } - len = sizeof(error); - ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len); + ret = gaim_input_get_error(connect_data->fd, &error); if ((ret != 0) || (error != 0)) { if (ret != 0) @@ -947,7 +948,6 @@ s4_canwrite(gpointer data, gint source, GaimInputCondition cond) unsigned char packet[9]; struct hostent *hp; GaimProxyConnectData *connect_data = data; - socklen_t len; int error = ETIMEDOUT; int ret; @@ -959,8 +959,7 @@ s4_canwrite(gpointer data, gint source, GaimInputCondition cond) connect_data->inpa = 0; } - len = sizeof(error); - ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len); + ret = gaim_input_get_error(connect_data->fd, &error); if ((ret != 0) || (error != 0)) { if (ret != 0) @@ -1515,7 +1514,6 @@ s5_canwrite(gpointer data, gint source, GaimInputCondition cond) unsigned char buf[5]; int i; GaimProxyConnectData *connect_data = data; - socklen_t len; int error = ETIMEDOUT; int ret; @@ -1527,8 +1525,7 @@ s5_canwrite(gpointer data, gint source, GaimInputCondition cond) connect_data->inpa = 0; } - len = sizeof(error); - ret = getsockopt(connect_data->fd, SOL_SOCKET, SO_ERROR, &error, &len); + ret = gaim_input_get_error(connect_data->fd, &error); if ((ret != 0) || (error != 0)) { if (ret != 0) |