From 8ffa800d16a3a0ea7cc713b63620681a5f910370 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 23 Jan 2014 21:33:32 +0000 Subject: [PATCH] integrated timeout monitor and removed socket close as it was causing a segfault at end of transfer --- src/udpipe_client.cpp | 9 ++++----- src/udpipe_threads.cpp | 26 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/udpipe_client.cpp b/src/udpipe_client.cpp index 9b0c51b..b46191b 100644 --- a/src/udpipe_client.cpp +++ b/src/udpipe_client.cpp @@ -25,6 +25,7 @@ and limitations under the License. #include #include #include +#include #include "udpipe.h" #include "udpipe_client.h" @@ -118,11 +119,9 @@ int run_client(thread_args *args) pthread_create(&rcvthread, NULL, recvdata, &rcvargs); pthread_detach(rcvthread); - if (args->verbose) fprintf(stderr, "[client] Creating send thread...\n"); - rs_args send_args; send_args.usocket = new UDTSOCKET(client); send_args.use_crypto = args->use_crypto; @@ -149,11 +148,11 @@ int run_client(thread_args *args) pthread_create(&sndthread, NULL, senddata, &send_args); - void * retval; pthread_join(sndthread, &retval); - - UDT::cleanup(); + + // Partial cause of segfault issue commented out for now + // UDT::cleanup(); return 0; } diff --git a/src/udpipe_threads.cpp b/src/udpipe_threads.cpp index e39a697..0bf4e12 100644 --- a/src/udpipe_threads.cpp +++ b/src/udpipe_threads.cpp @@ -76,7 +76,7 @@ void *monitor_timeout(void* arg) { -void send_full(UDTSOCKET sock, char* buffer, int len){ +void send_full(UDTSOCKET sock, char* buffer, int len){ int sent = 0; int rs = 0; @@ -107,6 +107,7 @@ void recv_full(UDTSOCKET sock, char* buffer, int len) "send_full: Unable to send data." << endl; exit(1); } + timeout_sem = 1; recvd += rs; } @@ -246,7 +247,7 @@ void* recvdata(void * _args) crypto_cursor = 0; } - + rs = UDT::recv(recver, indata+buffer_cursor, block_size-buffer_cursor, 0); @@ -308,6 +309,8 @@ void* recvdata(void * _args) exit(0); } + timeout_sem = 1; + write(fileno(stdout), indata, rs); } @@ -379,7 +382,7 @@ void* senddata(void* _args) if(bytes_read == 0) { sleep(1); UDT::close(client); - exit(0); + return NULL; } if(args->use_crypto){ @@ -423,14 +426,23 @@ void* senddata(void* _args) } else { while (1) { + bytes_read = read(fileno(stdin), outdata, BUFF_SIZE); int ssize = 0; int ss; if(bytes_read == 0) { - UDT::close(client); - sleep(1); - exit(0); + + // fprintf(stderr, "Transfer complete\n"); + + // sleep (1); + + //UDT::close(client); + //UDT::close(*args->usocket); + + return NULL; + + //exit(0); } @@ -449,7 +461,7 @@ void* senddata(void* _args) } } - UDT::close(client); + sleep(1); return NULL; }