stupid pthread try... i will reimplement it using purple events...
authorHarvie <tomas@mudrunka.cz>
Wed, 2 Jun 2010 16:09:45 +0000 (18:09 +0200)
committerHarvie <tomas@mudrunka.cz>
Wed, 2 Jun 2010 16:09:45 +0000 (18:09 +0200)
Makefile
answerscripts.c

index 160e3d085ecfdb418a41602598be2079c81cd509..cabb57a37be46857b6534020c0fc37e40ddb4cf2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,8 @@
 CC := gcc
 LIBTOOL := libtool
 
+#CFLAGS+=-lpthread -DPTHREAD
+
 ifeq ($(PREFIX),)
   LIB_INSTALL_DIR = $(HOME)/.purple/plugins
 else
index 7c7da4e1cf2de3c1ae8d4a9460183614c05355bf..e3f070a2ea65d98c2807324f5bc2f596f86390d5 100755 (executable)
 #define RESPONSE_LINE_LENGTH 4096
 #define HOOK_SCRIPT "answerscripts.exe"
 
+#ifdef PTHREAD
+       #include <pthread.h>
+#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
 }
 
 
This page took 0.110841 seconds and 4 git commands to generate.