FreeCalypso > hg > themwi-system-sw
view mgw/ctrl_prot.c @ 64:1f863c63f96b
sip-in: beginning of disconnect handling
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 18 Sep 2022 15:29:30 -0800 |
parents | 020ba624bdd8 |
children | f062c32a5116 |
line wrap: on
line source
/* * In this module we implement our control socket protocol. */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <syslog.h> #include <unistd.h> #include "../include/tmgw_ctrl.h" #include "struct.h" #include "select.h" struct endpoint * find_ep_by_id(conn, id) struct ctrl_conn *conn; unsigned id; { struct endpoint *ep; for (ep = conn->endp_list; ep; ep = ep->next) if (ep->ep_id == id) return ep; return 0; } void ctrl_message_handler(fd, conn) struct ctrl_conn *conn; { struct tmgw_ctrl_req req; struct tmgw_ctrl_resp resp; int rc; rc = recv(fd, &req, sizeof req, 0); if (rc < sizeof req) { syslog(LOG_INFO, "ctrl connection closing %s active endpoints", conn->endp_list ? "with" : "without"); close(fd); FD_CLR(fd, &select_for_read); dlcx_all_on_conn(conn); free(conn); return; } bzero(&resp, sizeof resp); resp.transact_ref = req.transact_ref; switch (req.opcode) { case TMGW_CTRL_OP_CRCX: process_crcx(conn, &req, &resp); break; case TMGW_CTRL_OP_MDCX: process_mdcx(conn, &req, &resp); break; case TMGW_CTRL_OP_DLCX: process_dlcx(conn, &req, &resp); break; default: resp.res = TMGW_RESP_ERR_OPCODE; } send(fd, &resp, sizeof resp, 0); }