summaryrefslogtreecommitdiff
path: root/libvxi11client/perlbits/perlglue.c
diff options
context:
space:
mode:
Diffstat (limited to 'libvxi11client/perlbits/perlglue.c')
-rw-r--r--libvxi11client/perlbits/perlglue.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/libvxi11client/perlbits/perlglue.c b/libvxi11client/perlbits/perlglue.c
index 551136e..3225ca0 100644
--- a/libvxi11client/perlbits/perlglue.c
+++ b/libvxi11client/perlbits/perlglue.c
@@ -6,13 +6,28 @@
static GAsyncQueue* interruptqueue;
typedef struct {
- GTimeVal when;
char* handle;
} Event;
+static Event* lastevent = NULL;
+
+static void freeevent(Event* event) {
+ g_free(event->handle);
+ g_free(event);
+}
+
+static void freelast() {
+ if (lastevent != NULL) {
+ freeevent(lastevent);
+ }
+ lastevent = NULL;
+}
+
static void interruptcallback(char* handle) {
Event* event = g_malloc(sizeof(Event));
- g_get_current_time(&event->when);
+ int handlelen = strlen(handle);
+ event->handle = g_malloc(handlelen + 1);
+ strcpy(event->handle, handle);
g_async_queue_push(interruptqueue, event);
}
@@ -33,19 +48,25 @@ int glue_start_interrupt_server() {
int glue_stop_interrupt_server() {
int ret = vxi11_stop_interrupt_server();
+ Event* event = NULL;
+ // clear everything that is left over
+ while ((event = (Event*) g_async_queue_try_pop(interruptqueue)) != NULL) {
+ freeevent(event);
+ }
+ freelast();
g_free(interruptqueue);
return ret;
}
-int glue_wait_for_interrupt() {
+char* glue_wait_for_interrupt() {
GTimeVal timeout;
g_get_current_time(&timeout);
g_time_val_add(&timeout, 2500);
- gpointer event = g_async_queue_timed_pop(interruptqueue, &timeout);
- if (event != NULL) {
- g_free(event);
- return 1;
+ freelast();
+ lastevent = (Event*) g_async_queue_timed_pop(interruptqueue, &timeout);
+ if (lastevent != NULL) {
+ return lastevent->handle;
}
else
- return 0;
+ return NULL;
}