Minor fixes

This commit is contained in:
Stephen Seo 2023-08-13 13:31:04 +09:00
parent cfdeceb638
commit 6574341870
2 changed files with 16 additions and 5 deletions

View file

@ -24,6 +24,7 @@ int unix_socket_handler_thread_function(void *ud) {
int data_socket; int data_socket;
char buffer[8]; char buffer[8];
char ret_buffer[8]; char ret_buffer[8];
unsigned int ticks;
while(1) { while(1) {
mtx_lock(handler->mutex); mtx_lock(handler->mutex);
@ -43,6 +44,7 @@ int unix_socket_handler_thread_function(void *ud) {
break; break;
} }
ticks = 0;
memset(ret_buffer, 0, sizeof(ret_buffer)); memset(ret_buffer, 0, sizeof(ret_buffer));
while (1) { while (1) {
mtx_lock(handler->mutex); mtx_lock(handler->mutex);
@ -56,6 +58,11 @@ int unix_socket_handler_thread_function(void *ud) {
ret = read(data_socket, buffer, sizeof(buffer)); ret = read(data_socket, buffer, sizeof(buffer));
if (ret == -1) { if (ret == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) { if (errno == EAGAIN || errno == EWOULDBLOCK) {
if (++ticks > 200) {
// Timed out.
ret = -1;
break;
}
thrd_sleep(&duration, 0); thrd_sleep(&duration, 0);
continue; continue;
} }
@ -84,13 +91,17 @@ int unix_socket_handler_thread_function(void *ud) {
ret_buffer[1] |= 2; ret_buffer[1] |= 2;
} }
} }
ret = 0;
break; break;
} }
ret = write(data_socket, ret_buffer, sizeof(ret_buffer)); if (ret == 0) {
if (ret == -1) { ret = write(data_socket, ret_buffer, sizeof(ret_buffer));
// Error. TODO handle this. if (ret == -1) {
break; // Error. TODO handle this.
close(data_socket);
continue;
}
} }
close(data_socket); close(data_socket);

View file

@ -23,7 +23,7 @@ typedef struct UnixSocketHandler {
/* /*
* ???? 0001 - thread should stop * ???? 0001 - thread should stop
*/ */
volatile uint64_t ccflags; uint64_t ccflags;
int socket_descriptor; int socket_descriptor;
} UnixSocketHandler; } UnixSocketHandler;