summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-03-11 14:07:13 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-03-11 14:07:13 -0500
commitba34d24d942e186d993732d7a19b5a32544845b3 (patch)
tree3cb565a6ae621e66b1529d0b7b501d22db9a0be8
parent28887d5145e41c9e073c7c6e6990c4e218e05628 (diff)
fix lockups
-rw-r--r--main.c3
-rw-r--r--main.h1
-rw-r--r--thread_http.c8
-rw-r--r--thread_kinect.c10
4 files changed, 15 insertions, 7 deletions
diff --git a/main.c b/main.c
index 0745df9..df892ac 100644
--- a/main.c
+++ b/main.c
@@ -86,6 +86,7 @@ void* start_kinect_inner(void *args_anon) {
thread_kinect(args->video_fd, args->depth_fd, args->accel_fd);
wg_sub(&wg, 1);
running = 0;
+ close(httpsock);
return NULL;
}
static
@@ -140,6 +141,7 @@ void *start_http_inner(void *args_anon) {
thread_http_listener(args->wg, args->video, args->depth);
wg_sub(&wg, 1);
running = 0;
+ close(httpsock);
return NULL;
}
static
@@ -167,6 +169,7 @@ static
void sigint_handler(int num UNUSED)
{
running = 0;
+ close(httpsock);
}
int main(int argc UNUSED, char **argv UNUSED)
diff --git a/main.h b/main.h
index c4fd5dc..32495fa 100644
--- a/main.h
+++ b/main.h
@@ -11,6 +11,7 @@
#endif
extern volatile sig_atomic_t running;
+extern int httpsock;
struct frame {
ssize_t len;
diff --git a/thread_http.c b/thread_http.c
index e410239..b257131 100644
--- a/thread_http.c
+++ b/thread_http.c
@@ -100,6 +100,8 @@ void *start_http_connection_inner(void *arg_anon) {
return NULL;
}
+int httpsock = 0;
+
static
void start_http_connection(int fd) {
wg_add(wg, 1);
@@ -113,12 +115,14 @@ void thread_http_listener(struct wg *awg,
wg = awg;
video = avideo;
depth = adepth;
- int sock = tcp4_parse_listen("8090");
+ httpsock = tcp4_parse_listen("8090");
while (running) {
- int conn = accept(sock, NULL, NULL);
+ int conn = accept(httpsock, NULL, NULL);
if (conn < 0)
continue;
start_http_connection(conn);
}
+ running = 0;
+ close(httpsock);
}
diff --git a/thread_kinect.c b/thread_kinect.c
index f3b5a78..fdd7f25 100644
--- a/thread_kinect.c
+++ b/thread_kinect.c
@@ -1,8 +1,9 @@
#include <error.h>
#include <libfreenect/libfreenect.h>
#include <libusb-1.0/libusb.h>
-#include <stdio.h>
#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
#include "main.h"
@@ -114,8 +115,7 @@ void thread_kinect(int video_fd, int depth_fd, int accel_fd) {
end:
freenect_shutdown(ctx);
-
- if (depth_stream) fclose(depth_stream);
- if (video_stream) fclose(video_stream);
- if (accel_stream) fclose(accel_stream);
+ close(video_fd);
+ close(depth_fd);
+ close(accel_fd);
}