aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2009-10-01 01:58:37 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2009-10-01 01:58:37 +0000
commitb6a7ac64157874fbbf65211aec60850a22929f4f (patch)
treeab33b38c7bb76c27b4c851735fcf0a6b71c78241
parent8ec24a7f0d2ee2522e8c1b542e7d5b1d75da0f70 (diff)
libsylph/imap.c: refactored.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2264 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog4
-rw-r--r--libsylph/imap.c70
2 files changed, 41 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index bf2b521e..9a611bef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-10-01
+
+ * libsylph/imap.c: refactored.
+
2009-09-30
* libsylph/imap.c: execute imap_cmd_fetch() in another thread.
diff --git a/libsylph/imap.c b/libsylph/imap.c
index c19076cb..34d79a0f 100644
--- a/libsylph/imap.c
+++ b/libsylph/imap.c
@@ -391,6 +391,12 @@ static GHashTable *imap_get_uid_table (GArray *array);
static gboolean imap_rename_folder_func (GNode *node,
gpointer data);
+#if USE_THREADS
+static gint imap_thread_run (IMAPSession *session,
+ GThreadFunc func,
+ gpointer data);
+#endif
+
static FolderClass imap_class =
{
F_IMAP,
@@ -3935,9 +3941,6 @@ static gint imap_cmd_fetch(IMAPSession *session, guint32 uid,
{
gint ok;
IMAPCmdFetchData fetch_data = {uid, filename};
-#if USE_THREADS
- GThread *thread;
-#endif
g_return_val_if_fail(filename != NULL, IMAP_ERROR);
@@ -3945,19 +3948,7 @@ static gint imap_cmd_fetch(IMAPSession *session, guint32 uid,
imap_cmd_gen_send(session, "UID FETCH %d BODY.PEEK[]", uid);
#if USE_THREADS
- SESSION(session)->data = &fetch_data;
- SESSION(session)->io_tag = 0;
- thread = g_thread_create(imap_cmd_fetch_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();
+ ok = imap_thread_run(session, imap_cmd_fetch_func, &fetch_data);
#else
SESSION(session)->data = &fetch_data;
ok = (gint)imap_cmd_fetch_func(session);
@@ -4219,23 +4210,7 @@ static gpointer imap_cmd_ok_func(gpointer data)
static gint imap_cmd_ok(IMAPSession *session, GPtrArray *argbuf)
{
#if USE_THREADS
- GThread *thread;
- gint ok;
-
- 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;
+ return imap_thread_run(session, imap_cmd_ok_func, argbuf);
#else
return imap_cmd_ok_real(session, argbuf);
#endif
@@ -4718,3 +4693,32 @@ static gboolean imap_rename_folder_func(GNode *node, gpointer data)
return FALSE;
}
+
+#if USE_THREADS
+static gint imap_thread_run(IMAPSession *session, GThreadFunc func,
+ gpointer data)
+{
+ GThread *thread;
+ gpointer save_data;
+ gint ret;
+
+ save_data = SESSION(session)->data;
+ SESSION(session)->data = data;
+ SESSION(session)->io_tag = 0;
+
+ thread = g_thread_create(func, session, TRUE, NULL);
+ if (!thread) {
+ SESSION(session)->data = save_data;
+ return IMAP_ERROR;
+ }
+ while (SESSION(session)->io_tag == 0)
+ event_loop_iterate();
+ ret = (gint)g_thread_join(thread);
+
+ SESSION(session)->data = save_data;
+ SESSION(session)->io_tag = 0;
+ log_flush();
+
+ return ret;
+}
+#endif