diff options
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/imap.c | 12 | ||||
-rw-r--r-- | libsylph/session.c | 4 | ||||
-rw-r--r-- | libsylph/socket.c | 23 | ||||
-rw-r--r-- | libsylph/socket.h | 9 |
4 files changed, 30 insertions, 18 deletions
diff --git a/libsylph/imap.c b/libsylph/imap.c index 10f9a273..3e554740 100644 --- a/libsylph/imap.c +++ b/libsylph/imap.c @@ -2743,13 +2743,23 @@ static SockInfo *imap_open(const gchar *server, gushort port, static SockInfo *imap_open(const gchar *server, gushort port) #endif { - SockInfo *sock; + SockInfo *sock = NULL; +#if USE_THREADS + gint conn_id; + if ((conn_id = sock_connect_async_thread(server, port)) < 0 || + sock_connect_async_thread_wait(conn_id, &sock) < 0) { + log_warning(_("Can't connect to IMAP4 server: %s:%d\n"), + server, port); + return NULL; + } +#else if ((sock = sock_connect(server, port)) == NULL) { log_warning(_("Can't connect to IMAP4 server: %s:%d\n"), server, port); return NULL; } +#endif #if USE_SSL if (ssl_type == SSL_TUNNEL && !ssl_init_socket(sock)) { diff --git a/libsylph/session.c b/libsylph/session.c index 4d043063..4ebbfeef 100644 --- a/libsylph/session.c +++ b/libsylph/session.c @@ -143,13 +143,13 @@ gint session_connect(Session *session, const gchar *server, gushort port) return 0; #elif USE_THREADS - session->conn_id = sock_connect_async(server, port); + session->conn_id = sock_connect_async_thread(server, port); if (session->conn_id < 0) { g_warning("can't connect to server."); session->state = SESSION_ERROR; return -1; } - if (sock_connect_async_wait(session->conn_id, &sock) < 0) { + if (sock_connect_async_thread_wait(session->conn_id, &sock) < 0) { g_warning("can't connect to server."); session->state = SESSION_ERROR; return -1; diff --git a/libsylph/socket.c b/libsylph/socket.c index 1dc9448d..d28f565e 100644 --- a/libsylph/socket.c +++ b/libsylph/socket.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2008 Hiroyuki Yamamoto + * Copyright (C) 1999-2009 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -87,7 +87,8 @@ struct _SockConnectData { SockLookupData *lookup_data; GIOChannel *channel; guint io_tag; -#elif USE_THREADS +#endif /* G_OS_UNIX */ +#if USE_THREADS gint flag; GThread *thread; SockInfo *sock; @@ -1323,13 +1324,15 @@ static gint sock_get_address_info_async_cancel(SockLookupData *lookup_data) return 0; } -#else /* !G_OS_UNIX */ +#endif /* G_OS_UNIX */ + #if USE_THREADS static gpointer sock_connect_async_func(gpointer data) { SockConnectData *conn_data = (SockConnectData *)data; conn_data->sock = sock_connect(conn_data->hostname, conn_data->port); + g_usleep(5000000); conn_data->flag = 1; debug_print("sock_connect_async_func: connected\n"); @@ -1338,7 +1341,7 @@ static gpointer sock_connect_async_func(gpointer data) return GINT_TO_POINTER(0); } -gint sock_connect_async(const gchar *hostname, gushort port) +gint sock_connect_async_thread(const gchar *hostname, gushort port) { static gint id = 1; SockConnectData *data; @@ -1362,7 +1365,7 @@ gint sock_connect_async(const gchar *hostname, gushort port) return data->id; } -gint sock_connect_async_wait(gint id, SockInfo **sock) +gint sock_connect_async_thread_wait(gint id, SockInfo **sock) { SockConnectData *conn_data = NULL; GList *cur; @@ -1375,17 +1378,17 @@ gint sock_connect_async_wait(gint id, SockInfo **sock) } if (!conn_data) { - g_warning("sock_connect_async_wait: id %d not found.", id); + g_warning("sock_connect_async_thread_wait: id %d not found.", id); return -1; } - debug_print("sock_connect_async_wait: waiting thread\n"); + debug_print("sock_connect_async_thread_wait: waiting thread\n"); while (conn_data->flag == 0) event_loop_iterate(); - debug_print("sock_connect_async_wait: flagged\n"); + debug_print("sock_connect_async_thread_wait: flagged\n"); g_thread_join(conn_data->thread); - debug_print("sock_connect_async_wait: thread exited\n"); + debug_print("sock_connect_async_thread_wait: thread exited\n"); *sock = conn_data->sock; @@ -1397,8 +1400,6 @@ gint sock_connect_async_wait(gint id, SockInfo **sock) return 0; } #endif /* USE_THREADS */ -#endif /* G_OS_UNIX */ - gint sock_printf(SockInfo *sock, const gchar *format, ...) { diff --git a/libsylph/socket.h b/libsylph/socket.h index 37d1e397..64d2d6a1 100644 --- a/libsylph/socket.h +++ b/libsylph/socket.h @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2008 Hiroyuki Yamamoto + * Copyright (C) 1999-2009 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -103,9 +103,10 @@ SockInfo *sock_connect (const gchar *hostname, gushort port); gint sock_connect_async (const gchar *hostname, gushort port, SockConnectFunc func, gpointer data); gint sock_connect_async_cancel (gint id); -#elif USE_THREADS -gint sock_connect_async (const gchar *hostname, gushort port); -gint sock_connect_async_wait (gint id, SockInfo **sock); +#endif +#if USE_THREADS +gint sock_connect_async_thread (const gchar *hostname, gushort port); +gint sock_connect_async_thread_wait (gint id, SockInfo **sock); #endif /* Basic I/O functions */ |