int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { u_short port = ACE_DEFAULT_SERVER_PORT; if (argc > 1) port = ACE_OS::atoi (argv[1]); return run_event_loop (port); }
/* * Processes an incoming "handle a new connection" item. This is called when * input arrives on the libevent wakeup pipe. */ static void thread_libevent_process(evutil_socket_t fd, short which, void *arg) { LIBEVENT_THREAD *me = arg; CQ_ITEM *item; conn* pending; cb_assert(me->type == GENERAL); drain_notification_channel(fd); if (memcached_shutdown) { event_base_loopbreak(me->base); return ; } while ((item = cq_pop(me->new_conn_queue)) != NULL) { conn *c = conn_new(item->sfd, item->parent_port, item->init_state, item->event_flags, item->read_buffer_size, me->base); if (c == NULL) { if (settings.verbose > 0) { settings.extensions.logger->log(EXTENSION_LOG_INFO, NULL, "Can't listen for events on fd %d\n", item->sfd); } closesocket(item->sfd); } else { cb_assert(c->thread == NULL); c->thread = me; } cqi_free(item); } LOCK_THREAD(me); pending = me->pending_io; me->pending_io = NULL; while (pending != NULL) { conn *c = pending; cb_assert(me == c->thread); pending = pending->next; c->next = NULL; if (c->sfd != INVALID_SOCKET && !c->registered_in_libevent) { /* The socket may have been shut down while we're looping */ /* in delayed shutdown */ register_event(c, 0); } /* * We don't want the thread to keep on serving all of the data * from the context of the notification pipe, so just let it * run one time to set up the correct mask in libevent */ c->nevents = 1; run_event_loop(c); } UNLOCK_THREAD(me); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_SSL_Context *context = ACE_SSL_Context::instance (); context->certificate ("./dummy.pem", SSL_FILETYPE_PEM); context->private_key ("./key.pem", SSL_FILETYPE_PEM); u_short port = ACE_DEFAULT_SERVER_PORT; if (argc > 1) port = ACE_OS::atoi (argv[1]); return run_event_loop (port); }
int main(int argc, char **argv) { // Default program parameters int port = 8080; char* pwd = "./static/"; // Print help if needed if (argc >= 2 && strcmp(argv[1], "--help") == 0) { printf("Usage: nweb <port> <root_dir>\t\tversion %d\n\n" "\tnweb is a small and very safe mini web server\n" "\tnweb only servers out file/web pages with extensions named below\n" "\t and only from the root directory or its sub-directories.\n" "\tThere is no fancy features = safe and secure.\n\n" "\tExample: nweb 8080 /home/foo &\n\n" "\tOnly Supports:", VERSION); for(int i=0; extensions[i].ext != 0; i++) printf(" %s", extensions[i].ext); printf("\n\tNot Supported: URLs including \"..\", Java, Javascript, CGI\n" "\tNot Supported: directories / /etc /bin /lib /tmp /usr /dev /sbin \n" "\tNo warranty given or implied\n\tNigel Griffiths [email protected]\n"); return 0; } fprintf(stderr, "The default port is %d; the default serving directory is `%s`.\n", port, pwd); fprintf(stderr, "For information, use --help flag.\n\n"); if (argc > 1) port = atoi(argv[1]); if (argc > 2) { if(!strncmp(argv[2],"/",2 ) || !strncmp(argv[2],"/etc", 5 ) || !strncmp(argv[2],"/bin",5 ) || !strncmp(argv[2],"/lib", 5 ) || !strncmp(argv[2],"/tmp",5 ) || !strncmp(argv[2],"/usr", 5 ) || !strncmp(argv[2],"/dev",5 ) || !strncmp(argv[2],"/sbin",6) ) { printf("ERROR: Bad top directory %s, see nweb -?\n", argv[2]); return -1; } pwd = argv[2]; } init_event_loop(); init_server(port, pwd); run_event_loop(); }
int tcf_client(void) { #else int main(int argc, char ** argv) { #endif int c; int ind; int keep_alive = 0; int mode = 1; /* interactive */ const char * host_name = "localhost"; const char * command = NULL; const char * log_name = "-"; const char * script_name = NULL; log_mode = 0; ini_mdep(); ini_trace(); ini_events_queue(); ini_asyncreq(); #if defined(_WRS_KERNEL) progname = "tcf"; open_log_file("-"); #else progname = argv[0]; /* Parse arguments */ for (ind = 1; ind < argc; ind++) { const char * s = argv[ind]; if (*s != '-') { break; } s++; while ((c = *s++) != '\0') { switch (c) { case 'd': keep_alive = 1; break; case 'l': case 'L': case 'S': case 'h': case 'c': #if ENABLE_Plugins case 'P': #endif if (*s == '\0') { if (++ind >= argc) { fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c); exit(1); } s = argv[ind]; } switch (c) { case 'l': log_mode = strtol(s, 0, 0); break; case 'L': log_name = s; break; case 'S': script_name = s; mode = 0; break; case 'h': host_name = s; break; case 'c': /* TODO: allow multiple -c options */ command = s; mode = 2; break; #if ENABLE_Plugins case 'P': plugins_path = s; break; #endif default: fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); exit(1); } s = ""; break; default: fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); exit(1); } } } if (script_name != NULL && command != NULL) { fprintf(stderr, "%s: error: illegal option -S and -c are mutually exclusive\n", progname); exit(1); } open_log_file(log_name); #endif discovery_start(); proto = protocol_alloc(); #if ENABLE_Cmdline if (script_name != NULL) open_script_file(script_name); if (command != NULL) set_single_command(keep_alive, host_name, command); ini_cmdline_handler(mode, proto); #else if (script_name != NULL) fprintf(stderr, "Warning: This version does not support script file as input.\n"); #endif #if ENABLE_Plugins plugins_load(proto, NULL); #endif /* Process events - must run on the initial thread since ptrace() * returns ECHILD otherwise, thinking we are not the owner. */ run_event_loop(); return 0; }
static void solve(int retry, int timeout, int cname, const ruli_list_t *server_list) { oop_source_sys *source_sys; /* System event source */ oop_source *source; /* Event registration interface */ ruli_res_t res_ctx; int result; ruli_conf_handler_t handler; /* * Create event source */ create_oop_source(&source_sys, &source); /* * Initialize resolver */ handler.opaque = server_list; handler.search_loader = load_search_list; handler.search_unloader = unload_search_list; handler.ns_loader = load_ns_list; handler.ns_unloader = unload_ns_list; res_ctx.res_conf_handler = &handler; res_ctx.res_source = source; res_ctx.res_retry = retry; res_ctx.res_timeout = timeout; result = ruli_res_new(&res_ctx); if (result) { fprintf(stderr, "%s: can't create ruli resolver: %s [%d]\n", prog_name, ruli_res_errstr(result), result); exit(1); } /* * main solve loop */ for (;;) { const int INBUFSZ = 1024; char inbuf[INBUFSZ]; /* * Read stdin */ if (!fgets(inbuf, INBUFSZ, stdin)) { if (feof(stdin)) break; fprintf(stderr, "%s: reading from stdin: %s\n", prog_name, strerror(errno)); continue; } /* * Scan tokens */ { const char *SEP = "\r\n\t "; char *ptr; char *tok; tok = strtok_r(inbuf, SEP, &ptr); if (!tok) continue; for (;;) { /* * Submit query for token */ do_query(&res_ctx, tok, cname); tok = strtok_r(0, SEP, &ptr); if (!tok) break; } /* for */ } /* Scan tokens */ /* * Run event loop (send queries, receive answers) */ { void *oop_result = run_event_loop(source_sys); if (oop_result != OOP_CONTINUE) break; } } /* main solve loop */ /* * Destroy resolver */ ruli_res_delete(&res_ctx); /* * Destroy event source */ oop_sys_delete(source_sys); }
int tcf_lua(void) { #else int main(int argc, char ** argv) { #endif int c; int ind; int error; const char * log_name = "-"; const char * script_name = NULL; char * engine_name; lua_State *L; log_mode = 0; #ifndef WIN32 signal(SIGPIPE, SIG_IGN); #endif ini_mdep(); ini_trace(); ini_events_queue(); ini_asyncreq(); #if defined(_WRS_KERNEL) progname = "tcf"; open_log_file("-"); #else progname = argv[0]; /* Parse arguments */ for (ind = 1; ind < argc; ind++) { const char * s = argv[ind]; if (*s != '-') { break; } s++; while ((c = *s++) != '\0') { switch (c) { case 'l': case 'L': case 'S': if (*s == '\0') { if (++ind >= argc) { fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c); exit(1); } s = argv[ind]; } switch (c) { case 'l': log_mode = strtol(s, 0, 0); break; case 'L': log_name = s; break; case 'S': script_name = s; break; default: fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); exit(1); } s = ""; break; default: fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); exit(1); } } } if (ind >= argc) { fprintf(stderr, "%s: error: no Lua script specified\n", progname); exit(1); } engine_name = argv[ind++]; if (ind < argc) { fprintf(stderr, "%s: error: too many arguments\n", progname); exit(1); } open_log_file(log_name); #endif if (script_name != NULL) { if((lua_read_command_state.req.u.fio.fd = open(script_name, O_RDONLY, 0)) < 0) { fprintf(stderr, "%s: error: cannot open script: %s\n", progname, script_name); exit(1); } } else { lua_read_command_state.req.u.fio.fd = fileno(stdin); } discovery_start(); if((luastate = L = luaL_newstate()) == NULL) { fprintf(stderr, "error from luaL_newstate\n"); exit(1); } luaL_openlibs(L); luaL_register(L, "tcf", tcffuncs); lua_pop(L, 1); /* Peer metatable */ luaL_newmetatable(L, "tcf_peer"); luaL_register(L, NULL, peerfuncs); lua_pushvalue(L, -1); lua_setfield(L, -1, "__index"); /* m.__index = m */ lua_pushvalue(L, -1); lua_setfield(L, -1, "__metatable"); /* m.__metatable = m */ lua_pop(L, 1); /* Protocol metatable */ luaL_newmetatable(L, "tcf_protocol"); luaL_register(L, NULL, protocolfuncs); lua_pushvalue(L, -1); lua_setfield(L, -1, "__index"); /* m.__index = m */ lua_pushvalue(L, -1); lua_setfield(L, -1, "__metatable"); /* m.__metatable = m */ lua_pop(L, 1); /* Channel metatable */ luaL_newmetatable(L, "tcf_channel"); luaL_register(L, NULL, channelfuncs); lua_pushvalue(L, -1); lua_setfield(L, -1, "__index"); /* m.__index = m */ lua_pushvalue(L, -1); lua_setfield(L, -1, "__metatable"); /* m.__metatable = m */ lua_pop(L, 1); /* Post event metatable */ luaL_newmetatable(L, "tcf_post_event"); luaL_register(L, NULL, posteventfuncs); lua_pushvalue(L, -1); lua_setfield(L, -1, "__index"); /* m.__index = m */ lua_pushvalue(L, -1); lua_setfield(L, -1, "__metatable"); /* m.__metatable = m */ lua_pop(L, 1); lua_newtable(L); /* peers = {} */ lua_newtable(L); /* m = {} */ lua_pushstring(L, "v"); /* Values are weak */ lua_setfield(L, -2, "__mode"); /* m.__mode = "v" */ lua_setmetatable(L, -2); /* setmetatable(peer, m) */ peers_refp = luaref_new(L, NULL); peer_server_add_listener(peer_server_changes, L); if((error = luaL_loadfile(L, engine_name)) != 0) { fprintf(stderr, "%s\n", lua_tostring(L,1)); exit(1); } if((error = lua_pcall(L, 0, LUA_MULTRET, 0)) != 0) { fprintf(stderr, "%s\n", lua_tostring(L,1)); exit(1); } /* Process events - must run on the initial thread since ptrace() * returns ECHILD otherwise, thinking we are not the owner. */ run_event_loop(); lua_close(L); return 0; }
int tcf_log(void) { #else int main(int argc, char ** argv) { int c; int ind; const char * log_name = "-"; #endif const char * url = "TCP:"; PeerServer * ps; ChannelServer * serv; int print_server_properties = 0; ini_mdep(); ini_trace(); ini_events_queue(); ini_asyncreq(); log_mode = LOG_TCFLOG; #if defined(_WRS_KERNEL) progname = "tcf"; open_log_file("-"); #else progname = argv[0]; /* Parse arguments */ for (ind = 1; ind < argc; ind++) { char * s = argv[ind]; if (*s++ != '-') break; while (s && (c = *s++) != '\0') { switch (c) { case 'h': show_help(); exit(0); case 'n': auto_redirect = 0; break; case 'S': print_server_properties = 1; break; #if ENABLE_Trace case 'l': #endif case 'L': case 's': case 'f': if (*s == '\0') { if (++ind >= argc) { fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c); exit(1); } s = argv[ind]; } switch (c) { #if ENABLE_Trace case 'l': if (parse_trace_mode(s, &log_mode) != 0) { fprintf(stderr, "Cannot parse log level: %s\n", s); exit(1); } break; #endif case 'L': log_name = s; break; case 's': url = s; break; case 'f': if (filter_add_message_filter(s) != 0) { fprintf(stderr, "Cannot parse filter level: %s\n", s); exit(1); } break; default: fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); show_help(); exit(1); } s = NULL; break; default: ILLEGAL_OPTION_HOOK; fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); show_help(); exit(1); } } } open_log_file(log_name); if (ind < argc) { dest_url = argv[ind++]; if (!auto_redirect) { fprintf(stderr, "Automatic redirect disabled: argument '%s' ignored\n", dest_url); dest_url = NULL; } } #endif bcg = broadcast_group_alloc(); /* Default filters (use "-fi" to disable). */ filter_add_message_filter("o,E,Locator,peerHeartBeat"); filter_add_message_filter("o,E,Locator,peerAdded"); filter_add_message_filter("o,E,Locator,peerRemoved"); filter_add_message_filter("o,E,Locator,peerChanged"); filter_add_message_filter("o,C,Locator,getPeers"); filter_add_message_filter("tr10,C,FileSystem,read"); filter_add_message_filter("t10,C,FileSystem,write"); set_proxy_log_filter_listener2(filter_is_log_filtered); ps = channel_peer_from_url(url); if (ps == NULL) { fprintf(stderr, "%s: invalid server URL (-s option value): %s\n", progname, url); exit(1); } peer_server_addprop(ps, loc_strdup("Name"), loc_strdup("TCF Protocol Logger")); peer_server_addprop(ps, loc_strdup("Proxy"), loc_strdup("")); SERVER_ADDPROP_HOOK; serv = channel_server(ps); if (serv == NULL) { fprintf(stderr, "%s: cannot create TCF server: %s\n", progname, errno_to_str(errno)); exit(1); } serv->new_conn = channel_new_connection; discovery_start(); if (print_server_properties) { ChannelServer * s; char * server_properties; assert(!list_is_empty(&channel_server_root)); s = servlink2channelserverp(channel_server_root.next); server_properties = channel_peer_to_json(s->ps); printf("Server-Properties: %s\n", server_properties); fflush(stdout); trace(LOG_ALWAYS, "Server-Properties: %s", server_properties); loc_free(server_properties); } /* Process events - must run on the initial thread since ptrace() * returns ECHILD otherwise, thinking we are not the owner. */ run_event_loop(); return 0; }
int tcf(void) { #else int main(int argc, char ** argv) { int c; int ind; int daemon = 0; const char * log_name = NULL; const char * log_level = NULL; #endif int interactive = 0; int print_server_properties = 0; const char * url = DEFAULT_SERVER_URL; Protocol * proto; TCFBroadcastGroup * bcg; ini_mdep(); ini_trace(); ini_events_queue(); ini_asyncreq(); #if defined(_WRS_KERNEL) progname = "tcf"; open_log_file("-"); log_mode = 0; #else progname = argv[0]; /* Parse arguments */ for (ind = 1; ind < argc; ind++) { const char * s = argv[ind]; if (*s != '-') { break; } s++; while ((c = *s++) != '\0') { switch (c) { case 'i': interactive = 1; break; case 't': #if ENABLE_RCBP_TEST test_proc(); #endif exit(0); break; case 'd': daemon = 1; break; case 'c': generate_ssl_certificate(); exit(0); break; case 'S': print_server_properties = 1; break; case 'h': show_help(); exit(0); case 'I': case 'l': case 'L': case 's': #if ENABLE_Plugins case 'P': #endif if (*s == '\0') { if (++ind >= argc) { fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c); exit(1); } s = argv[ind]; } switch (c) { case 'I': idle_timeout = strtol(s, 0, 0); break; case 'l': log_level = s; parse_trace_mode(log_level, &log_mode); break; case 'L': log_name = s; break; case 's': url = s; break; #if ENABLE_Plugins case 'P': plugins_path = s; break; #endif } s = ""; break; default: fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); show_help(); exit(1); } } } if (daemon && log_name != NULL && strcmp (log_name, LOG_NAME_STDERR) != 0) { fprintf(stderr, "%s: error: can only log to stderr when in daemon " "mode.\n", progname); exit (1); } if (daemon) become_daemon(); open_log_file(log_name); #endif bcg = broadcast_group_alloc(); proto = protocol_alloc(); /* The static services must be initialised before the plugins */ #if ENABLE_Cmdline if (interactive) ini_cmdline_handler(interactive, proto); #else if (interactive) fprintf(stderr, "Warning: This version does not support interactive mode.\n"); #endif ini_services(proto, bcg); #if !defined(_WRS_KERNEL) /* Reparse log level in case initialization cause additional * levels to be registered */ if (log_level != NULL && parse_trace_mode(log_level, &log_mode) != 0) { fprintf(stderr, "Cannot parse log level: %s\n", log_level); exit(1); } #endif if (ini_server(url, proto, bcg) < 0) { fprintf(stderr, "Cannot create TCF server: %s\n", errno_to_str(errno)); exit(1); } discovery_start(); if (print_server_properties) { ChannelServer * s; char * server_properties; assert(!list_is_empty(&channel_server_root)); s = servlink2channelserverp(channel_server_root.next); server_properties = channel_peer_to_json(s->ps); printf("Server-Properties: %s\n", server_properties); fflush(stdout); trace(LOG_ALWAYS, "Server-Properties: %s", server_properties); loc_free(server_properties); } #if ENABLE_SignalHandlers signal(SIGABRT, signal_handler); signal(SIGILL, signal_handler); signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); #if defined(_WIN32) SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE); AddVectoredExceptionHandler(1, VectoredExceptionHandler); #endif #endif /* ENABLE_SignalHandlers */ if (idle_timeout != 0) { add_channel_close_listener(channel_closed); check_idle_timeout(NULL); } /* Process events - must run on the initial thread since ptrace() * returns ECHILD otherwise, thinking we are not the owner. */ run_event_loop(); #if ENABLE_Plugins plugins_destroy(); #endif /* ENABLE_Plugins */ return 0; }
int MT_AMH_Server::svc (void) { run_event_loop (); return 1; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { return run_event_loop (argc > 1 ? argv[1] : ACE_DEFAULT_RENDEZVOUS); }
int tcf(void) { #else int main(int argc, char ** argv) { int c; int ind; int daemon = 0; const char * log_name = NULL; const char * log_level = NULL; #endif int interactive = 0; int print_server_properties = 0; const char * url = DEFAULT_SERVER_URL; Protocol * proto; TCFBroadcastGroup * bcg; PRE_INIT_HOOK; ini_mdep(); ini_trace(); ini_events_queue(); ini_asyncreq(); PRE_THREADING_HOOK; #if defined(_WRS_KERNEL) progname = "tcf"; open_log_file("-"); log_mode = 0; #else progname = argv[0]; /* Parse arguments */ for (ind = 1; ind < argc; ind++) { char * s = argv[ind]; if (*s++ != '-') break; while (s && (c = *s++) != '\0') { switch (c) { case 'i': interactive = 1; break; case 't': #if ENABLE_RCBP_TEST test_proc(); #endif exit(0); break; case 'd': #if defined(_WIN32) || defined(__CYGWIN__) /* For Windows the only way to detach a process is to * create a new process, so we patch the -d option to * -D for the second time we get invoked so we don't * keep on creating new processes forever. */ s[-1] = 'D'; daemon = 2; break; case 'D': #endif daemon = 1; break; case 'c': generate_ssl_certificate(); exit(0); break; case 'S': print_server_properties = 1; break; case 'h': show_help(); exit(0); case 'I': #if ENABLE_Trace case 'l': #endif case 'L': case 's': case 'g': #if ENABLE_Plugins case 'P': #endif if (*s == '\0') { if (++ind >= argc) { fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c); exit(1); } s = argv[ind]; } switch (c) { case 'I': idle_timeout = strtol(s, 0, 0); break; #if ENABLE_Trace case 'l': log_level = s; parse_trace_mode(log_level, &log_mode); break; #endif case 'L': log_name = s; break; case 's': url = s; break; #if ENABLE_DebugContext case 'g': if (ini_gdb_rsp(s) < 0) { fprintf(stderr, "Cannot create GDB server: %s\n", errno_to_str(errno)); exit(1); } break; #endif #if ENABLE_Plugins case 'P': plugins_path = s; break; #endif } s = NULL; break; default: ILLEGAL_OPTION_HOOK; fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); show_help(); exit(1); } } } POST_OPTION_HOOK; if (daemon) { #if defined(_WIN32) || defined(__CYGWIN__) become_daemon(daemon > 1 ? argv : NULL); #else become_daemon(); #endif } open_log_file(log_name); #endif bcg = broadcast_group_alloc(); proto = protocol_alloc(); /* The static services must be initialised before the plugins */ #if ENABLE_Cmdline if (interactive) ini_cmdline_handler(interactive, proto); #else if (interactive) fprintf(stderr, "Warning: This version does not support interactive mode.\n"); #endif ini_services(proto, bcg); #if !defined(_WRS_KERNEL) /* Reparse log level in case initialization cause additional * levels to be registered */ if (log_level != NULL && parse_trace_mode(log_level, &log_mode) != 0) { fprintf(stderr, "Cannot parse log level: %s\n", log_level); exit(1); } #endif if (ini_server(url, proto, bcg) < 0) { fprintf(stderr, "Cannot create TCF server: %s\n", errno_to_str(errno)); exit(1); } discovery_start(); if (print_server_properties) { ChannelServer * s; char * server_properties; assert(!list_is_empty(&channel_server_root)); s = servlink2channelserverp(channel_server_root.next); server_properties = channel_peer_to_json(s->ps); printf("Server-Properties: %s\n", server_properties); fflush(stdout); trace(LOG_ALWAYS, "Server-Properties: %s", server_properties); loc_free(server_properties); } PRE_DAEMON_HOOK; #if !defined(_WRS_KERNEL) if (daemon) close_out_and_err(); #endif #if ENABLE_SignalHandlers signal(SIGABRT, signal_handler); signal(SIGILL, signal_handler); signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); #if defined(_WIN32) || defined(__CYGWIN__) SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE); AddVectoredExceptionHandler(1, VectoredExceptionHandler); #endif #endif /* ENABLE_SignalHandlers */ if (idle_timeout != 0) { add_channel_close_listener(channel_closed); check_idle_timeout(NULL); } /* Process events - must run on the initial thread since ptrace() * returns ECHILD otherwise, thinking we are not the owner. */ run_event_loop(); #if ENABLE_Plugins plugins_destroy(); #endif /* ENABLE_Plugins */ return 0; }
void main(int argc, int* argv) { int i; int rv; start_gui("hellO",args,arg,0,DEF_CB,"draw_hello",draw_hello,DONE); create_window("Hello",0,0,200,100,0,SET_PROP,"ON_REDRAW",1,"draw_hello",DONE); run_event_loop(&rv); printf("Opening %s... ",BTSERIAL); //can_board = fopen(BTSERIAL,"r+"); can_board = open(BTSERIAL,O_RDWR|O_NONBLOCK); hdlc_frame = malloc(sizeof(HDLC_OBJ_T)); ringbuffer = malloc(sizeof(RINGBUFF_T)); RingBuffer_Init(ringbuffer, rb_data, rb_itemSize, RB_LEN); printf("Ringbuffer initialized\r\n"); hdlc_init(); if (can_board != 0) { printf("Success\r\n"); printf("1 - Send command\r\n" "2 - Listen only\r\n"); while(1) { if(inputAvailable()) { printf("Input available\r\n"); scanf("%d",&input); if(input == 1) { sendCommand(); } else if (input == 2) { while(1) { //fscanf(can_board, "%s",(char *)buffer); numread = read(can_board,buffer,64); if(numread > 0) { printf("%s\r\n",(char *)buffer); } } } printf("1 - Send command\r\n" "2 - Listen only\r\n"); } // else { // printf("no input available"); // } //numread = fread(buffer,1,64,can_board); numread = read(can_board,buffer,64); if(numread > 0) { printf("Read something:"); RingBuffer_InsertMult(ringbuffer, buffer,numread); for(i = 0; i< numread; i++){ printf(" %x",buffer[i]); } printf("\r\n"); hdlc_frame_parser(ringbuffer); } else { printf("Nothing read\r\n"); } sleep(1); } // fclose(can_board); close(can_board); } return; }
int tcf_log(void) { #else int main(int argc, char ** argv) { int c; int ind; const char * log_name = "-"; #endif const char * url = "TCP:"; PeerServer * ps; ChannelServer * serv; ini_mdep(); ini_trace(); ini_events_queue(); ini_asyncreq(); log_mode = LOG_TCFLOG; #if defined(_WRS_KERNEL) progname = "tcf"; open_log_file("-"); #else progname = argv[0]; /* Parse arguments */ for (ind = 1; ind < argc; ind++) { const char * s = argv[ind]; if (*s != '-') { break; } s++; while ((c = *s++) != '\0') { switch (c) { case 'h': show_help(); exit (0); case 'l': case 'L': case 's': if (*s == '\0') { if (++ind >= argc) { fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c); exit(1); } s = argv[ind]; } switch (c) { case 'l': if (parse_trace_mode(s, &log_mode) != 0) { fprintf(stderr, "Cannot parse log level: %s\n", s); exit(1); } break; case 'L': log_name = s; break; case 's': url = s; break; default: fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); show_help(); exit(1); } s = ""; break; default: fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c); show_help(); exit(1); } } } open_log_file(log_name); if (ind < argc) { dest_url = argv[ind++]; } #endif ps = channel_peer_from_url(url); if (ps == NULL) { fprintf(stderr, "%s: invalid server URL (-s option value): %s\n", progname, url); exit(1); } peer_server_addprop(ps, loc_strdup("Name"), loc_strdup("TCF Protocol Logger")); peer_server_addprop(ps, loc_strdup("Proxy"), loc_strdup("")); serv = channel_server(ps); if (serv == NULL) { fprintf(stderr, "%s: cannot create TCF server: %s\n", progname, errno_to_str(errno)); exit(1); } serv->new_conn = channel_new_connection; discovery_start(); /* Process events - must run on the initial thread since ptrace() * returns ECHILD otherwise, thinking we are not the owner. */ run_event_loop(); return 0; }