int main(int argc, char **argv) { struct cmdline_args args = {0}; int ret = 0; opdb_reset(); ctrlc_init(); args.devarg.vcc_mv = 3000; args.devarg.requested_serial = NULL; if (parse_cmdline_args(argc, argv, &args) < 0) return -1; if (sockets_init() < 0) return -1; printc_dbg("%s\n", version_text); if (setup_driver(&args) < 0) { sockets_exit(); return -1; } simio_init(); if (!args.no_rc) process_rc_file(); /* Process commands */ if (optind < argc) { while (optind < argc) { if (process_command(argv[optind++]) < 0) { ret = -1; break; } } } else { reader_loop(); } simio_exit(); stab_exit(); device_destroy(); sockets_exit(); return ret; }
/** * Stops the event loops and closes all socket structures */ void Sockets_Close() { /* Close all sockets */ int i = 0; for (i = 0; i < (int) sockets.used; ++i) DS_SocketClose ((DS_Socket*) sockets.data [i]); /* Free socket array */ DS_ArrayFree (&sockets); /* Close the sockets API */ sockets_exit(); }
int main(int argc, char **argv) { struct cmdline_args args = {0}; int ret = 0; setvbuf(stderr, NULL, _IOFBF, 0); setvbuf(stdout, NULL, _IOFBF, 0); opdb_reset(); ctrlc_init(); args.devarg.vcc_mv = 3000; args.devarg.requested_serial = NULL; if (parse_cmdline_args(argc, argv, &args) < 0) goto fail_parse; if (args.flags & OPT_EMBEDDED) input_module = &input_async; if (input_module->init() < 0) goto fail_input; output_set_embedded(args.flags & OPT_EMBEDDED); if (sockets_init() < 0) { ret = -1; goto fail_sockets; } printc_dbg("%s", version_text); printc_dbg("%s\n", chipinfo_copyright()); if (setup_driver(&args) < 0) { ret = -1; goto fail_driver; } if (device_probe_id(device_default, args.devarg.forced_chip_id) < 0) printc_err("warning: device ID probe failed\n"); simio_init(); if (!(args.flags & OPT_NO_RC)) process_rc_file(args.alt_config); /* Process commands */ if (optind < argc) { while (optind < argc) { if (process_command(argv[optind++]) < 0) { ret = -1; break; } } } else { reader_loop(); } simio_exit(); device_destroy(); stab_exit(); fail_driver: sockets_exit(); fail_sockets: input_module->exit(); fail_input: fail_parse: /* We need to do this on Windows, because in embedded mode we * may still have a running background thread for input. If so, * returning from main() won't cause the process to terminate. */ #if defined(__CYGWIN__) cygwin_internal(CW_EXIT_PROCESS, (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE, 1); #elif defined(__Windows__) ExitProcess(ret); #endif return ret; }