/* * Static initialization */ void CVmBifNet::attach(VMG0_) { /* initialize the network layer */ os_net_init(G_net_config); /* create the network message queue */ G_net_queue = new TadsMessageQueue(0); }
ut_setup() { int len; struct in_addr addr; int reuse; UT_ASSERT(!os_net_init()); /* create sockets */ server_sock = os_socket(AF_INET, SOCK_STREAM, 0); UT_ASSERT(server_sock >= 0); reuse = 1; UT_ASSERT(os_setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) >= 0); client_sock = os_socket(AF_INET, SOCK_STREAM, 0); UT_ASSERT(client_sock >= 0); /* fill in server information */ server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); server_addr.sin_port = htons(DATA_PORT); /* bind sockets */ UT_ASSERT(os_bind(server_sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) >= 0); UT_ASSERT(os_listen(server_sock, BACKLOG) >= 0); /* connect to server */ os_inet_aton("127.0.0.1", &addr); memset(&client_addr, 0, sizeof(client_addr)); client_addr.sin_family = AF_INET; client_addr.sin_addr.s_addr = addr.s_addr; client_addr.sin_port = htons(DATA_PORT); if (os_connect(client_sock, (struct sockaddr *)&client_addr, sizeof(client_addr)) < 0) UT_FAIL(); len = sizeof(struct sockaddr_in); accept_sock = os_accept(server_sock, (struct sockaddr *)&server_addr, &len); UT_ASSERT(accept_sock >= 0); }
/** * Set up network communication. * * \param[in] cluster_uuid iThe cluster uuid we bellong to * \param[in] node_name Node name * \param[in] hostname Host name * \param[in] nodeid This node id * \param[in] mgroup Multicast group * \param[in] mport Multicast port * \param[in] inca Incarnation * * \return 0 on success, negative error code otherwise */ static int startup(const exa_uuid_t *cluster_uuid, const char *node_name, const char *hostname, exa_nodeid_t nodeid, const char *mgroup, unsigned short mport, unsigned short inca) { const char *err_msg; int s; /* Initialize os_network */ if (os_net_init() != 0) { err_msg = "Failed initializing os_network"; s = -EFAULT; goto failed; } /* Initialize examsg framework */ local_mh = examsgInit(EXAMSG_CMSGD_ID); if (local_mh == NULL) { err_msg = "Failed initializing local handle"; s = -EFAULT; goto failed; } net_mh = examsgInit(EXAMSG_CMSGD_RECV_ID); if (net_mh == NULL) { err_msg = "Failed initializing network handle"; s = -EFAULT; goto failed; } /* Create local (regular) mailbox */ s = examsgAddMbox(local_mh, EXAMSG_CMSGD_ID, 3, EXAMSG_MSG_MAX); if (s) { err_msg = "Failed creating local mailbox"; goto failed; } /* Create special (reserved) network mailbox */ s = examsgAddMbox(local_mh, EXAMSG_NETMBOX_ID, 3, EXAMSG_MSG_MAX); if (s) { err_msg = "Failed creating network mailbox"; goto failed; } /* Create network channel */ s = network_init(cluster_uuid, node_name, hostname, nodeid, mgroup, mport, inca); if (s) { err_msg = "Failed initializing network"; goto failed; } return 0; failed: exalog_error("%s, error %d", err_msg, s); cleanup(); return s; }
ut_setup() { UT_ASSERT(!os_net_init()); }