/* creates a new tcp connection structure and informs the TCP Main on that * a +1 ref is set for the new conn ! * IMPORTANT - the function assumes you want to create a new TCP conn as * a result of a connect operation - the conn will be set as connect !! * Accepted connection are triggered internally only */ struct tcp_connection* tcp_conn_create(int sock, union sockaddr_union* su, struct socket_info* si, int state) { struct tcp_connection *c; /* create the connection structure */ c = tcp_conn_new(sock, su, si, state); if (c==NULL) return NULL; return (tcp_conn_send(c) == 0 ? c : NULL); }
void _9p_tcp_process_request(struct _9p_request_data *req9p) { u32 outdatalen = 0; int rc = 0; char replydata[_9P_MSG_SIZE]; rc = _9p_process_buffer(req9p, replydata, &outdatalen); if (rc != 1) { LogMajor(COMPONENT_9P, "Could not process 9P buffer on socket #%lu", req9p->pconn->trans_data.sockfd); } else { if (tcp_conn_send(req9p->pconn, replydata, outdatalen, 0) != outdatalen) LogMajor(COMPONENT_9P, "Could not send 9P/TCP reply correclty on socket #%lu", req9p->pconn->trans_data.sockfd); } _9p_DiscardFlushHook(req9p); } /* _9p_process_request */
static struct tcp_connection* ws_connect(struct socket_info* send_sock, union sockaddr_union* to, int *fd) { struct tcp_connection *c; if ((c=ws_sync_connect(send_sock, to))==0) { LM_ERR("connect failed\n"); return NULL; } /* the state of the connection should be NONE, otherwise something is * wrong */ if (WS_TYPE(c) != WS_NONE) { LM_BUG("invalid type for connection %d\n", WS_TYPE(c)); goto error; } WS_TYPE(c) = WS_CLIENT; if (ws_client_handshake(c) < 0) { LM_ERR("cannot complete WebSocket handshake\n"); goto error; } *fd = c->fd; /* clear the fd, just in case */ c->fd = -1; /* handshake done - send the socket to main */ if (tcp_conn_send(c) < 0) { LM_ERR("cannot send socket to main\n"); goto error; } return c; error: tcp_conn_destroy(c); return NULL; }