aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--libsylph/imap.c39
-rw-r--r--libsylph/socket.c1
-rw-r--r--libsylph/utils.c22
-rw-r--r--libsylph/utils.h18
-rw-r--r--src/logwindow.c5
6 files changed, 82 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 1d68ba96..e1b2192f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2009-09-30
+ * libsylph/utils.[ch]
+ src/logwindow.c: added log_flush() function.
+ * libsylph/imap.c: execute imap_cmd_ok() in another thread.
+
+2009-09-30
+
* libsylph/socket.[ch]
libsylph/session.c: renamed sock_connect_async() to
sock_connect_async_thread().
diff --git a/libsylph/imap.c b/libsylph/imap.c
index 3e554740..eec7a9a4 100644
--- a/libsylph/imap.c
+++ b/libsylph/imap.c
@@ -4074,8 +4074,10 @@ static gint imap_cmd_close(IMAPSession *session)
return ok;
}
-static gint imap_cmd_ok(IMAPSession *session, GPtrArray *argbuf)
+static gpointer imap_cmd_ok_func(gpointer data)
{
+ IMAPSession *session = IMAP_SESSION(data);
+ GPtrArray *argbuf = (GPtrArray *)SESSION(session)->data;
gint ok;
gchar *buf;
gint cmd_num;
@@ -4086,6 +4088,8 @@ static gint imap_cmd_ok(IMAPSession *session, GPtrArray *argbuf)
gint len;
gchar *literal;
+ g_print("enter imap_cmd_ok_func\n");
+
str = g_string_sized_new(256);
while ((ok = imap_cmd_gen_recv(session, &buf)) == IMAP_SUCCESS) {
@@ -4142,7 +4146,40 @@ static gint imap_cmd_ok(IMAPSession *session, GPtrArray *argbuf)
}
g_string_free(str, TRUE);
+#if USE_THREADS
+ SESSION(session)->io_tag = 1;
+ g_main_context_wakeup(NULL);
+#endif
+ g_print("leave imap_cmd_ok_func\n");
+ return GINT_TO_POINTER(ok);
+}
+
+static gint imap_cmd_ok(IMAPSession *session, GPtrArray *argbuf)
+{
+ gint ok;
+#if USE_THREADS
+ GThread *thread;
+
+ SESSION(session)->data = argbuf;
+ SESSION(session)->io_tag = 0;
+ thread = g_thread_create(imap_cmd_ok_func, session, TRUE, NULL);
+ if (!thread) {
+ SESSION(session)->data = NULL;
+ return IMAP_ERROR;
+ }
+ while (SESSION(session)->io_tag == 0)
+ event_loop_iterate();
+ ok = (gint)g_thread_join(thread);
+ SESSION(session)->data = NULL;
+ SESSION(session)->io_tag = 0;
+ log_flush();
+ return ok;
+#else
+ SESSION(session)->data = argbuf;
+ ok = (gint)imap_cmd_ok_func(session);
+ SESSION(session)->data = NULL;
return ok;
+#endif
}
static void imap_cmd_gen_send(IMAPSession *session, const gchar *format, ...)
diff --git a/libsylph/socket.c b/libsylph/socket.c
index d28f565e..d81236cb 100644
--- a/libsylph/socket.c
+++ b/libsylph/socket.c
@@ -1332,7 +1332,6 @@ 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");
diff --git a/libsylph/utils.c b/libsylph/utils.c
index 98371ee2..31f55a77 100644
--- a/libsylph/utils.c
+++ b/libsylph/utils.c
@@ -4318,10 +4318,15 @@ static void log_dummy_func(const gchar *str)
{
}
+static void log_dummy_flush_func(void)
+{
+}
+
static LogFunc log_print_ui_func = log_dummy_func;
static LogFunc log_message_ui_func = log_dummy_func;
static LogFunc log_warning_ui_func = log_dummy_func;
static LogFunc log_error_ui_func = log_dummy_func;
+static LogFlushFunc log_flush_ui_func = log_dummy_flush_func;
static LogFunc log_show_status_func = log_dummy_func;
@@ -4334,6 +4339,14 @@ void set_log_ui_func(LogFunc print_func, LogFunc message_func,
log_error_ui_func = error_func;
}
+void set_log_ui_func_full(LogFunc print_func, LogFunc message_func,
+ LogFunc warning_func, LogFunc error_func,
+ LogFlushFunc flush_func)
+{
+ set_log_ui_func(print_func, message_func, warning_func, error_func);
+ log_flush_ui_func = flush_func;
+}
+
void set_log_show_status_func(LogFunc status_func)
{
log_show_status_func = status_func;
@@ -4488,3 +4501,12 @@ void log_error(const gchar *format, ...)
}
S_UNLOCK(log_fp);
}
+
+void log_flush(void)
+{
+ S_LOCK(log_fp);
+ if (log_fp)
+ fflush(log_fp);
+ S_UNLOCK(log_fp);
+ log_flush_ui_func();
+}
diff --git a/libsylph/utils.h b/libsylph/utils.h
index 5f21dc63..aca5351e 100644
--- a/libsylph/utils.h
+++ b/libsylph/utils.h
@@ -1,6 +1,6 @@
/*
* LibSylph -- E-Mail client library
- * Copyright (C) 1999-2007 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
@@ -187,6 +187,7 @@ typedef void (*ProgressFunc) (gint cur,
typedef gchar * (*QueryPasswordFunc) (const gchar *server,
const gchar *user);
typedef void (*LogFunc) (const gchar *str);
+typedef void (*LogFlushFunc) (void);
/* for macro expansion */
#define Str(x) #x
@@ -517,10 +518,15 @@ void set_log_verbosity (gboolean verbose);
gboolean get_debug_mode (void);
void set_debug_mode (gboolean enable);
-void set_log_ui_func (LogFunc print_func,
- LogFunc message_func,
- LogFunc warning_func,
- LogFunc error_func);
+void set_log_ui_func (LogFunc print_func,
+ LogFunc message_func,
+ LogFunc warning_func,
+ LogFunc error_func);
+void set_log_ui_func_full (LogFunc print_func,
+ LogFunc message_func,
+ LogFunc warning_func,
+ LogFunc error_func,
+ LogFlushFunc flush_func);
void set_log_show_status_func (LogFunc status_func);
@@ -535,4 +541,6 @@ void log_message (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
void log_warning (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
void log_error (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
+void log_flush (void);
+
#endif /* __UTILS_H__ */
diff --git a/src/logwindow.c b/src/logwindow.c
index beab32a8..acf4f669 100644
--- a/src/logwindow.c
+++ b/src/logwindow.c
@@ -154,8 +154,9 @@ void log_window_init(LogWindow *logwin)
"foreground-gdk", &logwindow->error_color,
NULL);
- set_log_ui_func(log_window_print_func, log_window_message_func,
- log_window_warning_func, log_window_error_func);
+ set_log_ui_func_full(log_window_print_func, log_window_message_func,
+ log_window_warning_func, log_window_error_func,
+ log_window_flush);
}
void log_window_show(LogWindow *logwin)