Skip to content

Commit

Permalink
(continued)
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Dec 15, 2024
1 parent efb19fd commit c82728c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,11 @@ int start_region_handler() {
size_t stacksize;
pthread_attr_getstacksize(&thread_attr, &stacksize);
size_t new_stacksize = 320 * 1024;
if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) {
if (pthread_attr_setstacksize(&thread_attr, new_stacksize))
HAL_DANGER("region", "Can't set stack size %zu\n", new_stacksize);
}
pthread_create(&regionPid, &thread_attr, (void *(*)(void *))region_thread, NULL);
if (pthread_attr_setstacksize(&thread_attr, stacksize)) {
if (pthread_attr_setstacksize(&thread_attr, stacksize))
HAL_DANGER("region", "Can't set stack size %zu\n", stacksize);
}
pthread_attr_destroy(&thread_attr);
}

Expand Down
15 changes: 10 additions & 5 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,29 @@ void close_socket_fd(int socket_fd) {

void free_client(int i) {
if (client_fds[i].socket_fd < 0) return;

close_socket_fd(client_fds[i].socket_fd);
client_fds[i].socket_fd = -1;
}

int send_to_fd(int client_fd, char *buf, ssize_t size) {
ssize_t sent = 0, len = 0;
if (client_fd < 0) return -1;

while (sent < size) {
len = send(client_fd, buf + sent, size - sent, MSG_NOSIGNAL);
if (len < 0) return -1;
sent += len;
}

return 0;
}

int send_to_fd_nonblock(int client_fd, char *buf, ssize_t size) {
if (client_fd < 0) return -1;

send(client_fd, buf, size, MSG_DONTWAIT | MSG_NOSIGNAL);

return 0;
}

Expand All @@ -90,6 +95,7 @@ int send_to_client(int i, char *buf, ssize_t size) {
free_client(i);
return -1;
}

return 0;
}

Expand Down Expand Up @@ -263,11 +269,10 @@ void send_pcm_to_client(hal_audframe *frame) {

void send_mjpeg_to_client(char index, char *buf, ssize_t size) {
static char prefix_buf[128];
ssize_t prefix_size = sprintf(
prefix_buf,
"--boundarydonotcross\r\nContent-Type:image/jpeg\r\nContent-Length: "
"%lu\r\n\r\n",
size);
ssize_t prefix_size = sprintf(prefix_buf,
"--boundarydonotcross\r\n"
"Content-Type:image/jpeg\r\n"
"Content-Length: %lu\r\n\r\n", size);
buf[size++] = '\r';
buf[size++] = '\n';

Expand Down

0 comments on commit c82728c

Please sign in to comment.