From 3d6d522c1bd157b3a0d3f3c2df549ff886f03828 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 26 Nov 2009 03:01:23 +0000 Subject: sock_connect_with_timeout(): check socket with getsockopt() even if select() succeed. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2355 ee746299-78ed-0310-b773-934348b2243d --- libsylph/imap.c | 5 ++++- libsylph/socket.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'libsylph') diff --git a/libsylph/imap.c b/libsylph/imap.c index 45c345ac..201a59e0 100644 --- a/libsylph/imap.c +++ b/libsylph/imap.c @@ -549,8 +549,10 @@ static gint imap_greeting(IMAPSession *session) gchar *greeting; gint ok; - if ((ok = imap_cmd_gen_recv(session, &greeting)) != IMAP_SUCCESS) + if ((ok = imap_cmd_gen_recv(session, &greeting)) != IMAP_SUCCESS) { + log_warning("Cannot get greeting message (%d)\n", ok); return ok; + } if (greeting[0] != '*' || greeting[1] != ' ') ok = IMAP_ERROR; @@ -648,6 +650,7 @@ static Session *imap_session_new(PrefsAccount *account) session_list = g_list_append(session_list, session); if (imap_session_connect(session) != IMAP_SUCCESS) { + log_warning(_("Could not establish IMAP connection.\n")); session_destroy(SESSION(session)); return NULL; } diff --git a/libsylph/socket.c b/libsylph/socket.c index f28c8136..a3ad08b4 100644 --- a/libsylph/socket.c +++ b/libsylph/socket.c @@ -667,12 +667,25 @@ static gint sock_connect_with_timeout(gint sock, errno = ETIMEDOUT; return -1; } else { + gint val; + guint len; + if (FD_ISSET(sock, &fds)) { ret = 0; } else { debug_print("sock_connect_with_timeout: fd not set\n"); return -1; } + + len = sizeof(val); + if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &val, &len) < 0) { + perror("sock_connect_with_timeout: getsockopt"); + return -1; + } + if (val != 0) { + debug_print("sock_connect_with_timeout: getsockopt(SOL_SOCKET, SO_ERROR) returned error: %s\n", g_strerror(val)); + return -1; + } } } else { perror("sock_connect_with_timeout: connect"); -- cgit v1.2.3