static int run(void) { int i, ret = 0; buf = malloc(!custom ? test_size[TEST_CNT - 1].size : transfer_size); if (!buf) { perror("malloc"); return -1; } if (!dst_addr) { ret = server_listen(); if (ret) goto free; } printf("%-10s%-8s%-8s%-8s%-8s%8s %10s%13s\n", "name", "bytes", "xfers", "iters", "total", "time", "Gb/sec", "usec/xfer"); if (!custom) { optimization = opt_latency; ret = dst_addr ? client_connect() : server_connect(); if (ret) goto free; for (i = 0; i < TEST_CNT; i++) { if (test_size[i].option > size_option) continue; init_latency_test(test_size[i].size); run_test(); } rshutdown(rs, SHUT_RDWR); rclose(rs); optimization = opt_bandwidth; ret = dst_addr ? client_connect() : server_connect(); if (ret) goto free; for (i = 0; i < TEST_CNT; i++) { if (test_size[i].option > size_option) continue; init_bandwidth_test(test_size[i].size); run_test(); } } else { ret = dst_addr ? client_connect() : server_connect(); if (ret) goto free; ret = run_test(); } rshutdown(rs, SHUT_RDWR); rclose(rs); free: free(buf); return ret; }
/* * set basic stuff and send OPTIONS request. * this can be used to determine which protocol to use, * depending on its server. * return value sock : success * -1 : failure */ int rtsp_connect(struct stream_t *stream) { int sock; struct stream_ctrl_t *stream_ctrl = stream->stream_ctrl; struct rtsp_ctrl_t *rtsp_ctrl = stream_ctrl->rtsp_ctrl; struct url_t *url = stream->url; set_serverinfo(stream->serverinfo,url->hostname,url->port,NULL,0,RTSP_PORT); rtsp_ctrl->server = NULL; rtsp_ctrl->cseq = 1; rtsp_ctrl->server_state = 0; rtsp_ctrl->server_caps = 0; rtsp_ctrl->session = NULL; rtsp_ctrl->get_media_packet = NULL; /* make mrl */ rtsp_make_mrl(rtsp_ctrl,stream->serverinfo->host,stream->serverinfo->port,url->filepath); sock = server_connect(stream->serverinfo->connect_host,stream->serverinfo->connect_port); if(sock < 0) { /* couldn't connect for some reason. (port closed maybe) */ goto failed; } stream->netsock->sock = sock; /* save socket id */ return sock; failed: return -1; }
int sync_connect(struct sync_device *d, const char *host, unsigned short port) { int i; if (d->sock != INVALID_SOCKET) closesocket(d->sock); d->sock = server_connect(host, port); if (d->sock == INVALID_SOCKET) return -1; for (i = 0; i < (int)d->num_tracks; ++i) { free(d->tracks[i]->keys); d->tracks[i]->keys = NULL; d->tracks[i]->num_keys = 0; } for (i = 0; i < (int)d->num_tracks; ++i) { if (get_track_data(d, d->tracks[i])) { closesocket(d->sock); d->sock = INVALID_SOCKET; return -1; } } return 0; }
static zmsg_t * server_method (server_t *self, const char *method, zmsg_t *msg) { // Connect to a remote zmsg_t *reply = NULL; if (streq (method, "CONNECT")) { char *endpoint = zmsg_popstr (msg); assert (endpoint); server_connect (self, endpoint); zstr_free (&endpoint); } else if (streq (method, "PUBLISH")) { char *key = zmsg_popstr (msg); char *value = zmsg_popstr (msg); server_accept (self, key, value); zstr_free (&key); zstr_free (&value); } else if (streq (method, "STATUS")) { // Return number of tuples we have stored reply = zmsg_new (); assert (reply); zmsg_addstr (reply, "STATUS"); zmsg_addstrf (reply, "%d", (int) zhashx_size (self->tuples)); } else zsys_error ("unknown zgossip method '%s'", method); return reply; }
static rstatus_t server_each_preconnect(void *elem, void *data) { rstatus_t status; struct server *server; struct server_pool *pool; struct conn *conn; server = elem; pool = server->owner; conn = server_conn(server); if (conn == NULL) { return DN_ENOMEM; } status = server_connect(pool->ctx, server, conn); if (status != DN_OK) { log_warn("connect to server '%.*s' failed, ignored: %s", server->pname.len, server->pname.data, strerror(errno)); server_close(pool->ctx, conn); } return DN_OK; }
static int run(void) { int ret = 0; if (!dst_addr) { ret = server_listen(); if (ret) return ret; } ret = dst_addr ? client_connect() : server_connect(); if (ret) { return ret; } run_test(); fi_shutdown(ep, 0); fi_close(&ep->fid); free_ep_res(); if (!dst_addr) free_lres(); fi_close(&dom->fid); fi_close(&fab->fid); return ret; }
struct conn * server_pool_conn(struct context *ctx, struct server_pool *pool, uint8_t *key, uint32_t keylen) { rstatus_t status; struct server *server; struct conn *conn; status = server_pool_update(pool); if (status != NC_OK) { return NULL; } /* from a given {key, keylen} pick a server from pool */ server = server_pool_server(pool, key, keylen); if (server == NULL) { return NULL; } /* pick a connection to a given server */ conn = server_conn(server); if (conn == NULL) { return NULL; } //log_error("tyson tyson tyson: %p", TAILQ_FIRST(&server->s_conn_q)); status = server_connect(ctx, server, conn); if (status != NC_OK) { server_close(ctx, conn); return NULL; } return conn; }
/*********************************************************************** * server_init_process * * Start the server and create the initial socket pair. */ void server_init_process(void) { obj_handle_t dummy_handle; const char *env_socket = getenv( "WINESERVERSOCKET" ); if (env_socket) { fd_socket = atoi( env_socket ); if (fcntl( fd_socket, F_SETFD, 1 ) == -1) fatal_perror( "Bad server socket %d", fd_socket ); unsetenv( "WINESERVERSOCKET" ); } else fd_socket = server_connect(); /* setup the signal mask */ sigemptyset( &server_block_set ); sigaddset( &server_block_set, SIGALRM ); sigaddset( &server_block_set, SIGIO ); sigaddset( &server_block_set, SIGINT ); sigaddset( &server_block_set, SIGHUP ); sigaddset( &server_block_set, SIGUSR1 ); sigaddset( &server_block_set, SIGUSR2 ); sigaddset( &server_block_set, SIGCHLD ); pthread_functions.sigprocmask( SIG_BLOCK, &server_block_set, NULL ); /* receive the first thread request fd on the main socket */ ntdll_get_thread_data()->request_fd = receive_fd( &dummy_handle ); #ifdef __APPLE__ send_server_task_port(); #endif }
struct conn * server_pool_conn(struct context *ctx, struct server_pool *pool, uint8_t *key, uint32_t keylen) { rstatus_t status; struct server *server; struct conn *conn; status = server_pool_update(pool); if (status != DN_OK) { return NULL; } /* from a given {key, keylen} pick a server from pool */ server = server_pool_server(pool, key, keylen); if (server == NULL) { return NULL; } /* pick a connection to a given server */ conn = server_conn(server); if (conn == NULL) { return NULL; } status = server_connect(ctx, server, conn); if (status != DN_OK) { server_close(ctx, conn); return NULL; } return conn; }
/* server connect <servertag> */ bool cfg_conf_server_connect(struct cfg_state *cmd, char *args) { int fields = countfields(args); char tag[25], var[25], val[1000]; struct server *srv; struct channel *ch; /* Add requires 1 variables */ if ( fields != 1 || !copyfield(args, 1, tag, sizeof(tag))) { sock_printf(cmd->sock, "400 The command is: server connect <servertag>\n"); return false; } srv = server_find_tag(tag); if (!srv) { sock_printf(cmd->sock, "400 Server '%s' does not exist\n"); return false; } server_connect(srv); sock_printf(cmd->sock, "200 Connecting to server\n"); return true; }
struct conn * sentinel_connect(struct context *ctx) { rstatus_t status; struct conn *conn; int cmd_num; int i; ASSERT(sentinel_status == SENTINEL_CONN_DISCONNECTED); /* get the only connect of sentinel */ conn = sentinel_conn(ctx->sentinel); if (conn == NULL) { return NULL; } status = server_connect(ctx, ctx->sentinel, conn); if(status != NC_OK) { sentinel_close(ctx, conn); return NULL; } cmd_num = sizeof(sentinel_req_cmds) / sizeof(char *); for (i = 0; i < cmd_num; i++) { status = req_construct(ctx, conn, sentinel_req_cmds[i]); if(status != NC_OK) { sentinel_close(ctx, conn); return NULL; } } sentinel_status = SENTINEL_CONN_SEND_REQ; return conn; }
static void reconnect_all(void) { GSList *list; SERVER_CONNECT_REC *conn; RECONNECT_REC *rec; /* first move reconnects to another list so if server_connect() fails and goes to reconnection list again, we won't get stuck here forever */ list = NULL; while (reconnects != NULL) { rec = reconnects->data; list = g_slist_append(list, rec->conn); server_connect_ref(rec->conn); server_reconnect_destroy(rec); } while (list != NULL) { conn = list->data; server_connect(conn); server_connect_unref(conn); list = g_slist_remove(list, conn); } }
static int run(void) { int ret = 0; addr_array = calloc(ep_cnt, sizeof(*addr_array)); if (!addr_array) { perror("malloc"); return -FI_ENOMEM; } if (hints->ep_attr->type == FI_EP_MSG) { if (!opts.dst_addr) { ret = ft_start_server(); if (ret) return ret; } ret = opts.dst_addr ? client_connect() : server_connect(); } else { ret = init_fabric(); } if (ret) return ret; ret = run_test(); /* TODO: Add a local finalize applicable to shared ctx */ //ft_finalize(fi, ep_array[0], txcq, rxcq, addr_array[0]); return ret; }
static int server_reconnect_timeout(void) { SERVER_CONNECT_REC *conn; GSList *list, *tmp; time_t now; /* If server_connect() removes the next reconnection in queue, we're screwed. I don't think this should happen anymore, but just to be sure we don't crash, do this safely. */ list = g_slist_copy(reconnects); now = time(NULL); for (tmp = list; tmp != NULL; tmp = tmp->next) { RECONNECT_REC *rec = tmp->data; if (g_slist_find(reconnects, rec) == NULL) continue; if (rec->next_connect <= now) { conn = rec->conn; server_reconnect_destroy(rec, FALSE); server_connect(conn); } } g_slist_free(list); return 1; }
int main(int argc, char* argv[]) { GtkWidget *window; GtkWidget *inc_button, *dec_button; GtkWidget *hbox1; GtkWidget *vbox1; GtkWidget *label1; pthread_t thread; long t = 0; serverConnected = 0; if (server_connect(1) == 1) { pthread_create(&thread, NULL, listener_thread, (void*)t); gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Opal6 ThingFabric Demo"); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_window_set_default_size(GTK_WINDOW(window), 250, 50); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(closeApp), NULL); dec_button = gtk_button_new_with_label(" DOWN "); g_signal_connect(G_OBJECT(dec_button), "clicked", G_CALLBACK(temp_button_clicked), "-"); inc_button = gtk_button_new_with_label(" UP "); g_signal_connect(G_OBJECT(inc_button), "clicked", G_CALLBACK(temp_button_clicked), "+"); label1 = gtk_label_new("Temperature"); tempLabel = gtk_label_new("25C"); publish_temp(temp); // send the initial value vbox1 = gtk_vbox_new(TRUE, 1); gtk_box_pack_start(GTK_BOX(vbox1), label1, TRUE, FALSE, 1); gtk_box_pack_start(GTK_BOX(vbox1), tempLabel, TRUE, FALSE, 1); hbox1 = gtk_hbox_new(TRUE, 5); gtk_box_pack_start(GTK_BOX(hbox1), dec_button, TRUE, FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox1), vbox1, TRUE, FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox1), inc_button, TRUE, FALSE, 5); gtk_container_add(GTK_CONTAINER(window), hbox1); gtk_widget_show_all(window); gtk_main(); } else { printf("Error: Unable to connect to ThingFabric server\n"); } return 0; }
s32 GetConnection(char * domain) { u32 ipaddress = getipbynamecached(domain); if(ipaddress == 0) { return -1; } s32 connection = server_connect(ipaddress, 80); return connection; }
int main(int argc, char **argv) { int op, ret; opts = INIT_OPTS; hints = fi_allocinfo(); if (!hints) return EXIT_FAILURE; while ((op = getopt(argc, argv, "h" ADDR_OPTS INFO_OPTS)) != -1) { switch (op) { default: ft_parse_addr_opts(op, optarg, &opts); ft_parseinfo(op, optarg, hints); break; case '?': case 'h': ft_usage(argv[0], "A simple MSG client-sever example that " "demonstrates one possible usage of the underlying " "cq wait objects."); return EXIT_FAILURE; } } if (optind < argc) opts.dst_addr = argv[optind]; hints->ep_attr->type = FI_EP_MSG; hints->caps = FI_MSG; hints->mode = FI_LOCAL_MR; hints->addr_format = FI_SOCKADDR; /* Fabric and connection setup */ if (!opts.dst_addr) { ret = server_listen(); if (ret) return -ret; } ret = opts.dst_addr ? client_connect() : server_connect(); if (ret) { return -ret; } /* Exchange data */ ret = send_recv(); fi_shutdown(ep, 0); free_ep_res(); fi_close(&cmeq->fid); fi_close(&dom->fid); fi_close(&fab->fid); return ret; }
/*********************************************************************** * server_init_process * * Start the server and create the initial socket pair. */ void server_init_process(void) { obj_handle_t version; const char *env_socket = getenv( "WINESERVERSOCKET" ); server_pid = -1; if (env_socket) { fd_socket = atoi( env_socket ); if (fcntl( fd_socket, F_SETFD, 1 ) == -1) fatal_perror( "Bad server socket %d", fd_socket ); unsetenv( "WINESERVERSOCKET" ); } else fd_socket = server_connect(); /* setup the signal mask */ sigemptyset( &server_block_set ); sigaddset( &server_block_set, SIGALRM ); sigaddset( &server_block_set, SIGIO ); sigaddset( &server_block_set, SIGINT ); sigaddset( &server_block_set, SIGHUP ); sigaddset( &server_block_set, SIGUSR1 ); sigaddset( &server_block_set, SIGUSR2 ); sigaddset( &server_block_set, SIGCHLD ); pthread_sigmask( SIG_BLOCK, &server_block_set, NULL ); /* receive the first thread request fd on the main socket */ #ifdef SO_PASSCRED if (server_pid == -1) { int enable = 1; setsockopt( fd_socket, SOL_SOCKET, SO_PASSCRED, &enable, sizeof(enable) ); ntdll_get_thread_data()->request_fd = receive_fd( &version ); enable = 0; setsockopt( fd_socket, SOL_SOCKET, SO_PASSCRED, &enable, sizeof(enable) ); } else #endif ntdll_get_thread_data()->request_fd = receive_fd( &version ); if (version != SERVER_PROTOCOL_VERSION) server_protocol_error( "version mismatch %d/%d.\n" "Your %s binary was not upgraded correctly,\n" "or you have an older one somewhere in your PATH.\n" "Or maybe the wrong wineserver is still running?\n", version, SERVER_PROTOCOL_VERSION, (version > SERVER_PROTOCOL_VERSION) ? "wine" : "wineserver" ); #ifdef __APPLE__ send_server_task_port(); #endif #if defined(__linux__) && defined(HAVE_PRCTL) /* work around Ubuntu's ptrace breakage */ if (server_pid != -1) prctl( 0x59616d61 /* PR_SET_PTRACER */, server_pid ); #endif }
int main(int argc, char *argv[]) { if(argc < 2 || argc > 4) { printf("\n Usage: %s port [a|b] [name] \n",argv[0]); return 1; } sockfd = server_connect(argv[1]); if (sockfd < 0) { // something happened while trying to connect-- abort mission return -1; } parse_settings(argv[2], argv[3]); printf("Request name %s and team %d\n", name, team); //construct proper sendBuff //(name, team) snprintf(sendBuff, sizeof sendBuff, "%s %d", name, team); // send it send_to_server(); // read reply read_from_server(); //printf("Bytes written: %d. Bytes read: %d.\n%s\n", writtenbytes, readbytes, recvBuff); sscanf(recvBuff, "%s", recvName); printf("%s\n", recvBuff); char *ghs = "Game has already started"; if(strcmp(ghs, recvBuff) == 0){ close(sockfd); return 0; } initscr(); loading_screen(); display_teams(); start_color(); initscr(); loadMap(mapNameFromServer); teamInfoMap(); initBoard();/* creates play board */ refresh();/* Print it on to the real screen */ load_players(); //place_players(); control_test(); final_standings(); getch(); endwin(); close(sockfd); return 0; }
int main(int ac, char **av) { t_env env; if (ac < 3) ft_exit("client: invalid arguments\nclient <host> <port>" , EXIT_FAILURE); parse_arguments(&env, av); resolve_host(&env); server_connect(&env); run(&env); }
static int check_reconnect(server *s, time_t t) { /* Check if the server is in auto-reconnect mode, and issue a reconnect if needed */ if (s->reconnect_time && t > s->reconnect_time) { server_connect(s->host, s->port); return 1; } return 0; }
static void sserver_connect(SERVER_SETUP_REC *rec, SERVER_CONNECT_REC *conn) { conn->address = g_strdup(rec->address); if (conn->port == 0) conn->port = rec->port; server_setup_fill_reconn(conn, rec); if (rec->last_connect > time(NULL)-reconnect_time) { /* can't reconnect this fast, wait.. */ server_reconnect_add(conn, rec->last_connect+reconnect_time); } else { /* connect to server.. */ server_connect(conn); } }
PageResponse* server_forward_page_request(int client, PageRequest *request, ClientEntry* owner) { int clientWithPageSocket = server_connect(owner->forwardIpAddress, owner->forwardPort); char logMessage[100]; sprintf(logMessage, "Forwarding request to %s:%d", owner->forwardIpAddress, owner->forwardPort); logger_log_message(logMessage, INFO); char message[MAXDATASIZE]; int buffer1 = 0; int buffer2 = 0; long buffer3 = 0; sprintf( message, REQ_FORMAT, GET, PAGE, request->nodeId, request->ownershipOnly, request->readOnlyMode, request->pageNumber ); send(clientWithPageSocket, message, strlen(message), 0); recv(clientWithPageSocket, message, MAXDATASIZE, 0); PageResponse* response = (PageResponse*) malloc(sizeof(PageResponse)); sscanf( message, RES_FORMAT, &response->errorCode, &buffer1, &buffer2, &buffer3, response->pageContents ); // requesting not only ownership and no error if (!request->ownershipOnly && response->errorCode == 0) { char *contentBeforePage = strchr(message, '&'); memcpy(response->pageContents, contentBeforePage + 1, getpagesize()); } printf("Closing socket: %d\n", clientWithPageSocket); shutdown(clientWithPageSocket, SHUT_RDWR); close(clientWithPageSocket); return response; }
int main(int argc, char **argv) { #ifdef HAVE_LIBDMALLOC if (!getenv("DMALLOC_OPTIONS")) dmalloc_debug(0x2f03d00); #endif interactive = isatty(0); parse_args(argc, argv); cmd_build_tree(); server_connect(); select_loop(); return 0; }
EAPI Eina_Bool evas_cserve_init(void) { csrve_init++; if (cserve) return 1; cserve = server_connect(); if (!cserve) return 0; if (!server_init(cserve)) { if (cserve) server_disconnect(cserve); cserve = NULL; return 0; } return 1; }
static void server_reinit(void) { if (cserve) return; if (cserve_discon) return; cserve = server_connect(); if (cserve) { if (!server_init(cserve)) { if (cserve) server_disconnect(cserve); cserve = NULL; } } }
int TCP_Helper::server_open_endpoints(__u8* eps,__u8 num_eps,int timeout) { int i; struct pollfd* poll_connections=NULL; __u8* poll_idxs=NULL; int poll_count=0; int poll_idx=0; for (i=0;i<num_eps;i++) { int idx=(eps[i]&0x80)?(eps[i]&0xf)|0x10:eps[i]; if (!ep_connect[idx]) { if (!ep_listener[idx]) { fprintf(stderr,"Listening EP%02x\n",eps[i]); server_listen(idx); } poll_count++; } } poll_connections=(struct pollfd*)calloc(poll_count,sizeof(struct pollfd)); poll_idxs=(__u8*)calloc(poll_count,sizeof(__u8)); for (i=0;i<num_eps;i++) { int idx=(eps[i]&0x80)?(eps[i]&0xf)|0x10:eps[i]; if (!ep_connect[idx]) { TRACE3(i,idx,ep_listener[idx]) poll_connections[poll_idx].fd=ep_listener[idx]; poll_connections[poll_idx].events=POLLIN; poll_idxs[poll_idx]=idx; poll_idx++; } } int ep_count=poll_count; int rc=-1; TRACE1(poll_count) if (poll(poll_connections,poll_count,timeout)) { TRACE for (poll_idx=0;poll_idx<poll_count;poll_idx++) { TRACE1(poll_idx) if (poll_connections[poll_idx].revents==POLLIN) { int idx=poll_idxs[poll_idx]; if (server_connect(idx,0)==0) { fprintf(stderr,"Connected EP%02x\n",(idx&0xf) | ((idx&0x10)<<3)); ep_buf[idx] = (__u8*) malloc(TCP_BUFFER_SIZE); ep_count--; } } } rc=ep_count; } else {
static int run(void) { int i, ret = 0; if (!opts.dst_addr) { ret = server_listen(); if (ret) return ret; } ret = opts.dst_addr ? client_connect() : server_connect(); if (ret) return ret; ret = exchange_addr_key(); if (ret) return ret; if (!(opts.user_options & FT_OPT_SIZE)) { for (i = 0; i < TEST_CNT; i++) { if (test_size[i].option > opts.size_option) continue; opts.transfer_size = test_size[i].size; init_test(&opts, test_name, sizeof(test_name)); ret = run_test(); if (ret) goto out; } } else { init_test(&opts, test_name, sizeof(test_name)); ret = run_test(); if (ret) goto out; } sync_test(); wait_for_data_completion(scq, max_credits - credits); /* Finalize before closing ep */ ft_finalize(ep, scq, rcq, FI_ADDR_UNSPEC); out: fi_shutdown(ep, 0); free_ep_res(); if (!opts.dst_addr) free_lres(); fi_close(&dom->fid); fi_close(&fab->fid); return ret; }
int browser_add(struct tpe *tpe, const char *servername){ struct browser *browser; struct bserver *bserver; browser = calloc(1,sizeof(struct browser)); bserver = calloc(1,sizeof(struct bserver)); bserver->name = strdup("localhost"); bserver->next = browser->servers; bserver->browser = browser; browser->servers = bserver; bserver->server = server_connect(tpe, "localhost", 6923, 0, browser_socket_connect, bserver); return 0; }
static int run(void) { int i, ret = 0; ret = opts.dst_addr ? client_connect() : server_connect(); if (ret) return ret; if (!(opts.user_options & FT_OPT_SIZE)) { for (i = 0; i < TEST_CNT; i++) { if (test_size[i].option > opts.size_option) continue; opts.transfer_size = test_size[i].size; init_test(&opts, test_name, sizeof(test_name)); ret = run_test(); if (ret) goto out; } } else { init_test(&opts, test_name, sizeof(test_name)); ret = run_test(); if (ret) goto out; } while (credits < max_credits) poll_all_sends(); ft_finalize(ep, scq, rcq, remote_fi_addr); out: free_ep_res(); ret = fi_close(&av->fid); if (ret != 0) { FT_PRINTERR("fi_close", ret); } ret = fi_close(&dom->fid); if (ret != 0) { FT_PRINTERR("fi_close", ret); } ret = fi_close(&fab->fid); if (ret != 0) { FT_PRINTERR("fi_close", ret); } return ret; }