fix segv on reconnect

Signed-off-by: Hoernchen <la@tfc-server.de>

improve staibility (for sdr#)

Signed-off-by: Hoernchen <la@tfc-server.de>
master
edy555 12 years ago committed by Hoernchen
parent 196bb15169
commit aa60c2aaed
  1. 24
      src/rtl_tcp.c

@ -123,8 +123,10 @@ sighandler(int signum)
static void sighandler(int signum) static void sighandler(int signum)
{ {
fprintf(stderr, "Signal caught, exiting!\n"); fprintf(stderr, "Signal caught, exiting!\n");
do_exit = 1; if (!do_exit) {
rtlsdr_cancel_async(dev); rtlsdr_cancel_async(dev);
do_exit = 1;
}
} }
#endif #endif
@ -206,11 +208,15 @@ static void *tcp_worker(void *arg)
r = select(s+1, NULL, &writefds, NULL, &tv); r = select(s+1, NULL, &writefds, NULL, &tv);
if(r) { if(r) {
bytessent = send(s, &curelem->data[index], bytesleft, 0); bytessent = send(s, &curelem->data[index], bytesleft, 0);
if (bytessent == SOCKET_ERROR || do_exit) { if (bytessent == SOCKET_ERROR) {
printf("worker socket error\n"); perror("worker socket error");
sighandler(0); sighandler(0);
dead[0]=1; dead[0]=1;
pthread_exit(NULL); pthread_exit(NULL);
} else if (do_exit) {
printf("do_exit\n");
dead[0]=1;
pthread_exit(NULL);
} else { } else {
bytesleft -= bytessent; bytesleft -= bytessent;
index += bytessent; index += bytessent;
@ -260,11 +266,15 @@ static void *command_worker(void *arg)
r = select(s+1, &readfds, NULL, NULL, &tv); r = select(s+1, &readfds, NULL, NULL, &tv);
if(r) { if(r) {
received = recv(s, (char*)&cmd+(sizeof(cmd)-left), left, 0); received = recv(s, (char*)&cmd+(sizeof(cmd)-left), left, 0);
if(received == SOCKET_ERROR || do_exit){ if(received == SOCKET_ERROR){
printf("comm recv socket error\n"); perror("comm recv socket error");
sighandler(0); sighandler(0);
dead[1]=1; dead[1]=1;
pthread_exit(NULL); pthread_exit(NULL);
} else if(do_exit){
printf("do exit\n");
dead[1]=1;
pthread_exit(NULL);
} else { } else {
left -= received; left -= received;
} }
@ -514,12 +524,14 @@ int main(int argc, char **argv)
r = rtlsdr_read_async(dev, rtlsdr_callback, (void *)0, r = rtlsdr_read_async(dev, rtlsdr_callback, (void *)0,
buf_num, 0); buf_num, 0);
closesocket(s);
if(!dead[0]) if(!dead[0])
pthread_join(tcp_worker_thread, &status); pthread_join(tcp_worker_thread, &status);
dead[0]=0;
if(!dead[1]) if(!dead[1])
pthread_join(command_thread, &status); pthread_join(command_thread, &status);
dead[1]=0;
closesocket(s);
printf("all threads dead..\n"); printf("all threads dead..\n");
curelem = ll_buffers; curelem = ll_buffers;

Loading…
Cancel
Save