void uim_helper_read_proc(int fd) { int rc; while (uim_helper_fd_readable(fd) > 0) { rc = read(fd, uim_recv_buf, sizeof(uim_recv_buf)); if (rc == 0 || (rc == -1 && errno != EAGAIN)) { uim_helper_close_client_fd(fd); return; } else if (rc > 0) { uim_read_buf = uim_helper_buffer_append(uim_read_buf, uim_recv_buf, rc); } } }
static void distribute_message(char *msg, struct client *cl) { int i; size_t msg_len; msg_len = strlen(msg); for (i = 0; i < nr_client_slots; i++) { if (clients[i].fd != -1 && clients[i].fd != cl->fd) { clients[i].wbuf = uim_helper_buffer_append(clients[i].wbuf, msg, msg_len); FD_SET(clients[i].fd, &s_fdset_write); } } }
static int reflect_message_fragment(struct client *cl) { ssize_t rc; char *msg; /* do read */ rc = read(cl->fd, read_buf, sizeof(read_buf)); if (rc == -1) { if (errno == EAGAIN || errno == EINTR) return 0; return -1; } else if (rc == 0) return -1; cl->rbuf = uim_helper_buffer_append(cl->rbuf, read_buf, rc); while ((msg = uim_helper_buffer_get_message(cl->rbuf))) { distribute_message(msg, cl); free(msg); } return 1; }