int main (int argc, char **argv) { gsk_init_without_threads (&argc, &argv); g_printerr ("TCP/IP server/client... "); addr = gsk_socket_address_ipv4_localhost (10306); create_server (addr); client_count = 0; create_client (addr); while (!done_test) gsk_main_loop_run (gsk_main_loop_default(), -1, NULL); g_object_unref (listener); listener = NULL; g_object_unref (addr); addr = NULL; g_printerr (" done.\n"); client_count = 0; done_test = FALSE; g_printerr ("Local-socket server/client... "); #define TEST_LOCAL_SOCKET_FNAME "./test-socket-sc" addr = gsk_socket_address_local_new (TEST_LOCAL_SOCKET_FNAME); create_server (addr); client_count = 0; create_client (addr); while (!done_test) gsk_main_loop_run (gsk_main_loop_default(), -1, NULL); g_object_unref (listener); g_object_unref (addr); g_printerr (" done.\n"); return 0; }
static void scan_wins(void) { int i; uint num; XWindow *wins; XWindowAttributes wa; XWindow d1, d2; if(XQueryTree(display, scr.root.w, &d1, &d2, &wins, &num)) { for(i = 0; i < num; i++) { if(!XGetWindowAttributes(display, wins[i], &wa)) continue; if(wa.override_redirect || XGetTransientForHint(display, wins[i], &d1)) continue; if(wa.map_state == IsViewable) create_client(wins[i], &wa); } for(i = 0; i < num; i++) { if(!XGetWindowAttributes(display, wins[i], &wa)) continue; if((XGetTransientForHint(display, wins[i], &d1)) && (wa.map_state == IsViewable)) create_client(wins[i], &wa); } } if(wins) XFree(wins); }
/* work starts here */ int main (int argc, char **argv) { int rc; /* * allocate options structure * and parse command line */ if(parse_arguments(argc, argv) != GM_OK) { print_usage(); exit( STATE_UNKNOWN ); } /* set logging */ mod_gm_opt->debug_level = GM_LOG_INFO; mod_gm_opt->logmode = GM_LOG_MODE_TOOLS; /* init crypto functions */ if(mod_gm_opt->encryption == GM_ENABLED) { mod_gm_crypt_init(mod_gm_opt->crypt_key); } else { mod_gm_opt->transportmode = GM_ENCODE_ONLY; } /* create client */ if ( create_client( mod_gm_opt->server_list, &client ) != GM_OK ) { printf( "send_gearman UNKNOWN: cannot start client\n" ); exit( STATE_UNKNOWN ); } current_client = &client; /* create duplicate client */ if ( mod_gm_opt->dupserver_num > 0 ) { if ( create_client( mod_gm_opt->dupserver_list, &client_dup ) != GM_OK ) { printf( "send_gearman UNKNOWN: cannot start client for duplicate server\n" ); exit( STATE_UNKNOWN ); } } current_client_dup = &client_dup; /* send result message */ signal(SIGALRM, alarm_sighandler); rc = send_result(); gearman_client_free( &client ); if( mod_gm_opt->dupserver_num ) gearman_client_free( &client_dup ); mod_gm_free_opt(mod_gm_opt); exit( rc ); }
int main(int argc, char *argv[]) { client_t *c; c = create_client(argv[0]); if (c == NULL) { fprintf(stderr, "Failed to create client."); exit(1); } parse_cmdline(c, argc, &argv[0]); create_mainloop(c); setup_signals(c); setup_input(c); if (c->glib) print(c, "Using GMainLoop..."); else print(c, "Using pa_manloop..."); run_mainloop(c); cleanup_input(c); destroy_client(c); return 0; }
int main(int ac, char **av) { if (ac == 1 || ac > 3) { printf("USAGE : ./client machine [port]\n"); exit(0); } if (ac == 2) { printf("You try to connect on default port 4242\n"); create_client(av[1], "4242"); } else create_client(av[1], av[2]); return (0); }
int main(int argc, char *argv[]) { if (argc < 3) { usage(); } if (getenv("NOPOLL_TEST_DEBUG")) debug_local = 1; if (getenv("NOPOLL_TEST_DEBUG_NOPOLL")) debug_nopoll = 1; if (strcmp(argv[1], "server") == 0) { return create_listener(argv[2]); } else if (strcmp(argv[1], "client") == 0) { if (argc < 6) usage(); instanceID = strdup(argv[2]); const char * host = argv[3]; const char * port = argv[4]; int duration = atoi(argv[5]); if (duration <= 0) { printf("Duration should be greater than 0 seconds.\n"); usage(); } return create_client(host, port, duration); } else { printf("First argument should be \"server\" or \"client\"\n"); exit(1); } }
int main(int argc, char **argv) { int port; int sock; char *input; char *buf; int r; if (argc != 3) { printf("Usage: %s <addr> <port>\n", argv[0]); return (-1); } port = atoi(argv[2]); sock = create_client(argv[1], port); while (42) { ft_putstr("$> "); if (get_next_line(1, &input)) exec_input(input, sock); while ((r = recv(sock, buf, 1023, 0)) > 0) { buf[r] = '\0'; ft_putstr_fd(buf, 2); } } close(sock); return (0); }
/**launch handler for each incoming connection. */ static void start_child(ICI *d, int fd, char *rh, unsigned short rp) { pthread_mutex_lock(&d->lock); d->num_clients++; if (d->num_clients > d->max_clients) d->max_clients = d->num_clients; pthread_mutex_unlock(&d->lock); CONN *c = calloc(1, sizeof(CONN)); c->run = 1; c->fd = fd; c->d = d; c->client_address = strdup(rh); c->client_port = rp; #ifdef SOCKET_WRITE c->cq = NULL; #endif c->userdata = NULL; if(create_client(&socket_handler, c)) { if(fd >= 0) #ifndef HAVE_WINDOWS close(fd); #else closesocket(fd); #endif dlog(DLOG_ERR, "SRV: Protocol handler child fork failed\n"); pthread_mutex_lock(&d->lock); d->num_clients--; pthread_mutex_unlock(&d->lock); free(c); debugmsg(DEBUG_SRV, "SRV: Connection terminated: now %i connections active\n", d->num_clients); return; } debugmsg(DEBUG_SRV, "SRV: Connection started: now %i connections active\n", d->num_clients); }
void serve(int serverfd) { int maxfd = 0; struct sockaddr_in addr; socklen_t addrlen = sizeof(struct sockaddr_in); struct timeval timeout; memset(&addr, 0, sizeof(struct sockaddr_in)); while(1) { fd_set fds; FD_ZERO(&fds); FD_SET(serverfd, &fds); if(serverfd >= maxfd) maxfd = serverfd + 1; timeout.tv_sec = 5; timeout.tv_usec = 0; /* listen for new clients */ if(select(maxfd, &fds, NULL, NULL, &timeout) > 0 && FD_ISSET(serverfd, &fds)) { int clientfd = accept(serverfd, (struct sockaddr *) &addr, &addrlen); if(clientfd == -1) { perror("accept()"); continue; } create_client(clientfd, &addr, &addrlen); } reap_messages(); } }
void Avahi::PresencePublisher::client_callback (AvahiClient* client_, AvahiClientState state) { if (client_ == NULL) return; client = client_; switch (state) { case AVAHI_CLIENT_FAILURE: if (avahi_client_errno (client) == AVAHI_ERR_DISCONNECTED) { free_client (); create_client (); } break; case AVAHI_CLIENT_S_RUNNING: register_services (); break; case AVAHI_CLIENT_S_REGISTERING: case AVAHI_CLIENT_S_COLLISION: case AVAHI_CLIENT_CONNECTING: default: break; // nothing } }
/** * Allows to start the translation process */ inline void start() { //Define and initialize the attempt counter size_t attempt = 0; //Make several re-connection attempts while (true) { //Create a new client create_client(); LOG_INFO1 << "Attempting to connect to the server!" << END_LOG; if (m_client->connect()) { LOG_INFO << "Starting creating and sending out " << m_name << " jobs!" << END_LOG; //Run the translation job sending thread m_sending_thread_ptr = new thread(bind(&client_manager::send_requests, this)); //Stop the loop as we did connect. break; } else { if (attempt >= MAX_NUM_CONNECTION_ATTEMPTS) { THROW_EXCEPTION(string("Tried ") + to_string(attempt) + string(" times but could not open the connection to: ") + m_uri); } else { LOG_INFO2 << "Could not connect, attempt: " << attempt << "/" << MAX_NUM_CONNECTION_ATTEMPTS << ", timeout: " << RE_CONNECTION_TIME_OUT_MILLISEC << " milliseconds" << END_LOG; //Increment the attempts counter ++attempt; //Sleep some time before trying to re-connect std::this_thread::sleep_for(std::chrono::milliseconds(RE_CONNECTION_TIME_OUT_MILLISEC)); } } } }
static bool_t IDCCallback_Bound_m ( IDCCallback_cl *self, IDCOffer_clp offer /* IN */, IDCServerBinding_clp binding /* IN */, Domain_ID dom /* IN */, ProtectionDomain_ID pdid /* IN */, const Binder_Cookies *clt_cks /* IN */, Type_Any *server /* INOUT */ ) { ext2fs_st *st = self->st; Client_st *c; /* A client has finished binding. We need to invent a server. */ TRC(printf("ext2fs: accepted connection from dom %qx\n",dom)); c=Heap$Malloc(st->heap, sizeof(*c)); if (!c) { printf("ext2fs: out of memory while accepting connection from %qx\n", dom); return False; } if (!create_client(st,c,binding)) { printf("ext2fs: aargh, client create failed. Rejecting connection.\n"); FREE(c); return False; } /* XXX: concurrency? */ LINK_ADD_TO_HEAD(&st->client.clients, c); ANY_INIT(server, Ext2_clp, &c->cl); return True; }
int main(int argc, char **argv) { CLIENT client_struct, *c; FLICK_SERVER_LOCATION s; int sel, done; c = &client_struct; if (argc != 2) { fprintf(stderr, "Usage: %s <host>\n", argv[0]); exit(1); } s.server_name = argv[1]; s.prog_num = netphone; s.vers_num = firstphone; create_client(c, s); done = 0; while (!done) { read_integer(("\n(1) Add an entry (2) Remove an entry " "(3) Find a phone number (4) Exit: "), &sel); switch(sel) { case 1: add_entry(c); break; case 2: remove_entry(c); break; case 3: find_entry(c); break; case 4: done = 1; break; default: printf("Please enter 1, 2, 3, or 4.\n"); } } return 0; }
void virtual_stream_create(const char * type, const char * context_id, size_t buf_len, unsigned access, VirtualStreamCallBack * callback, void * callback_args, VirtualStream ** res) { LINK * l; VirtualStream * stream = loc_alloc_zero(sizeof(VirtualStream)); buf_len++; list_init(&stream->clients); strncpy(stream->type, type, sizeof(stream->type) - 1); stream->magic = STREAM_MAGIC; stream->id = id_cnt++; stream->access = access; stream->callback = callback; stream->callback_args = callback_args; stream->ref_cnt = 1; stream->buf = loc_alloc(buf_len); stream->buf_len = buf_len; for (l = subscriptions.next; l != &subscriptions; l = l->next) { Subscription * h = all2subscription(l); if (strcmp(type, h->type) == 0) { Trap trap; create_client(stream, h->channel); if (set_trap(&trap)) { send_event_stream_created(&h->channel->out, stream, context_id); clear_trap(&trap); } else { trace(LOG_ALWAYS, "Exception sending stream created event: %d %s", trap.error, errno_to_str(trap.error)); } } } list_add_first(&stream->link_all, &streams); *res = stream; }
static void test_pending_calls(size_t concurrent_calls) { size_t i; grpc_call **calls; grpc_channel *client; request_data rdata; servers_fixture *f; test_spec *spec = test_spec_create(0, 4); rdata.call_details = gpr_malloc(sizeof(grpc_call_details) * spec->num_servers); f = setup_servers("127.0.0.1", &rdata, spec->num_servers); client = create_client(f); calls = perform_multirequest(f, client, concurrent_calls); grpc_call_cancel( calls[0], NULL); /* exercise the cancel pick path whilst there are pending picks */ gpr_free(rdata.call_details); grpc_channel_destroy(client); /* calls the LB's shutdown func */ /* destroy the calls after the channel so that they are still around for the * LB's shutdown func to process */ for (i = 0; i < concurrent_calls; i++) { grpc_call_destroy(calls[i]); } gpr_free(calls); teardown_servers(f); test_spec_destroy(spec); }
int main(int ac, char **av) { t_client all_c; struct hostent *hp; struct in_addr **addr_list; if (ac != 3) ft_error_client(USG, av[0]); if ((hp = gethostbyname(av[1])) == NULL) { ft_putendl("\033[1;31m-- Connect to the server ERROR --\033[00m"); exit(2); } addr_list = (struct in_addr **)hp->h_addr_list; ft_init_client(&all_c, av, inet_ntoa(*addr_list[0])); create_client(inet_ntoa(*addr_list[0]), &all_c); while (all_c.quit == 0 && ft_put_prompt(&all_c)) { if (get_next_line(0, &(all_c).line) > 0) { brain_client(&all_c); free(all_c.line); } } close(all_c.sock); return (0); }
int main(int argc, char **argv) { t_client clt; char *line; char *addr; if (argc != 3) usage_client(argv[0]); clt.port = atoi(argv[2]); printf("port : %d \n", clt.port); if ((addr = get_addr(argv[1])) == NULL) usage_client(argv[0]); clt.sock = create_client(addr, clt.port); clt.home = getcwd(NULL, 0); while (1) { ft_putstr("Plait-il ?>"); get_next_line(0, &line); hub_client(line, clt); free(line); line = NULL; } close(clt.sock); return (0); }
void device::work() { load_options(); create_client(); delegate_all(); initialize_device(); }
int main(int argc, char **argv) { int optidx = 0; setprogname (argv[0]); if (getarg (args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx)) usage (1); if (help_flag) usage (0); if (version_flag) { print_version (NULL); return 0; } if (optidx != argc) usage (1); if (port_str) { char *ptr; port = strtol (port_str, &ptr, 10); if (port == 0 && ptr == port_str) errx (1, "Bad port `%s'", port_str); } krb5_init_context(&context); { const char *lf = logfile_str; if (lf == NULL) lf = "/dev/tty"; logfile = fopen(lf, "w"); if (logfile == NULL) err(1, "error opening %s", lf); } mini_inetd(htons(port), NULL); fprintf(logfile, "connected\n"); { struct client *c; c = create_client(0, port, moniker_str); /* close(0); */ handleServer(c); free_client(c); } krb5_free_context(context); return 0; }
int inetget_main(const int argc, const wchar_t *const argv[]) { //Print application info print_logo(); //Initialize parameters Params params; //Load configuration file, if it exists const std::wstring config_file = Utils::exe_path(L".cfg"); if(Utils::file_exists(config_file)) { if(!params.load_conf_file(config_file)) { std::wcerr << "Invalid configuration file, refer to the documentation for details!\n" << std::endl; return EXIT_FAILURE; } } //Parse command-line parameters if(!params.parse_cli_args(argc, argv)) { std::wcerr << "Invalid command-line arguments, type \"INetGet.exe --help\" for details!\n" << std::endl; return EXIT_FAILURE; } //Show help screen, if it was requested if(params.getShowHelp()) { print_help_screen(); return EXIT_SUCCESS; } //Parse the specified source URL const std::wstring source = (params.getSource().compare(L"-") == 0) ? Utils::utf8_to_wide_str(stdin_get_line()) : params.getSource(); URL url(source); if(!url.isComplete()) { std::wcerr << "The specified URL is incomplete or unsupported:\n" << source << L'\n' << std::endl; return EXIT_FAILURE; } //Print request URL const std::wstring url_string = url.toString(); std::wcerr << L"Request address:\n" << url.toString() << L'\n' << std::endl; Utils::set_console_title(std::wstring(L"INetGet - ").append(url_string)); //Create the HTTP(S) client std::unique_ptr<AbstractClient> client; StatusListener listener; if(!create_client(client, listener, url.getScheme(), params)) { std::wcerr << "Specified protocol is unsupported! Only HTTP(S) and FTP are allowed.\n" << std::endl; return EXIT_FAILURE; } //Retrieve the URL return retrieve_url(client.get(), url_string, params.getHttpVerb(), url, params.getPostData(), params.getReferrer(), params.getOutput(), params.getSetTimestamp(), params.getUpdateMode(), params.getEnableAlert(), params.getKeepFailed()); }
/* open new ports, update fds */ int bind_ports(void) { SERVICE_OPTIONS *opt; char *local_address; #ifdef USE_LIBWRAP /* execute after parse_commandline() to know service_options.next, * but as early as possible to avoid leaking file descriptors */ /* retry on each bind_ports() in case stunnel.conf was reloaded without "libwrap = no" */ libwrap_init(); #endif /* USE_LIBWRAP */ s_poll_init(fds); s_poll_add(fds, signal_pipe[0], 1, 0); /* allow clean unbind_ports() even though bind_ports() was not fully performed */ for(opt=service_options.next; opt; opt=opt->next) if(opt->option.accept) opt->fd=-1; for(opt=service_options.next; opt; opt=opt->next) { if(opt->option.accept) { opt->fd=s_socket(opt->local_addr.sa.sa_family, SOCK_STREAM, 0, 1, "accept socket"); if(opt->fd<0) return 1; if(set_socket_options(opt->fd, 0)<0) { closesocket(opt->fd); return 1; } /* local socket can't be unnamed */ local_address=s_ntop(&opt->local_addr, addr_len(&opt->local_addr)); if(bind(opt->fd, &opt->local_addr.sa, addr_len(&opt->local_addr))) { s_log(LOG_ERR, "Error binding service [%s] to %s", opt->servname, local_address); sockerror("bind"); closesocket(opt->fd); str_free(local_address); return 1; } if(listen(opt->fd, SOMAXCONN)) { sockerror("listen"); closesocket(opt->fd); str_free(local_address); return 1; } s_poll_add(fds, opt->fd, 1, 0); s_log(LOG_DEBUG, "Service [%s] (FD=%d) bound to %s", opt->servname, opt->fd, local_address); str_free(local_address); } else if(opt->option.program && opt->option.remote) { /* create exec+connect services */ create_client(-1, -1, alloc_client_session(opt, -1, -1), client_thread); } } return 0; /* OK */ }
static void gst_multiudpsink_add_internal (GstMultiUDPSink * sink, const gchar * host, gint port, gboolean lock) { GstUDPClient *client; GstUDPClient udpclient; GTimeVal now; GList *find; udpclient.host = (gchar *) host; udpclient.port = port; GST_DEBUG_OBJECT (sink, "adding client on host %s, port %d", host, port); if (lock) g_mutex_lock (&sink->client_lock); find = g_list_find_custom (sink->clients, &udpclient, (GCompareFunc) client_compare); if (find) { client = (GstUDPClient *) find->data; GST_DEBUG_OBJECT (sink, "found %d existing clients with host %s, port %d", client->refcount, host, port); client->refcount++; } else { client = create_client (sink, host, port); if (!client) goto error; g_get_current_time (&now); client->connect_time = GST_TIMEVAL_TO_TIME (now); if (sink->used_socket) gst_multiudpsink_configure_client (sink, client); GST_DEBUG_OBJECT (sink, "add client with host %s, port %d", host, port); sink->clients = g_list_prepend (sink->clients, client); } if (lock) g_mutex_unlock (&sink->client_lock); g_signal_emit (G_OBJECT (sink), gst_multiudpsink_signals[SIGNAL_CLIENT_ADDED], 0, host, port); GST_DEBUG_OBJECT (sink, "added client on host %s, port %d", host, port); return; /* ERRORS */ error: { GST_DEBUG_OBJECT (sink, "did not add client on host %s, port %d", host, port); if (lock) g_mutex_unlock (&sink->client_lock); return; } }
/** * Creates a new client connection. * * The method does not establishes real bluetooth connection * just creates a client connection instance. * * @param authenticate JAVACALL_TRUE if authication is required * @param encrypt JAVACALL_TRUE if required to be encrypted * @param master JAVACALL_TRUE if required to be a connection's master * @param pHandle pointer to connection handle variable, * new connection handle returned in result. * @retval JAVACALL_OK on success, * @retval JAVACALL_FAIL on error */ javacall_result javacall_bt_rfcomm_create_client( javacall_bool authenticate, javacall_bool encrypt, javacall_bool master, /*OUT*/javacall_handle* pHandle) { return create_client(RFCOMM, -1, -1, authenticate, encrypt, master, pHandle); }
/* work starts here */ int main (int argc, char **argv) { int rc; /* * allocate options structure * and parse command line */ if(parse_arguments(argc, argv) != GM_OK) { print_usage(); exit( STATE_UNKNOWN ); } /* set logging */ mod_gm_opt->debug_level = GM_LOG_INFO; mod_gm_opt->logmode = GM_LOG_MODE_TOOLS; /* init crypto functions */ if(mod_gm_opt->encryption == GM_ENABLED) { mod_gm_crypt_init(mod_gm_opt->crypt_key); } else { mod_gm_opt->transportmode = GM_ENCODE_ONLY; } /* create client */ if ( create_client( mod_gm_opt->server_list, &client ) != GM_OK ) { printf( "send_multi UNKNOWN: cannot start client\n" ); exit( STATE_UNKNOWN ); } /* create duplicate client */ if ( create_client_dup( mod_gm_opt->dupserver_list, &client_dup ) != GM_OK ) { printf( "send_multi UNKNOWN: cannot start client for duplicate server\n" ); exit( STATE_UNKNOWN ); } /* send result message */ signal(SIGALRM, alarm_sighandler); rc = read_multi_stream(stdin); /* if rc > 0, it contains the number of checks being submitted, otherwise its an error code (-1 - WARNING, -2 - CRITICAL, -3 - UNKNOWN) */ if (rc == 0) { printf( "send_multi UNKNOWN: %d check_multi child checks submitted\n", rc ); rc=STATE_UNKNOWN; } else if (rc > 0) { printf( "send_multi OK: %d check_multi child check%s submitted\n", rc, (rc>1)?"s":"" ); rc=STATE_OK; } else { rc*=-1; } gearman_client_free( &client ); if( mod_gm_opt->dupserver_num ) gearman_client_free( &client_dup ); mod_gm_free_opt(mod_gm_opt); exit( rc ); }
NTSTATUS pipe_container_t::open( object_t *&out, open_info_t& info ) { dprintf("allocating pipe client = %pus\n", &info.path ); pipe_client_t *pipe = 0; NTSTATUS r = create_client( pipe ); if (r < STATUS_SUCCESS) return r; out = pipe; return r; }
void create_modules() { ok(create_client( mod_gm_opt->server_list, &client ) == GM_OK, "created test client"); ok(create_worker( mod_gm_opt->server_list, &worker ) == GM_OK, "created test worker"); ok(worker_add_function( &worker, GM_DEFAULT_RESULT_QUEUE, get_results ) == GM_OK, "added result worker"); ok(worker_add_function( &worker, "dummy", dummy ) == GM_OK, "added dummy worker"); //gearman_worker_add_options(&worker, GEARMAN_WORKER_NON_BLOCKING); gearman_worker_set_timeout(&worker, 5000); return; }
int virtual_stream_connect(Channel * c, char * token, char * id) { int err = 0; if (find_client(id, c) == NULL) { VirtualStream * stream = virtual_stream_find(id); if (stream == NULL) err = errno; else create_client(stream, c); } return err == 0 ? 0 : -1; }
static void create_missing_clients(client *c) { int n = 0; while (conf.live_clients < conf.num_clients) { create_client(c->obuf, sdslen(c->obuf)); /* listen backlog is quite limited on most system */ if (++n > 64) { usleep(50000); n = 0; } } }
int begin_client(int ac, char **av) { int port; int sock; if (ac != 3) usage(av[0]); port = ft_atoi(av[2]); sock = create_client(av[1], port); return (sock); }
Avahi::PresencePublisher::PresencePublisher (Ekiga::ServiceCore& core_, Ekiga::PersonalDetails& details_, Ekiga::CallCore& call_core_): core(core_), details(details_), call_core(call_core_), client(NULL), group(NULL) { display_name = details.get_display_name (); details.updated.connect (boost::bind (&Avahi::PresencePublisher::on_details_updated, this)); name = avahi_strdup (display_name.c_str ()); glib_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); create_client (); }