static void lwmsg_connection_destruct( LWMsgAssoc* assoc ) { ConnectionPrivate* priv = CONNECTION_PRIVATE(assoc); lwmsg_connection_buffer_destruct(&priv->sendbuffer); lwmsg_connection_buffer_destruct(&priv->recvbuffer); if (priv->fd != -1) { close(priv->fd); priv->fd = -1; } if (priv->endpoint) { free(priv->endpoint); priv->endpoint = NULL; } if (priv->active_session) { lwmsg_session_release(priv->active_session); } if (priv->default_session) { lwmsg_session_release(priv->default_session); } if (priv->marshal_context) { lwmsg_data_context_delete(priv->marshal_context); } }
LWMsgStatus lwmsg_peer_accept_fd_internal( LWMsgPeer* peer, LWMsgEndpointType type, int fd, const char* endpoint ) { LWMsgStatus status = LWMSG_STATUS_SUCCESS; PeerSession* session = NULL; LWMsgAssoc* assoc = NULL; LWMsgBool locked = LWMSG_FALSE; PEER_LOCK(peer, locked); if (!peer->listen_tasks) { BAIL_ON_ERROR(status = lwmsg_task_group_new(peer->task_manager, &peer->listen_tasks)); } BAIL_ON_ERROR(status = lwmsg_set_close_on_exec(fd)); /* Create new connection with client fd, put it into task, schedule task */ BAIL_ON_ERROR(status = lwmsg_peer_session_new(peer, &session)); switch (type) { case LWMSG_ENDPOINT_LOCAL: if (endpoint) { session->endpoint_str = lwmsg_format("<local socket:%s>", endpoint); } else { session->endpoint_str = lwmsg_format("<local fd:%d>", fd); } break; default: break; } BAIL_ON_ERROR(status = lwmsg_connection_new(peer->context, peer->protocol, &assoc)); BAIL_ON_ERROR(status = lwmsg_connection_set_fd(assoc, type, fd)); BAIL_ON_ERROR(status = lwmsg_assoc_set_nonblock(assoc, LWMSG_TRUE)); BAIL_ON_ERROR(status = lwmsg_peer_assoc_task_new_accept(session, assoc, &session->assoc_session)); assoc = NULL; lwmsg_task_wake(session->assoc_session->event_task); error: PEER_UNLOCK(peer, locked); if (status) { if (assoc) { lwmsg_assoc_delete(assoc); } if (session) { lwmsg_session_release((LWMsgSession*) session); } } return status; }