From d43aa2e692e5689cbd54a4398df51e1f51db3cb9 Mon Sep 17 00:00:00 2001 From: hiro Date: Tue, 14 Feb 2006 08:39:10 +0000 Subject: win32: avoid blocking when reading from socket. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1001 ee746299-78ed-0310-b773-934348b2243d --- libsylph/session.c | 8 +++++++- libsylph/socket.c | 21 +++++++++++++++++++++ libsylph/socket.h | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'libsylph') diff --git a/libsylph/session.c b/libsylph/session.c index 7a526765..8e7cd835 100644 --- a/libsylph/session.c +++ b/libsylph/session.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2005 Hiroyuki Yamamoto + * Copyright (C) 1999-2006 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -512,6 +512,8 @@ static gboolean session_read_msg_cb(SockInfo *source, GIOCondition condition, if (session->read_buf_len == 0) { gint read_len; + if (!sock_has_read_data(session->sock)) + return TRUE; read_len = sock_read(session->sock, session->read_buf, SESSION_BUFFSIZE - 1); @@ -598,6 +600,8 @@ static gboolean session_read_data_cb(SockInfo *source, GIOCondition condition, if (session->read_buf_len == 0) { gint read_len; + if (!sock_has_read_data(session->sock)) + return TRUE; read_len = sock_read(session->sock, session->read_buf, SESSION_BUFFSIZE); @@ -709,6 +713,8 @@ static gboolean session_read_data_as_file_cb(SockInfo *source, session_set_timeout(session, session->timeout_interval); if (session->read_buf_len == 0) { + if (!sock_has_read_data(session->sock)) + return TRUE; read_len = sock_read(session->sock, session->read_buf_p, READ_BUF_LEFT()); diff --git a/libsylph/socket.c b/libsylph/socket.c index 954c33f0..7ddde9e5 100644 --- a/libsylph/socket.c +++ b/libsylph/socket.c @@ -398,6 +398,27 @@ gboolean sock_is_nonblocking_mode(SockInfo *sock) return is_nonblocking_mode(sock->sock); } +gboolean sock_has_read_data(SockInfo *sock) +{ +#ifdef G_OS_WIN32 + gulong val; + +#if USE_SSL + if (sock->ssl) + return TRUE; +#endif + if (ioctlsocket(sock->sock, FIONREAD, &val) < 0) + return TRUE; + + if (val == 0) + return FALSE; + else + return TRUE; +#else + return TRUE; +#endif +} + static gboolean sock_prepare(GSource *source, gint *timeout) { diff --git a/libsylph/socket.h b/libsylph/socket.h index 5f627c67..c3b773ef 100644 --- a/libsylph/socket.h +++ b/libsylph/socket.h @@ -75,6 +75,8 @@ gint sock_set_io_timeout (guint sec); gint sock_set_nonblocking_mode (SockInfo *sock, gboolean nonblock); gboolean sock_is_nonblocking_mode (SockInfo *sock); +gboolean sock_has_read_data (SockInfo *sock); + guint sock_add_watch (SockInfo *sock, GIOCondition condition, SockFunc func, gpointer data); -- cgit v1.2.3