static PortServer * find_port_server(const char * id) { LINK * qhp = &server_list; LINK * qp = qhp->next; while (qp != qhp) { PortServer * server = link2server(qp); if (strcmp(server->id, id) == 0) return server; qp = qp->next; } return NULL; }
static void port_connection_open_event(void * arg) { LINK * qhp = &server_list; LINK * qp = qhp->next; while (qp != qhp) { PortServer * server = link2server(qp); if (server == (PortServer *)arg) { port_connection_open(server, server->is_udp ? server->sock : -1); } qp = qp->next; } }
static void event_channel_closed(Channel * c) { LINK * qhp = &server_list; LINK * qp = qhp->next; while (qp != qhp) { PortServer * server = link2server(qp); qp = qp->next; if (server->channel == c) { port_server_shutdown(server); } } }
int destroy_port_server(PortServer * server) { LINK * qhp = &server_list; LINK * qp = qhp->next; while (qp != qhp) { if (server == (PortServer *)link2server(qp)) break; qp = qp->next; } if (qp == qp->next) { errno = EINVAL; return -1; } port_server_shutdown(server); return 0; }
int get_port_server_info(PortServer * server, PortServerInfo * info) { LINK * qhp = &server_list; LINK * qp = qhp->next; while (qp != qhp) { if (server == (PortServer *)link2server(qp)) break; qp = qp->next; } if (qp == qp->next) { errno = EINVAL; return -1; } info->is_udp = server->is_udp; info->port = server->local_port; return 0; }
static void port_server_cmd_list(char * token, Channel * c) { LINK * qhp = &server_list; LINK * qp = qhp->next; int cnt = 0; if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX); write_stringz(&c->out, "R"); write_stringz(&c->out, token); write_errno(&c->out, 0); write_stream(&c->out, '['); while (qp != qhp) { PortServer * server = link2server(qp); if (cnt > 0) write_stream(&c->out, ','); json_write_string(&c->out, server->id); qp = qp->next; cnt++; } write_stream(&c->out, ']'); write_stream(&c->out, 0); write_stream(&c->out, MARKER_EOM); }