int main(int argc, char *argv[]) { const char * config_file = "config"; if (argc > 1) { config_file = argv[1]; } skynet_env_init(); sigign(); struct skynet_config config; // lua 相关的一些初始化 struct lua_State *L = luaL_newstate(); luaL_openlibs(L); // link lua lib lua_close(L); L = luaL_newstate(); int err = luaL_dofile(L, config_file); if (err) { fprintf(stderr,"%s\n",lua_tostring(L,-1)); lua_close(L); return 1; } // 初始化 lua 环境 _init_env(L); const char *path = optstring("lua_path","./lualib/?.lua;./lualib/?/init.lua"); setenv("LUA_PATH",path,1); const char *cpath = optstring("lua_cpath","./luaclib/?.so"); setenv("LUA_CPATH",cpath,1); optstring("luaservice","./service/?.lua"); // 加载配置项 config.thread = optint("thread",8); config.module_path = optstring("cpath","./service/?.so"); config.logger = optstring("logger",NULL); config.harbor = optint("harbor", 1); config.master = optstring("master","127.0.0.1:2012"); config.start = optstring("start","main.lua"); config.local = optstring("address","127.0.0.1:2525"); config.standalone = optstring("standalone",NULL); lua_close(L); skynet_start(&config); printf("skynet exit\n"); return 0; }
int main (int argc, char **argv) { int pid; char qactivefile [256]; char *progname = argv[0]; openlog ("mdmn", 0, LOG_MAIL); umask (002); if (argc > 1 && !strcmp (argv[1], "-d")) { ++debug; ++argv; --argc; } if (argc > 2) { fprintf (stderr, "usage: %s [-d] [config-file]\n", progname); exit (-1); } if (! config (argv [1])) { fprintf (stderr, "cannot read config file\n"); exit (-1); } if (! debug) { /* let's fork */ pid = fork (); if (pid < 0) { fprintf (stderr, "%s: cannot fork\n", progname); exit (-1); } if (pid) exit (0); /* now we are a child */ /* catch signals */ sigign (); } /* make temp file name */ mktemp (tmpf); syslog (LOG_INFO, "daemon started"); sprintf (qactivefile, "%s/queueactive", SERVDIR); for (;;) { if (filesize (MAILBOX)) runqueuer (); if (filesize (qactivefile)) runbatcher (); sleep (DAEMONDELAY); } /* NOTREACHED */ }
int main(int argc, char *argv[]) { const char * config_file = NULL ; if (argc > 1) { config_file = argv[1]; } else { fprintf(stderr, "Need a config file.\n"); return 1; } server_globalinit(); server_env_init(); sigign(); server_pid = (int)getpid(); struct server_config config; struct lua_State *L = lua_newstate(server_lalloc, NULL); luaL_openlibs(L); int r = luaL_loadfile(L, config_file); if (r) { fprintf(stderr,"luaL_loadfile err:%s\n",lua_tostring(L,-1)); lua_close(L); return 1; } int err = lua_pcall(L,0,1,0); if (err) { fprintf(stderr,"lua_pcall config file err:%s\n",lua_tostring(L,-1)); lua_close(L); return 1; } _init_env(L); config.harbor = optint("harbor", 1); config.thread = optint("thread",8); config.logger = optstring("logger", NULL); config.bootstrap = optstring("bootstrap","snlua bootstrap"); config.module_path = optstring("cpath","./cservice/?.so"); lua_close(L); //启动服务 server_start(&config); return 0; }
int main(int argc, char *argv[]) { const char * config_file = "config"; if (argc > 1) { config_file = argv[1]; } skynet_globalinit(); skynet_env_init(); #if !defined(__WIN32__) sigign(); #endif struct skynet_config config; struct lua_State *L = lua_newstate(skynet_lalloc, NULL); luaL_openlibs(L); // link lua lib lua_close(L); L = luaL_newstate(); int err = luaL_dofile(L, config_file); if (err) { fprintf(stderr,"%s\n",lua_tostring(L,-1)); lua_close(L); return 1; } _init_env(L); #ifdef LUA_CACHELIB printf("Skynet lua code cache enable\n"); #endif config.thread = optint("thread",8); config.module_path = optstring("cpath","./cservice/?.dll"); config.harbor = optint("harbor", 1); config.bootstrap = optstring("bootstrap","snlua bootstrap"); lua_close(L); skynet_start(&config); skynet_globalexit(); printf("skynet exit\n"); return 0; }
int main(int argc, char *argv[]) { #if defined(__WIN32__) WSADATA WSAData; if(WSAStartup(MAKEWORD(2, 2), &WSAData))//初始化 { printf("initializationing error!\n"); WSACleanup(); exit(0); } #endif const char * config_file = "config"; if (argc > 1) { config_file = argv[1]; } skynet_globalinit(); skynet_env_init(); #if !defined(__WIN32__) sigign(); #endif struct skynet_config config; struct lua_State *L = lua_newstate(skynet_lalloc, NULL); luaL_openlibs(L); // link lua lib lua_close(L); L = luaL_newstate(); int err = luaL_dofile(L, config_file); if (err) { fprintf(stderr,"%s\n",lua_tostring(L,-1)); lua_close(L); return 1; } _init_env(L); #ifdef LUA_CACHELIB printf("Skynet lua code cache enable\n"); #endif config.thread = optint("thread",8); config.module_path = optstring("cpath","./cservice/?.so"); config.logger = optstring("logger",NULL); config.harbor = optint("harbor", 1); config.master = optstring("master","127.0.0.1:2012"); config.bootstrap = optstring("bootstrap","snlua bootstrap"); config.local = optstring("address","127.0.0.1:2525"); config.standalone = optstring("standalone",NULL); lua_close(L); skynet_start(&config); skynet_globalexit(); printf("skynet exit\n"); return 0; }
main (int argc, char **argv, char **envp) { register c; if (argc > 2) { outerr("Usage: deco [dirname]\n",0); exit (1); } outerr("Demos Commander, Copyright (C) 1989-1994 Serge Vakulenko\n",0); palette = dflt_palette; EnvInit (envp); uid = getuid (); gid = getgid (); # ifdef GROUPS gidnum = getgroups (sizeof(gidlist)/sizeof(gidlist[0]), (unsigned int *)gidlist); # endif ppid = getppid (); user = username (uid); group = groupname (gid); tty = ttyname (0); machine = getmachine (); #if 0 sigign(); #else signal(SIGTERM, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); # ifdef SIGTSTP signal(SIGTSTP, SIG_IGN); # endif #endif init (); // inithome (); VClear (); /* init class dir */ if (argc > 1) // chdir (argv [1]); left = new dir(argv [1]); else left = new dir; right = new dir; left->d.basecol = 0; right->d.basecol = 40; /*-----------*/ initfile.read(); if (uid == 0) palette.dimfg = 6; v.VSetPalette (palette.fg, palette.bg, palette.revfg, palette.revbg, palette.boldfg, palette.boldbg, palette.boldrevfg, palette.boldrevbg, palette.dimfg, palette.dimbg, palette.dimrevfg, palette.dimrevbg); setdir (left, "."); setdir (right, "."); left->chdir(left->d.cwd); cur = left; draw.draw(cur, left, right); for (;;) { if (! cmdreg) draw.drawcursor(cur); // cmd.drawcmd(cur, &left, &right); VSync (); c = KeyGet (); if (! cmdreg) draw.undrawcursor(cur); switch (c) { case '+': /* select */ case '-': /* unselect */ if (! cpos && ! cmdreg && ! cur->d.status) { if (c == '+') tagall (); else untagall (); draw.draw(cur, left, right); continue; } default: // if (c>=' ' && c<='~' || c>=0300 && c<=0376) { // if (cpos || c!=' ') // cmd.inscmd(c); // continue; // } VBeep (); continue; // case cntrl ('V'): /* quote next char */ // cmd.inscmd(quote ()); // continue; // case cntrl ('J'): /* insert file name */ // if (! cmdreg && ! cur->status) // cmd.namecmd(cur); // continue; // case cntrl ('G'): // cmd.delcmd(); // continue; // case meta ('b'): /* backspace */ // if (cpos) { // cmd.leftcmd(); // cmd.delcmd(); // } // continue; case cntrl ('O'): /* set/unset command mode */ case cntrl ('P'): /* set/unset command mode */ switchcmdreg (); if (! cmdreg) visualwin = 1; draw.draw(cur, left, right); continue; case cntrl ('M'): /* return */ // if (command [0]) { // cmd.exec(cur, &left, &right, 1, 1); // draw.draw(cur, &left, &right); // continue; // } if (cmdreg) { cmdreg = 0; if (! visualwin) { visualwin = 1; setdir (cur==left ? right : left, NULL); setdir (cur, NULL); } draw.draw(cur, left, right); continue; } execute (); continue; case cntrl (']'): /* redraw screen */ VRedraw (); continue; // case cntrl ('B'): /* history */ // if (! visualwin) // VClearBox (1, 0, LINES-2, 80); // cmd.histmenu(cur, &left, &right); // draw.draw(cur, &left, &right); // continue; case meta ('A'): /* f1 */ genhelp (); draw.draw(cur, left, right); continue; case meta ('B'): /* f2 */ udm.menu(); draw.draw(cur, left, right); continue; case meta ('I'): /* f9 */ mymenu.runmenu (cur==left ? 'l' : 'r'); draw.draw(cur, left, right); continue; case meta ('J'): /* f0 */ case cntrl ('C'): /* quit */ quit (); continue; case cntrl ('U'): /* swap panels */ swappanels (); draw.draw(cur, left, right); continue; case cntrl ('F'): /* full screen */ fullscreen (); draw.draw(cur, left, right); continue; case cntrl ('^'): /* cd / */ directory (0, 'r'); if (! cur->d.status) draw.drawdir(cur, 1, left, right); continue; case cntrl ('\\'): /* cd $HOME */ directory (0, 'o'); if (! cur->d.status) draw.drawdir(cur, 1, left, right); continue; // case cntrl ('Y'): /* clear line */ // command [cpos = 0] = 0; // continue; // case cntrl ('X'): /* next history */ // cmd.nextcmd(); // continue; // case cntrl ('E'): /* prev history */ // cmd.prevcmd(); // continue; // case cntrl ('S'): /* char left */ // case cntrl ('A'): /* char left */ // cmd.leftcmd(); // continue; // case cntrl ('D'): /* char right */ // cmd.rightcmd(); // continue; case cntrl ('I'): /* tab */ if (cmdreg) {} // if (command [cpos]) // cmd.endcmd(); // else // cmd.homecmd(); else { switchpanels (); if (fullwin) { draw.drawbanners(); draw.drawdir(cur, 0, left, right); break; } } continue; case cntrl ('W'): /* double width */ if (! cmdreg) { setdwid (); draw.draw(cur, left, right); } continue; // case meta ('G'): /* f7 */ // makedir (); // draw.draw(cur, &left, &right); // continue; case meta ('h'): /* home */ case meta ('e'): /* end */ case meta ('u'): /* up */ case meta ('d'): /* down */ case meta ('l'): /* left */ case meta ('r'): /* right */ case meta ('n'): /* next page */ case meta ('p'): /* prev page */ case cntrl ('K'): /* find file */ case cntrl ('R'): /* reread catalog */ case cntrl ('T'): /* tag file */ case meta ('C'): /* f3 */ case meta ('D'): /* f4 */ case meta ('E'): /* f5 */ case meta ('F'): /* f6 */ case meta ('H'): /* f8 */ case cntrl ('L'): /* status */ if (cmdreg || cur->d.status) {} // docmdreg (c); else doscrreg (c); continue; } } }
int main(int argc, char *argv[]) { if (argc != 4) { printf("Copyright (c) 2014, Dali Wang<*****@*****.**>.\n"); printf("Used: sms ip port serial\n"); printf("./sms 127.0.0.1 8888 /dev/ttyS0"); return 0; } sigign(); // 信号处理 // 注册返回函数 settings.on_message_begin = begin_cb; settings.on_url = url_cb; settings.on_header_field = field_cb; settings.on_header_value = value_cb; settings.on_headers_complete = herders_cb; settings.on_body = body_cb; settings.on_message_complete = end_cb; settings.on_status = status_cb; cssl_start(); // 开启CSSL库 //"/dev/ttyS1" serial = cssl_open(argv[3], callback, 0, 9600, 8, 0, 1); // 打开串口 // 打开失败 if (!serial) { printf("Open COM Fail = %s\n", cssl_geterrormsg()); // 获得错误信息 return -1; } ss = socket_server_create(); // 创建 socket_server int listen_id = socket_server_listen(ss, 100, argv[1], atoi(argv[2]), 32); // 监听 socket socket_server_start(ss, 200, listen_id); // 纳入事件管理 struct socket_message result; // 声明一个soket消息的结构 for (;;) { int type = socket_server_poll(ss, &result, NULL); // 事件循环 switch (type) { case SOCKET_EXIT: printf("exit(%lu) [id=%d]\n", result.opaque, result.id); goto EXIT_LOOP; case SOCKET_DATA: //printf("data(%lu) [id=%d] %s\n", result.opaque, result.id, result.data); OnReceive(result); // 收到数据,调用函数处理 break; case SOCKET_CLOSE: printf("close(%lu) [id=%d]\n", result.opaque, result.id); free((void*)result.opaque); break; case SOCKET_OPEN: printf("open(%lu) [id=%d] %s\n", result.opaque, result.id, result.data); break; case SOCKET_ERROR: printf("error(%lu) [id=%d]\n", result.opaque, result.id); break; case SOCKET_ACCEPT: { printf("accept(%lu) [id=%d %s] from [%d]\n", result.opaque, result.ud, result.data, result.id); // 初始化 HTTP 结构 struct http_parser *parser; parser = (http_parser *) malloc(sizeof(http_parser)); http_parser_init(parser, HTTP_REQUEST); socket_server_start(ss, (uintptr_t)parser, result.ud); // 纳入事件管理 id = result.ud; // 临时解决办法,应该使用 parser->data来传输 。 } break; } // switch } // for EXIT_LOOP: socket_server_release(ss); // 关闭 socket_server return 0; }