diff options
author | daniel <danieruru@gmail.com> | 2013-01-30 13:16:17 +0900 |
---|---|---|
committer | daniel <danieruru@gmail.com> | 2013-01-30 13:16:17 +0900 |
commit | 54394d26b686702091e584d524ad77bfbb469fd4 (patch) | |
tree | 506f3f5bcc06f0c00625802904e2168903cb01fd | |
parent | af2ad8e37d852f66d499125e75fca92762463678 (diff) |
Data lengths sent to the server shouldn't include the terminator.
Fix up how the handle gets copied out into perl
-rw-r--r-- | libvxi11client/libvxi11client.c | 8 | ||||
-rw-r--r-- | libvxi11client/perlbits/perlglue.c | 13 | ||||
-rw-r--r-- | vxi11_server.c | 2 |
3 files changed, 11 insertions, 12 deletions
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c index 601e490..c44f086 100644 --- a/libvxi11client/libvxi11client.c +++ b/libvxi11client/libvxi11client.c @@ -39,7 +39,7 @@ device_intr_srq_1_svc(Device_SrqParms *argp, struct svc_req *rqstp) { #endif if (interruptcallback != NULL ) { - interruptcallback(argp->handle.handle_val); + interruptcallback(g_strndup(argp->handle.handle_val, argp->handle.handle_len)); } static char * result; @@ -196,7 +196,7 @@ int vxi11_write(VXI11Context* context, char* data, int len, bool waitlock, bool Device_WriteParms params = { .lid = context->devicelink, .io_timeout = VXI11_DEFAULT_TIMEOUT, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .flags = vxi11_generateflags(waitlock, end, false) }; - params.data.data_len = len < 0 ? (strlen(data) + 1) : len; + params.data.data_len = len < 0 ? strlen(data) : len; params.data.data_val = data; Device_WriteResp* resp = device_write_1(¶ms, context->clnt); @@ -497,7 +497,7 @@ static gpointer interruptthreadfunc(gpointer data) { return NULL ; } -int vxi11_start_interrupt_server(void (*callback)(char* handle)) { +int vxi11_start_interrupt_server(void (*callback)(gchar* handle)) { interruptcallback = callback; interruptserverstarted = true; g_thread_init(NULL ); @@ -617,7 +617,7 @@ int vxi11_enable_srq(VXI11Context* context, bool enable, char* handle) { if (enable) { if (handle != NULL ) { params.handle.handle_val = handle; - params.handle.handle_len = strlen(handle) + 1; + params.handle.handle_len = strlen(handle); } } else { diff --git a/libvxi11client/perlbits/perlglue.c b/libvxi11client/perlbits/perlglue.c index 259a652..5c6448b 100644 --- a/libvxi11client/perlbits/perlglue.c +++ b/libvxi11client/perlbits/perlglue.c @@ -12,13 +12,13 @@ static GAsyncQueue* interruptqueue; typedef struct { - char* handle; + gchar* handle; } Event; static Event* lastevent = NULL; +// perl is responsible for freeing the handle static void freeevent(Event* event) { - g_free(event->handle); g_free(event); } @@ -29,11 +29,9 @@ static void freelast() { } } -static void interruptcallback(char* handle) { +static void interruptcallback(gchar* handle) { Event* event = g_malloc(sizeof(Event)); - int handlelen = strlen(handle); - event->handle = g_malloc(handlelen + 1); - strcpy(event->handle, handle); + event->handle = handle; g_async_queue_push(interruptqueue, event); } @@ -76,11 +74,12 @@ char* glue_wait_for_interrupt(unsigned int timeout) { // if we have a timeout pop with a time out // otherwise block until an interrupt happens + freelast(); + if (timeout > 0) { GTimeVal whentotimeout; g_get_current_time(&whentotimeout); g_time_val_add(&whentotimeout, timeout * 1000); - freelast(); lastevent = (Event*) g_async_queue_timed_pop(interruptqueue, &whentotimeout); } else { diff --git a/vxi11_server.c b/vxi11_server.c index 144141e..398de47 100644 --- a/vxi11_server.c +++ b/vxi11_server.c @@ -482,7 +482,7 @@ device_enable_srq_1_svc(Device_EnableSrqParms *argp, struct svc_req *rqstp) { } if (argp->enable) { if (argp->handle.handle_val != NULL ) { - inthandler = g_strdup(argp->handle.handle_val); + inthandler = g_strndup(argp->handle.handle_val, argp->handle.handle_len); #ifdef DEBUG printf("Interrupt handle set to %s\n", inthandler); #endif |