diff options
-rw-r--r-- | libvxi11client/client.c | 2 | ||||
-rw-r--r-- | libvxi11client/libvxi11client.c | 40 |
2 files changed, 33 insertions, 9 deletions
diff --git a/libvxi11client/client.c b/libvxi11client/client.c index bc8a49f..816d2f3 100644 --- a/libvxi11client/client.c +++ b/libvxi11client/client.c @@ -18,6 +18,8 @@ static char* geterrorstring(int errorcode) { return "device locked by another link"; case -12: return "no lock held by this link"; + case -29: + return "channel already established"; default: return "unknown error code"; } diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c index d0eef3d..7c7878c 100644 --- a/libvxi11client/libvxi11client.c +++ b/libvxi11client/libvxi11client.c @@ -26,6 +26,14 @@ static CLIENT* clnt = NULL; static CLIENT* abortclnt = NULL; static Device_Link link; +static GThread* interruptthread; +static bool interruptchannelopen = false; + +static void killinterruptthreadandwait() { + interruptchannelopen = false; + g_thread_join(interruptthread); + interruptthread = NULL; +} void * device_intr_srq_1_svc(Device_SrqParms *argp, struct svc_req *rqstp) { @@ -359,7 +367,7 @@ static gpointer interruptthreadfunc(gpointer data) { //svc_run(); // stolen from: http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.commtechref%2Fdoc%2Fcommtrf1%2Fsvc_getreq_poll.htm - while (1) { + while (interruptchannelopen) { /* initialize the pollfd_set array and get no of file descriptors in "no_of_fds"*/ @@ -384,17 +392,20 @@ static gpointer interruptthreadfunc(gpointer data) { * create an interrupt channel from the connected device */ int vxi11_create_intr_chan() { - if (clnt == NULL) + if (interruptchannelopen) + return 0; + else if (clnt == NULL) + return 0; + else if (interruptthread != NULL) return 0; + interruptchannelopen = true; u_short port = 0; g_thread_init(NULL); - GThread* interruptthread = g_thread_create(interruptthreadfunc, &port, false, NULL); + interruptthread = g_thread_create(interruptthreadfunc, &port, true, NULL); sleep(2); - // - struct sockaddr_in myaddress; get_myaddress(&myaddress); @@ -403,10 +414,14 @@ int vxi11_create_intr_chan() { Device_Error* error = create_intr_chan_1(&remotefunc, clnt); if (error != NULL && error->error == 0) return 1; - else if (error == NULL) + else if (error == NULL) { + killinterruptthreadandwait(); return 0; - else + } + else { + killinterruptthreadandwait(); return -(error->error); + } } /** @@ -414,11 +429,18 @@ int vxi11_create_intr_chan() { */ int vxi11_destroy_intr_chan() { - if (clnt == NULL) + if (!interruptchannelopen) + return 0; + else if (clnt == NULL) return 0; + else if (interruptthread == NULL) + return 0; + Device_Error* error = destroy_intr_chan_1(NULL, clnt); - if (error != NULL && error->error == 0) + if (error != NULL && error->error == 0) { + killinterruptthreadandwait(); return 1; + } else if (error == NULL) return 0; else |