int AccountService::run(int port) { if (soap_valid_socket(this->master) || soap_valid_socket(bind(NULL, port, 100))) { for (;;) { if (!soap_valid_socket(accept()) || serve()) return this->error; soap_destroy(this); soap_end(this); } } else return this->error; return SOAP_OK; }
int WSHttpBinding_USCOREINWNMasterServerAPIService::run(int port) { if (soap_valid_socket(this->master) || soap_valid_socket(bind(NULL, port, 100))) { for (;;) { if (!soap_valid_socket(accept()) || serve()) return this->error; soap_destroy(this); soap_end(this); } } else return this->error; return SOAP_OK; }
int AdvancedSecurityServiceBindingService::run(int port) { if (soap_valid_socket(this->soap->master) || soap_valid_socket(bind(NULL, port, 100))) { for (;;) { if (!soap_valid_socket(accept()) || serve()) return this->soap->error; soap_destroy(this->soap); soap_end(this->soap); } } else return this->soap->error; return SOAP_OK; }
int BasicHttpBinding_USCOREICalculatorService::run(int port) { if (soap_valid_socket(this->soap->master) || soap_valid_socket(bind(NULL, port, 100))) { for (;;) { if (!soap_valid_socket(accept()) || serve()) return this->soap->error; soap_destroy(this->soap); soap_end(this->soap); } } else return this->soap->error; return SOAP_OK; }
void test_get_query (void) { const gchar *uri; GHashTable *query; uri = serve(client); query = gcut_take_new_hash_table_string_string("name", "value", NULL); soupcut_client_get(client, uri, "name", "value", NULL); gcut_assert_equal_hash_table_string_string(query, received_query); }
/* Code executed by the client */ void *client_run(void *arg) { client_t *client = (client_t *) arg; /* main loop of the client: fetch commands from window, interpret * and handle them, return results to window. */ char command[256]; char response[256] = { 0 }; /* response must be null for the first call to serve */ serve(client->win, response, command); while (handle_command(command, response, sizeof(response))) { pthread_mutex_lock(&run_lock); while( run_threads == 0 ){ pthread_cond_wait(&ready_to_run, &run_lock); } pthread_mutex_unlock(&run_lock); serve(client->win, response, command); } client_destroy(client); return 0; }
void *thread (void *vargp) { thread_args args; args = *((thread_args *) vargp); Pthread_detach(pthread_self()); // handle segment fault: it is sometimes weird Signal(SIGSEGV, sigsegv_handler); // Valar Dohaeris serve(args.fd); // Valar Morghulis Close(args.fd); Free(vargp); return NULL; }
dword SioTcps::Worker(void) { SOCKET so = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (so == INVALID_SOCKET) { dword dw = WSAGetLastError(); trace("socket: %d [%08X]\n", dw, dw); return dw; } SOCKADDR_IN sin; sin.sin_family = AF_INET; sin.sin_port = htons(port); sin.sin_addr.S_un.S_addr = 0; if (bind(so, (SOCKADDR *)&sin, sizeof(sin)) != 0) { dword dw = WSAGetLastError(); trace("bind: %d [%08X]\n", dw, dw); return dw; } if (listen(so, SOMAXCONN) != 0) { dword dw = WSAGetLastError(); trace("listen: %d [%08X]\n", dw, dw); return dw; } do { trace("Kronos server is accepting connections...\n"); SOCKADDR_IN sinClient; int sinLen = sizeof(sinClient); dword soClient = accept(so, (SOCKADDR *)&sinClient, &sinLen); if (soClient != INVALID_SOCKET) { trace("Connection from %d.%d.%d.%d\n", sinClient.sin_addr.S_un.S_un_b.s_b1, sinClient.sin_addr.S_un.S_un_b.s_b2, sinClient.sin_addr.S_un.S_un_b.s_b3, sinClient.sin_addr.S_un.S_un_b.s_b4); serve(soClient); } } while (sin.sin_addr.S_un.S_addr == 0); // John - you never get here. // May be you need shutdown() same as in IGD480 trace("Kronos server exiting...\n"); closesocket(so); return 0; }
int main(int argc, char** argv) { char *eth, *ip1, *ip2; if (argc < 2) { printf("No www directory found\nUsage: %s wwwdir\n", argv[0]); return 1; } if (chdir(argv[1]) < 0) { printf("Could not change dir to '%s'\n", argv[1]); return 1; } eth = getenv("ETH"); if (!eth) { printf("The ETH environment variable must be set!\n"); return 1; } ip1 = getenv("IP1"); ip2 = getenv("IP2"); if (!ip1 || !ip2) { printf("The IP1 and IP2 environment variables must be set!\n"); return 1; } #if KEEP_SERVING /* keep calling serve() until it fails, then exit with error code */ while (serve(argv[1])) { } printf("Listening failed\n"); return 1; #else /* call serve() and exit */ return (!serve(argv[1])); #endif }
int main(int argc, char** argv) { int detach = (argc > 1 && !strncmp(argv[1],"-d",2)) ? 1 : 0; char* port = (argc > (1 + detach) ? argv[1 + detach] : SERVER_PORT);; char* tls_port = (argc > (2 + detach) ? argv[2 + detach] : TLS_SERVER_PORT); if (argc > 3) usage(argv[0]); if (argc > 1 && !strcmp(argv[1],"-r")) restart(); demon(detach); serve(atoi(port),atoi(tls_port)); return 0; }
void sMain() { sGetMemHandler(sAMF_HEAP)->MakeThreadSafe(); // WTF?! { sThread serve(ServerThread); sCatchCtrlC(); while(!sGotCtrlC()) sSleep(100); } sPrintF(L"Server quit.\n"); }
void WaitForConnection(SocketServer* self) { listen(self->Socket,1); SOCKET TempSock = SOCKET_ERROR; while(TempSock==SOCKET_ERROR) { TempSock = accept(self->Socket,NULL,NULL); } serve(self, TempSock); closesocket(TempSock); }
int ConsoleObserverService::run(int port) { if (soap_valid_socket(bind(NULL, port, 100))) { for (;;) { if (!soap_valid_socket(accept())) return this->error; (void)serve(); soap_destroy(this); soap_end(this); } } else return this->error; return SOAP_OK; }
int server(int initfd) { // Create the shared queue queue_t q; int res; queue_init(&q, QUEUE_SIZE); // Create the consumer threads pthread_t cthreads[CONSUMERS_COUNT]; unsigned i; for (i = 0; i < CONSUMERS_COUNT; i++) { res = pthread_create(&cthreads[i], NULL, &consumer_thread, &q); assert(res == 0); } // Create the listening socket int accsock = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); assert(accsock >= 0); int true = 1; res = setsockopt(accsock, SOL_SOCKET, SO_REUSEADDR, &true, sizeof(true)); assert(res == 0); struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = htons(LISTEN_PORT); res = bind(accsock, (struct sockaddr*)&addr, sizeof(addr)); assert(res == 0); res = listen(accsock, BACKLOG_SIZE); assert(res == 0); close(initfd); fprintf(stderr, "Server initialized\n"); serve(&q, accsock); for (i = 0; i < CONSUMERS_COUNT; i++) { res = pthread_join(cthreads[i], NULL); assert(res == 0); } queue_deinit(&q); return 0; }
int main(int argc, char** argv) { auto& main_prof = make_profiler("main"); profile_start(main_prof); try { options opt = parse_cmdline(argc, argv); switch (opt.m_mode) { case options::init: init(); break; case options::config: run_config(require_codedb_path(opt), opt); break; case options::build: build(require_codedb_path(opt), opt); break; case options::find: find(require_codedb_path(opt), opt); break; case options::serve: serve(require_codedb_path(opt), opt); break; case options::undefined: std::cout << "cdb: '" << opt.m_args[0] << "' is not a cdb-command. See 'cdb --help'.\n"; break; case options::help: help(opt); break; default: std::cout << "Not implemented '" << opt.m_args.at(0) << "'\n"; break; } } catch (const regex_error& error) { std::string desc = error.what(); if (!desc.empty()) desc[0] = std::toupper(desc[0]); std::cerr << "Error: invalid regex '" << error.m_expr << "'\n " << desc << '\n'; } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; } profile_stop(main_prof); profiler_report(); }
int main(int argc, char** argv) { stlink_t *sl = NULL; st_state_t state; memset(&state, 0, sizeof(state)); // set defaults... state.stlink_version = 2; state.logging_level = DEFAULT_LOGGING_LEVEL; state.listen_port = DEFAULT_GDB_LISTEN_PORT; parse_options(argc, argv, &state); switch (state.stlink_version) { case 2: sl = stlink_open_usb(state.logging_level); if(sl == NULL) return 1; break; case 1: sl = stlink_v1_open(state.logging_level); if(sl == NULL) return 1; break; } printf("Chip ID is %08x, Core ID is %08x.\n", sl->chip_id, sl->core_id); sl->verbose=0; current_memory_map = make_memory_map(sl); #ifdef __MINGW32__ WSADATA wsadata; if (WSAStartup(MAKEWORD(2,2),&wsadata) !=0 ) { goto winsock_error; } #endif while(serve(sl, state.listen_port, state.elf_filename) == 0); #ifdef __MINGW32__ winsock_error: WSACleanup(); #endif /* Switch back to mass storage mode before closing. */ stlink_run(sl); stlink_exit_debug_mode(sl); stlink_close(sl); return 0; }
int main(int argc, char *argv[]) { int fd; if (!parseargs(argc, argv)) usage(); else { fd = initserver(port, qlen); fprintf(stdout, "Server HTTP on port %d ...\n", port); serve(fd); } return 0; }
void umain(int argc, char **argv) { static_assert(sizeof(struct File) == 256); binaryname = "fs"; cprintf("FS is running\n"); // Check that we are able to do I/O outw(0x8A00, 0x8A00); cprintf("FS can do I/O\n"); serve_init(); fs_init(); serve(); }
SocksClient *SocksServer::takeIncoming() { if(d->incomingConns.isEmpty()) return 0; SocksClient *c = d->incomingConns.takeFirst(); // we don't care about errors anymore disconnect(c, SIGNAL(error(int)), this, SLOT(connectionError())); // don't serve the connection until the event loop, to give the caller a chance to map signals QTimer::singleShot(0, c, SLOT(serve())); return c; }
void test_set_base_null (void) { const gchar *uri; uri = serve(client); soupcut_client_set_base(client, NULL); cut_assert_equal_uint(SOUP_STATUS_MALFORMED, soupcut_client_get(client, NULL, NULL)); soupcut_client_get(client, uri, NULL); assert_response_equal_body(cut_take_printf("Hello %s", uri), client); }
void umain(void) { user_assert(sizeof(struct File) == 256); writef("FS is running\n"); // Check that we are able to do I/O //outw(0x8A00, 0x8A00); writef("FS can do I/O\n"); serve_init(); fs_init(); fs_test(); serve(); }
void test_send_message (void) { SoupMessage *message; const gchar *uri; uri = serve(client); message = soup_message_new("GET", uri); cut_assert_equal_uint(0, soupcut_client_get_n_messages(client)); soupcut_client_send_message(client, message); cut_assert_equal_uint(1, soupcut_client_get_n_messages(client)); gcut_assert_equal_object(message, soupcut_client_get_latest_message(client)); assert_response_equal_body(cut_take_printf("Hello %s", uri), client); }
int main(void) { uint32_t mode = 0; for(int i = 0; i < 9; i++) { mode |= (1<<i); } mode = mode ^ (1 << 1); // o-w p9server server; server.default_mode = mode; server.open = ram_open; server.read = ram_read; server.write = ram_write; server.create = ram_create; server.setup = ram_setup; serve(&server); }
int main(int argc, char* argv[]) { static char* cmds[] = { "serve", "fetch", "send" }; const char* usage = "Usage: tftp [-h] <command> [<args>]\n" "\n" "<command> is one of the following:\n" " serve Start a tftp server\n" " fetch Fetch file from a tftp server\n" " send Send file to a tftp server (not implemented)\n" "\n"; if(argc < 2) { fprintf(stderr, "Please provide a command.\n\n%s", usage); exit(EXIT_FAILURE); } if((strlen(argv[1]) == 2 && strncmp(argv[1], "-h", 2) == 0) || (strlen(argv[1]) == 6 && strncmp(argv[1], "--help", 6) == 0)) { printf("%s", usage); exit(EXIT_SUCCESS); } unsigned int i; for(i = 0; i < (sizeof cmds) / (sizeof (char*)); i++) { if(strncmp(argv[1], cmds[i], 6) == 0) { break; } } switch(i) { case 0: serve(argc, argv); break; case 1: fetch(argc, argv); break; case 2: send(argc, argv); break; default: fprintf(stderr, "%s is not a valid command.\n\n%s", argv[1], usage); exit(EXIT_FAILURE); } }
int main(int argc, char *argv[]) { struct addrinfo *ailist, *aip; struct addrinfo hint; int sockfd, err, n; char *host; if(argc != 1) err_quit("usage: %s", argv[0]); //取得系统参数 //Max length of a hostname, not including the terminating null byte if((n = sysconf(_SC_HOST_NAME_MAX)) < 0) n = HOST_NAME_MAX; if((host = malloc(n)) == NULL) err_sys("malloc error"); if(gethostname(host, n) < 0) err_sys("gethostname error"); //daemonize("ruptimed"); memset(&hint, 0, sizeof(hint)); hint.ai_flags = AI_CANONNAME; hint.ai_socktype = SOCK_STREAM; hint.ai_canonname = NULL; hint.ai_addr = NULL; hint.ai_next = NULL; if((err = getaddrinfo(host, "ruptime", &hint, &ailist)) != 0) { syslog(LOG_ERR, "ruptimed: getaddrinfo error %s", gai_strerror(err)); //此函数用来返回getaddrinfo函数的错误码返回的信息 exit(1); } for(aip = ailist; aip != NULL; aip = aip->ai_next) { #if 0 struct sockaddr_in *socktmp; socktmp = (struct sockaddr_in *)(aip->ai_addr); printf("the port id is %d, the address is %s\n", ntohs(socktmp->sin_port), inet_ntoa(socktmp->sin_addr)); #endif if((sockfd = initserver(SOCK_STREAM, aip->ai_addr, aip->ai_addrlen, QLEN)) >= 0) { serve(sockfd); exit(0); } } exit(0); }
int main(int argc, char *argv[]) { int serverport; char *serveraddr; if (argc >= 3) { serveraddr = argv[1]; serverport = atoi(argv[2]); } else { puts("Usage: ping [server] [port]"); exit(0); } unsigned int seed = time(NULL); srandom(seed); SLEEPT = 125000; user1_serving = 1; user1_serving_now = 1; user_served = 0; init_curses(); init_game(); netset(serverport, serveraddr); redraw(); serve(); while (!end) { redraw(); userctl(getch()); peersync(); move_ball(); redraw(); usleep(SLEEPT); } end_curses(); return 0; }
void umain(void) { assert(sizeof(struct File)==256); binaryname = "fs"; printf("FS is running\n"); // Check that we are able to do I/O outw(0x8A00, 0x8A00); printf("FS can do I/O\n"); serve_init(); fs_init(); fs_test(); serve(); }
int main(int argc, char *argv[]) { struct addrinfo *ailist, *aip; struct addrinfo hint; int sockfd, err, n; char *host; if (argc != 1) { err_quit("usage: ruptimed"); } if (( n = sysconf(_SC_HOST_NAME_MAX)) < 0) { n = HOST_NAME_MAX; } if ((host = malloc(n)) == NULL) { err_sys("malloc error"); } if (gethostname(host, n) < 0) { err_sys("gethostname error"); } daemonize("ruptimed"); memset(&hint, 0, sizeof(hint)); hint.ai_flags = AI_CANONNAME; hint.ai_socktype = SOCK_DGRAM; hint.ai_canonname = NULL; hint.ai_addr = NULL; hint.ai_next = NULL; if ((err = getaddrinfo(host, "ruptime", &hint, &ailist)) != 0) { syslog(LOG_ERR, "ruptimed: getaddrinfo error: %s", gai_strerror(err)); exit(EXIT_FAILURE); } for (aip = ailist; aip != NULL; aip = aip->ai_next) { if ((sockfd = initserver(SOCK_DGRAM, aip->ai_addr, aip->ai_addrlen, 0)) >= 0) { serve(sockfd); exit(EXIT_SUCCESS); } } exit(1); }
int main(int argc, const char * argv[]) { // handling zombie processes signal(SIGCHLD, handleSIGCHLD); srand(time(0)); init_client_list(); init_global_pipe_list(); init_message_boxes(); struct sockaddr_in my_addr; struct sockaddr_in client_addr; int port = 2000 + rand() % 100; printf("Port : %d\n", port); char port_str[5]; sprintf(port_str, "%d", port); int sc_fd = passivesock(port_str, "tcp", 5); printf("accepting.....\n"); int addrlen = sizeof(client_addr); while(1) { int new_client_sock = accept(sc_fd, (struct sockaddr *)&client_addr, (socklen_t*)&addrlen); int pid = fork(); if(pid == 0) { // child client_node_t* client = create_client_node(new_client_sock, "CGILAB"/*inet_ntoa(client_addr.sin_addr)*/, 511/*ntohs(client_addr.sin_port)*/); close(sc_fd); if(insert_to_client_list(client) != -1) { serve(client); close(new_client_sock); return 0; } } else { close(new_client_sock); } } return 0; }
int main(int argc, char *argv[]) { struct addrinfo *ailist, *aip; struct addrinfo hint; int sockfd, err, n; char *host; if (argc != 1) err_quit("usage: ./%s",argv[0]); #ifdef _SC_HOST_NAME_MAX n = sysconf(_SC_HOST_NAME_MAX); if (n < 0) /* best guess */ #endif n = HOST_NAME_MAX; host = malloc(n); if (host == NULL) err_sys("malloc error"); if (gethostname(host, n) < 0) err_sys("gethostname error"); init_LED(); printf("hostname=%s\n",host); daemonize("Zynq@Server"); hint.ai_flags = AI_PASSIVE; hint.ai_family = 0; hint.ai_socktype = SOCK_STREAM; hint.ai_protocol = 0; hint.ai_addrlen = 0; hint.ai_canonname = NULL; hint.ai_addr = NULL; hint.ai_next = NULL; if ((err = getaddrinfo(host, "2001", &hint, &ailist)) != 0) { syslog(LOG_ERR, "Zynq@Server: getaddrinfo error: %s", gai_strerror(err)); exit(1); } for (aip = ailist; aip != NULL; aip = aip->ai_next) { if ((sockfd = initserver(SOCK_STREAM, aip->ai_addr, aip->ai_addrlen, QLEN)) >= 0) { serve(sockfd); exit(0); } } exit(1); }