diff --git a/dev_in.c b/dev_in.c index f27c847..b342ba3 100644 --- a/dev_in.c +++ b/dev_in.c @@ -529,18 +529,22 @@ void* dev_in_thread_func(void *ptr) { } if (dev_in_data->communication.type == ipc_client_socket) { - const int write_res = write(dev_in_data->communication.endpoint.socket.fd, (void*)&controller_msg[0], sizeof(in_message_t) * controller_msg_count); - if (write_res < 0) { - fprintf(stderr, "Error in writing input event messages: %d -- connection will be drop and retried\n", write_res); + for (int msg_idx = 0; msg_idx < controller_msg_count; ++msg_idx) { + const int write_res = write(dev_in_data->communication.endpoint.socket.fd, (void*)&controller_msg[0], sizeof(in_message_t)); + if (write_res < 0) { + fprintf(stderr, "Error in writing input event messages: %d -- connection will be drop and retried\n", write_res); - // in case of an error reschedule to socket for reconnection - close(dev_in_data->communication.endpoint.socket.fd); - dev_in_data->communication.endpoint.socket.fd = -1; + // in case of an error reschedule to socket for reconnection + close(dev_in_data->communication.endpoint.socket.fd); + dev_in_data->communication.endpoint.socket.fd = -1; + } } } else if (dev_in_data->communication.type == ipc_unix_pipe) { - const int write_res = write(dev_in_data->communication.endpoint.pipe.in_message_pipe_fd, (void*)&controller_msg[0], sizeof(in_message_t) * controller_msg_count); - if (write_res < 0) { - fprintf(stderr, "Error in writing input event messages: %d\n", write_res); + for (int msg_idx = 0; msg_idx < controller_msg_count; ++msg_idx) { + const int write_res = write(dev_in_data->communication.endpoint.pipe.in_message_pipe_fd, (void*)&controller_msg[0], sizeof(in_message_t)); + if (write_res < 0) { + fprintf(stderr, "Error in writing input event messages: %d\n", write_res); + } } } } diff --git a/dev_out.c b/dev_out.c index 75901d8..43e7319 100644 --- a/dev_out.c +++ b/dev_out.c @@ -324,23 +324,24 @@ void *dev_out_thread_func(void *ptr) { } // send out game-generated events to sockets - int fd = -1; - const size_t bytes_to_send = sizeof(out_message_t) * out_msgs_count; - if (dev_out_data->communication.type == ipc_unix_pipe) { - const int write_res = write(dev_out_data->communication.endpoint.pipe.out_message_pipe_fd, (void*)&out_msgs, bytes_to_send); - if (write_res != bytes_to_send) { - fprintf(stderr, "Error in writing out_message to out_message_pipe: %d\n", write_res); + for (int msg_idx = 0; msg_idx < out_msgs_count; ++msg_idx) { + const int write_res = write(dev_out_data->communication.endpoint.pipe.out_message_pipe_fd, (void*)&out_msgs, sizeof(out_message_t)); + if (write_res != sizeof(out_message_t)) { + fprintf(stderr, "Error in writing out_message to out_message_pipe: %d\n", write_res); + } } } else if (dev_out_data->communication.type == ipc_server_sockets) { if (pthread_mutex_lock(&dev_out_data->communication.endpoint.ssocket.mutex) == 0) { for (int i = 0; i < MAX_CONNECTED_CLIENTS; ++i) { if (dev_out_data->communication.endpoint.ssocket.clients[i] > 0) { - const int write_res = write(dev_out_data->communication.endpoint.ssocket.clients[i], (void*)&out_msgs, bytes_to_send); - if (write_res != bytes_to_send) { - fprintf(stderr, "Error in writing out_message to socket number %d: %d\n", i, write_res); - close(dev_out_data->communication.endpoint.ssocket.clients[i]); - dev_out_data->communication.endpoint.ssocket.clients[i] = -1; + for (int msg_idx = 0; msg_idx < out_msgs_count; ++msg_idx) { + const int write_res = write(dev_out_data->communication.endpoint.ssocket.clients[i], (void*)&out_msgs, sizeof(out_message_t)); + if (write_res != sizeof(out_message_t)) { + fprintf(stderr, "Error in writing out_message to socket number %d: %d\n", i, write_res); + close(dev_out_data->communication.endpoint.ssocket.clients[i]); + dev_out_data->communication.endpoint.ssocket.clients[i] = -1; + } } } }