make logic work with both SOCK_STREAM and SEQ_PACKET

This commit is contained in:
Denis 2023-12-14 13:41:33 +01:00
parent 4d2c9c2e36
commit c2e3a7704a
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
2 changed files with 25 additions and 20 deletions

View file

@ -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;
}
}
}
}