make logic work with both SOCK_STREAM and SEQ_PACKET
This commit is contained in:
parent
4d2c9c2e36
commit
c2e3a7704a
2 changed files with 25 additions and 20 deletions
22
dev_in.c
22
dev_in.c
|
|
@ -529,18 +529,22 @@ void* dev_in_thread_func(void *ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev_in_data->communication.type == ipc_client_socket) {
|
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);
|
for (int msg_idx = 0; msg_idx < controller_msg_count; ++msg_idx) {
|
||||||
if (write_res < 0) {
|
const int write_res = write(dev_in_data->communication.endpoint.socket.fd, (void*)&controller_msg[0], sizeof(in_message_t));
|
||||||
fprintf(stderr, "Error in writing input event messages: %d -- connection will be drop and retried\n", write_res);
|
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
|
// in case of an error reschedule to socket for reconnection
|
||||||
close(dev_in_data->communication.endpoint.socket.fd);
|
close(dev_in_data->communication.endpoint.socket.fd);
|
||||||
dev_in_data->communication.endpoint.socket.fd = -1;
|
dev_in_data->communication.endpoint.socket.fd = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (dev_in_data->communication.type == ipc_unix_pipe) {
|
} 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);
|
for (int msg_idx = 0; msg_idx < controller_msg_count; ++msg_idx) {
|
||||||
if (write_res < 0) {
|
const int write_res = write(dev_in_data->communication.endpoint.pipe.in_message_pipe_fd, (void*)&controller_msg[0], sizeof(in_message_t));
|
||||||
fprintf(stderr, "Error in writing input event messages: %d\n", write_res);
|
if (write_res < 0) {
|
||||||
|
fprintf(stderr, "Error in writing input event messages: %d\n", write_res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
dev_out.c
23
dev_out.c
|
|
@ -324,23 +324,24 @@ void *dev_out_thread_func(void *ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// send out game-generated events to sockets
|
// 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) {
|
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);
|
for (int msg_idx = 0; msg_idx < out_msgs_count; ++msg_idx) {
|
||||||
if (write_res != bytes_to_send) {
|
const int write_res = write(dev_out_data->communication.endpoint.pipe.out_message_pipe_fd, (void*)&out_msgs, sizeof(out_message_t));
|
||||||
fprintf(stderr, "Error in writing out_message to out_message_pipe: %d\n", write_res);
|
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) {
|
} else if (dev_out_data->communication.type == ipc_server_sockets) {
|
||||||
if (pthread_mutex_lock(&dev_out_data->communication.endpoint.ssocket.mutex) == 0) {
|
if (pthread_mutex_lock(&dev_out_data->communication.endpoint.ssocket.mutex) == 0) {
|
||||||
for (int i = 0; i < MAX_CONNECTED_CLIENTS; ++i) {
|
for (int i = 0; i < MAX_CONNECTED_CLIENTS; ++i) {
|
||||||
if (dev_out_data->communication.endpoint.ssocket.clients[i] > 0) {
|
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);
|
for (int msg_idx = 0; msg_idx < out_msgs_count; ++msg_idx) {
|
||||||
if (write_res != bytes_to_send) {
|
const int write_res = write(dev_out_data->communication.endpoint.ssocket.clients[i], (void*)&out_msgs, sizeof(out_message_t));
|
||||||
fprintf(stderr, "Error in writing out_message to socket number %d: %d\n", i, write_res);
|
if (write_res != sizeof(out_message_t)) {
|
||||||
close(dev_out_data->communication.endpoint.ssocket.clients[i]);
|
fprintf(stderr, "Error in writing out_message to socket number %d: %d\n", i, write_res);
|
||||||
dev_out_data->communication.endpoint.ssocket.clients[i] = -1;
|
close(dev_out_data->communication.endpoint.ssocket.clients[i]);
|
||||||
|
dev_out_data->communication.endpoint.ssocket.clients[i] = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue