From d852a69454e41e5c4d354b509da04c7dfd5e80ad Mon Sep 17 00:00:00 2001 From: Harvie Date: Wed, 2 Jun 2010 18:09:45 +0200 Subject: [PATCH] stupid pthread try... i will reimplement it using purple events... --- Makefile | 2 ++ answerscripts.c | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 160e3d0..cabb57a 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,8 @@ CC := gcc LIBTOOL := libtool +#CFLAGS+=-lpthread -DPTHREAD + ifeq ($(PREFIX),) LIB_INSTALL_DIR = $(HOME)/.purple/plugins else diff --git a/answerscripts.c b/answerscripts.c index 7c7da4e..e3f070a 100755 --- a/answerscripts.c +++ b/answerscripts.c @@ -19,11 +19,24 @@ #define RESPONSE_LINE_LENGTH 4096 #define HOOK_SCRIPT "answerscripts.exe" +#ifdef PTHREAD + #include +#endif + char *buff = NULL; char *hook_script = NULL; char response[RESPONSE_LINE_LENGTH+1]; int i; +void *answerscripts_process_message(void *conv) { + FILE* pipe = popen(hook_script, "r"); //TODO: process scripts and send response asynchronously + while (pipe && fgets(response, RESPONSE_LINE_LENGTH, pipe)) { + for(i=0;response[i];i++) if(response[i]=='\n') response[i]=0; + purple_conv_im_send(purple_conversation_get_im_data((PurpleConversation *)conv), response); + } + pclose(pipe); +} + static void received_im_msg_cb(PurpleAccount * account, char *who, char *buffer, PurpleConversation * conv, PurpleMessageFlags flags, @@ -38,12 +51,14 @@ void *data) { setenv("PURPLE_FROM", who, 1); setenv("PURPLE_MSG", buff, 1); - FILE* pipe = popen(hook_script, "r"); //TODO: process scripts and send response asynchronously - while (pipe && fgets(response, RESPONSE_LINE_LENGTH, pipe)) { - for(i=0;response[i];i++) if(response[i]=='\n') response[i]=0; - purple_conv_im_send(purple_conversation_get_im_data(conv), response); - } - pclose(pipe); + #ifndef PTHREAD + answerscripts_process_message((void *)conv); + #else + pthread_t t; + puts("new thread..."); + pthread_create(&t, NULL, answerscripts_process_message, (void *)conv); + puts("new thread created!"); + #endif } -- 2.30.2