int uman_send_user_list(struct hub_info* hub, struct hub_user* target) { int ret = 1; struct hub_user* user; user_flag_set(target, flag_user_list); user = (struct hub_user*) list_get_first(hub->users->list); /* iterate users - only on INF or PAS msg */ while (user) { if (user_is_logged_in(user)) { ret = route_to_user(hub, target, user->info); if (!ret) break; } user = (struct hub_user*) list_get_next(hub->users->list); } #if 0 FIXME: FIXME FIXME handle send queue excess if (!target->send_queue_size) { user_flag_unset(target, flag_user_list); } #endif return ret; }
int route_flush_pipeline(struct hub_info* hub, struct hub_user* u) { if (ioq_send_is_empty(u->send_queue)) return 0; handle_net_write(u); user_flag_unset(u, flag_pipeline); return 1; }
int handle_net_read(struct hub_user* user) { static char buf[MAX_RECV_BUF]; struct hub_recvq* q = user->recv_queue; size_t buf_size = hub_recvq_get(q, buf, MAX_RECV_BUF); ssize_t size; if (user_flag_get(user, flag_maxbuf)) buf_size = 0; size = net_con_recv(user->connection, buf + buf_size, MAX_RECV_BUF - buf_size); if (size > 0) buf_size += size; if (size < 0) { if (size == -1) return quit_disconnected; else return quit_socket_error; } else if (size == 0) { return 0; } else { char* lastPos = 0; char* start = buf; char* pos = 0; size_t remaining = buf_size; while ((pos = memchr(start, '\n', remaining))) { lastPos = pos; pos[0] = '\0'; #ifdef DEBUG_SENDQ LOG_DUMP("PROC: \"%s\" (%d)\n", start, (int) (pos - start)); #endif if (user_flag_get(user, flag_maxbuf)) { user_flag_unset(user, flag_maxbuf); } else { if (((pos - start) > 0) && g_hub->config->max_recv_buffer > (pos - start)) { if (hub_handle_message(g_hub, user, start, (pos - start)) == -1) { return quit_protocol_error; } } } pos[0] = '\n'; /* FIXME: not needed */ pos ++; remaining -= (pos - start); start = pos; } if (lastPos || remaining) { if (remaining < g_hub->config->max_recv_buffer) { hub_recvq_set(q, lastPos ? lastPos : buf, remaining); } else { hub_recvq_set(q, 0, 0); user_flag_set(user, flag_maxbuf); LOG_WARN("Received message past max_recv_buffer, dropping message."); } } else { hub_recvq_set(q, 0, 0); } } return 0; }