本文整理汇总了C++中server_start函数的典型用法代码示例。如果您正苦于以下问题:C++ server_start函数的具体用法?C++ server_start怎么用?C++ server_start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了server_start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
//init win32 socket
#ifdef __WIN32__
static WSADATA wsa_data;
int result = WSAStartup((WORD)(1<<8|1), &wsa_data); //初始化WinSocket动态连接库
if( result != 0 ) // 初始化失败
return -1;
#endif
#ifndef __WIN32__
signal( SIGPIPE, SIG_IGN ); //ignore send,recv SIGPIPE error
#endif
NEW( websrv, sizeof(webserver) );
memset( websrv, 0, sizeof(webserver) );
server_create( websrv, "config.xml" );
server_start( websrv );
do_console();
server_stop( websrv );
server_end( websrv );
DEL( websrv );
#ifdef __WIN32__
WSACleanup();
#endif
memory_end();
return 0;
}
示例2: main
int main(int argv,char **args)
{
int ret,epfd,nfds,server_socket_fd,i,index;
struct epoll_event events[256];
int count;
server_socket_fd = server_start();
if(server_socket_fd<0)
{
return 0;
}
set_non_blocking(server_socket_fd);
epfd = epoll_create(1024);
set_non_blocking(epfd);
epoll_add(epfd,server_socket_fd);
struct http_request_r *r=NULL,*p=NULL;
while(1)
{
nfds=epoll_wait(epfd,events,20,500);
for(i=0;i<nfds;i++)
{
if(events[i].data.fd==server_socket_fd)
{
onAccept(epfd,events[i],&r);
}
else if(events[i].events&EPOLLIN)
{
onData(epfd,events[i],&r);
}
}
}
}
示例3: main
// ---------------------------------- main() --------------------------------
int main(int argc, char *argv[]) {
if (argc == 2) //if you input 2 arguments, then the first input becomes the port number
portno = atoi(argv[1]);
server_start();
return 0;
}
示例4: csiebox_server_init
//read config file, and start to listen
void csiebox_server_init(/*{{{*/
csiebox_server** server, int argc, char** argv) {
csiebox_server* tmp = (csiebox_server*)malloc(sizeof(csiebox_server));
if (!tmp) {
fprintf(stderr, "server malloc fail\n");
return;
}
memset(tmp, 0, sizeof(csiebox_server));
if (!parse_arg(tmp, argc, argv)) {
fprintf(stderr, "Usage: %s [config file]\n", argv[0]);
free(tmp);
return;
}
int fd = server_start();
if (fd < 0) {
fprintf(stderr, "server fail\n");
free(tmp);
return;
}
tmp->client = (csiebox_client_info**)
malloc(sizeof(csiebox_client_info*) * getdtablesize());
if (!tmp->client) {
fprintf(stderr, "client list malloc fail\n");
close(fd);
free(tmp);
return;
}
memset(tmp->client, 0, sizeof(csiebox_client_info*) * getdtablesize());
tmp->listen_fd = fd;
*server = tmp;
}
示例5: main
int main(int argc, char **argv) {
int port, gamespeed;
if (argc < 4) {
fprintf(stdout, "Usage: %s <map> <gamespeed (1-10)> <players> [port]\n", argv[0]);
return -1;
}
if (argc >= 5)
port = atoi(argv[4]);
else
port = SERVER_PORT_DEFAULT;
fprintf(stderr, "Listening on port %i...\n", port);
server_init();
gettimeofday(&time_d, NULL);
gamespeed = atoi(argv[2]);
if (server_start(argv[1], atoi(argv[3]), port, gamespeed) == NULL)
return -1;
for (;;) {
server_loop(deltaTime());
#ifdef _WIN32
Sleep(15);
#else
usleep(15000);
#endif
}
return 0;
}
示例6: main
int main(int argc, char* argv[])
{
int id = 0;
if (argc >= 2)
{
id = atoi(argv[1]);
}
int i=0;
for (;i<argc; i++)
{
if (strcmp(argv[i], "-d") == 0)
{
init_daemon();
break;
}
}
server_start(id);
while (1)
{
sleep(60);
}
server_shutdown();
return 0;
}
示例7: main
int main(int argc, char *argv[]) {
server_setup_signals();
server_parse_params(argc, argv);
server_printopts();
server_start();
return 0;
}
示例8: init
/* Module functions */
static int
init(const struct mpdcron_config *conf, GKeyFile *fd)
{
GError *error;
g_debug("Initializing");
/* Load configuration */
if (file_load(conf, fd) < 0)
return MPDCRON_INIT_FAILURE;
/* Initialize database */
error = NULL;
if (!db_init(globalconf.dbpath, true, false, &error)) {
g_critical("Failed to initialize database `%s': %s",
globalconf.dbpath, error->message);
g_error_free(error);
file_cleanup();
return MPDCRON_INIT_FAILURE;
}
/* Initialize, bind and start the server */
server_init();
for (unsigned int i = 0; globalconf.addrs[i] != NULL; i++) {
if (strncmp(globalconf.addrs[i], "any", 4) == 0)
server_bind(NULL, globalconf.port);
else if (globalconf.addrs[i][0] == '/')
server_bind(globalconf.addrs[i], -1);
else
server_bind(globalconf.addrs[i], globalconf.port);
}
server_start();
timer = g_timer_new();
return MPDCRON_INIT_SUCCESS;
}
示例9: hsn_node_setup
int hsn_node_setup(t_hsn_node *node,
const char *credentials_dirpath,
const char *peers_list_filepath,
const char *peers_dirpath,
int port)
{
fprintf(stderr, "HSN node setup:\n");
fprintf(stderr, "* Loading credentials...\n");
if (hsn_node_load_credentials(node, credentials_dirpath) != 0)
goto err_load_credentials;
fprintf(stderr, "* Loading peers...\n");
if (hsn_node_load_peers(node, peers_list_filepath, peers_dirpath) != 0)
goto err_load_peers;
fprintf(stderr, "* Connecting to peers...\n");
if (hsn_node_connect_to_peers(node) != 0)
goto err_connect_to_peers;
fprintf(stderr, "* Starting server...\n");
node->server.port = port;
if (server_start(node) != 0)
goto err_start_server;
fprintf(stderr, "done.\n\n");
return (0);
err_start_server:
hsn_node_disconnect_from_peers(node);
err_connect_to_peers:
hsn_node_unload_peers(node);
err_load_peers:
hsn_node_unload_credentials(node);
err_load_credentials:
return (1);
}
示例10: main
int main(int argc, char **argv) {
server_t srv = server_init("0.0.0.0", 5431, test_onmessage, test_onconnect, test_ondisconnect);
if (!server_start(srv)) {
return EXIT_FAILURE;
}
server_loop(srv);
return EXIT_SUCCESS;
}
示例11: test
void test()
{
server = epollserver_create(HTTP_PORT, MAX_CLIENT_NUM, 1024, 1024);
printf("EAGAIN is %d\n", EAGAIN);
printf("ECONNRESET is %d\n", ECONNRESET);
server_start(server, my_logic_on_enter_pt, my_logic_on_close_pt, my_logic_on_recved_pt);
}
示例12: mu_assert
char *test_server_start()
{
mu_assert("Starting server", server_start("::1","3141",1,&pid) == 0);
mu_assert("Ensure we have pid for daemon", pid > 0);
mu_assert("Verify pid is valid", kill(pid, 0) == 0);
return 0;
}
示例13: main
int main(int argc, char *argv[]) {
short port;
port = get_port(argc, argv);
server_start(port, (callback_t) &handle); /* infinite loop */
return EXIT_SUCCESS; /* to make gcc happy */
}
示例14: main
int main(int argc, char *argv[]) {
Server *server = create_server();
server->port = PORT;
server->handler = &handler;
server_start(server);
return 0;
}
示例15: main
int main(int argc, char const* argv[]) {
server_t* s;
sigset_t mask;
siginfo_t info;
struct sigaction action;
if(argc == 1) {
if(!server_create(&s, "../calories.csv", NULL)) {
if(!server_create(&s, "./calories.csv", NULL)) {
printf("File '%s' fot found\n", "calories.csv");
exit(1);
}
}
} else if(argc == 2) {
if(!server_create(&s, "../calories.csv", argv[1])) {
if(!server_create(&s, "./calories.csv", argv[1])) {
printf("File '%s' fot found\n", "calories.csv");
exit(1);
}
}
} else {
printf("%s\n", SERVER_MAIN_HELP);
exit(1);
}
printf("Press CTRL+C to shutdown the server\n");
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
sigprocmask(SIG_BLOCK, &mask, NULL);
sigemptyset(&action.sa_mask);
action.sa_flags = SA_SIGINFO;
sigaction(SIGCHLD, &action, NULL);
if(server_start(s)) {
while(true) {
// signal() is NOT thread safe!
// And since the server doesn't block signal handling is "not" needed ...
if(sigwaitinfo(&mask, &info) == -1) {
perror("sigwaitinfo() failed");
exit(1);
}
switch(info.si_signo) {
case SIGINT:
server_destroy(s);
return 0;
}
}
} else {
server_destroy(s);
}
}