int main(int argc, char** argv) { villa::EventManager evmgr; // TODO: read config file std::map<std::string, std::string> device_config{ {"name", "USB WDE1"}, {"connection", "/dev/ttyUSB0:9600"}}; villa::InternalConnection internalcon(&evmgr); // villa::TtyConnection con1(&evmgr, "/dev/ttyUSB0", // villa::SerialPort::BaudRate::Baud38400); // auto dev1(std::make_unique<villa::DeviceWde1>(device_config)); // con1.addDevice(std::move(dev1)); villa::TcpConnection tcpconn(&evmgr, "0.0.0.0", 9991); try { evmgr.run(); } catch (std::exception const& e) { std::cerr << "Error: " << e.what() << std::endl; } catch (...) { std::cerr << "Unknown Exception" << std::endl; return -1; } return 0; }
static void *keepalive_thread(void *arg) { int sock; int print_errmsg = 1; while (1) { sock = tcpconn(server_ip, server_port, 5); if (sock == -1) { if (print_errmsg == 1) { syslog(LOG_ERR, "connect app server failed."); print_errmsg = 0; } sleep(5); continue; } syslog(LOG_INFO, "connect app server success."); set_keepalive(sock, KEEPALIVE_IDEL, KEEPALIVE_CNT, KEEPALIVE_INTV); LOCK(mtx); server_sock = sock; UNLOCK(mtx); dummy_recv_loop(server_sock); LOCK(mtx); close(server_sock); server_sock = INVALID_SOCKET; UNLOCK(mtx); syslog(LOG_INFO, "disconnect from app server."); print_errmsg = 1; sleep(5); } return NULL; }
static int default_login_func(char *ip, int port, char *user, char *pwd, void *param) { return tcpconn(ip, port, 5); }
int main(int argc, char **argv) { int c; myname = argv[0]; memset(host_array, 0, sizeof(host_array)); while ((c = getopt(argc, argv, "hf:t:p:")) != -1) { switch (c) { case 'f': filename = optarg; break; case 'p': dest_port = atoi(optarg); break; case 'h': usage(); break; case 't': timeout = atoi(optarg); break; default: usage(); } } argc -= optind; argv += optind; if ( (*argv && filename) || (!*argv && !filename) ) { usage(); } if( *argv ) { while( *argv ) { add_host( *argv ); ++argv; } }else if( filename ) { FILE *ping_file; char line[132]; char host[132]; ping_file = fopen( filename, "r" ); if( !ping_file ) { perror("-f"); exit(1); } while( fgets( line, sizeof(line), ping_file ) ) { if( sscanf( line, "%s", host ) != 1 ) continue; if( ( !*host ) || ( host[0] == '#' ) ) /* magic to avoid comments */ continue; add_host(host); }/* WHILE */ fclose( ping_file ); } else { usage(); } if ( !host_num ) { exit(1); } tcpconn(); return 0; }