int new_connection_handler(event_loop* el, int fd, kivi_client* client) { log_info("new connection %d", fd); int client_fd = accept(fd, NULL, NULL); if (client_fd > 0) { if (set_non_blocking(client_fd)) { log_warn("couldn't make client socket nonblocking %d", client_fd); return FAILED; } file_event file_ev; file_ev.mask = READ_EVENT | WRITE_EVENT; file_ev.read_handler = socket_reader; file_ev.write_handler = socket_writer; if (add_to_el(el, client_fd, file_ev) == FAILED) { return FAILED; } else { client = create_new_client(client_fd); server.clients[client_fd] = client; } } else { return FAILED; } return OK; }
char * ccnetrpc_transport_send (void *arg, const gchar *fcall_str, size_t fcall_len, size_t *ret_len) { CcnetrpcTransportParam *priv; CcnetClient *session, *new_session; g_warn_if_fail (arg != NULL && fcall_str != NULL); priv = (CcnetrpcTransportParam *)arg; if (priv->session != NULL) { /* Use single ccnet client as transport. */ return invoke_service (priv->session, priv->peer_id, priv->service, fcall_str, fcall_len, ret_len); } else { /* Use client pool as transport. */ session = ccnet_client_pool_get_client (priv->pool); if (!session) { g_warning ("[Sea RPC] Failed to get client from pool.\n"); *ret_len = 0; return NULL; } char *ret = invoke_service (session, priv->peer_id, priv->service, fcall_str, fcall_len, ret_len); if (ret != NULL) { ccnet_client_pool_return_client (priv->pool, session); return ret; } /* If we failed to send data through the ccnet client returned by * client pool, ccnet may have been restarted. * In this case, we create a new ccnet client and put it into * the client pool after use. */ g_message ("[Sea RPC] Ccnet disconnected. Connect again.\n"); new_session = create_new_client (session->config_dir); if (!new_session) { *ret_len = 0; return NULL; } g_object_unref (session); ret = invoke_service (new_session, priv->peer_id, priv->service, fcall_str, fcall_len, ret_len); if (ret != NULL) ccnet_client_pool_return_client (priv->pool, new_session); else g_object_unref (new_session); return ret; } }
static errval_t connect_ether_cb(void *st, struct net_queue_manager_binding *b) { ETHERSRV_DEBUG("ether service got a connection!44\n"); // copy my message receive handler vtable to the binding b->rx_vtbl = rx_nqm_vtbl; b->error_handler = error_handler; // Create a new client for this connection struct client_closure *cc = create_new_client(b); if (cc == NULL) { return ETHERSRV_ERR_NOT_ENOUGH_MEM; } return SYS_ERR_OK; } // end function: connect_ether_cb
void process_incomming_sockets(server_info_t* server_info) { if(!FD_ISSET(server_info->socket, &server_info->stReadFDS)) { return; } server_info->dataSockets--; int length = sizeof(SOCKADDR_IN); SOCKADDR_IN newClientSockAddr = {0}; SOCKET newClient = accept(server_info->socket, (struct sockaddr *) &newClientSockAddr, &length); if(newClient == INVALID_SOCKET) { printf("Error while accepting new client\n"); return; } new_client_broadcast(newClient, server_info); client_info_t* clt_info = create_new_client(newClient, &newClientSockAddr); if(!clt_info) { printf("Server memory error\n"); closesocket(newClient); return; } if(!server_info->clt_info_list) { server_info->clt_info_list = clt_info; return; } client_info_t* clt_info_walker = server_info->clt_info_list; while(clt_info_walker->next) { clt_info_walker = clt_info_walker->next; } clt_info_walker->next = clt_info; }