static DWORD test_do(HWND hwnd) { int s = net_init(); fd_set rfds; struct timeval tv; struct sockaddr_in to; struct sockaddr_in from; int start = time(NULL); int ret = 0; net_address(&to, config_get("Host"), config_get_int("Port")); net_bind("0.0.0.0", 8054); net_write_int8(CMD_TESTP2P); net_write_int32(start); while (time(NULL) < start + 5) { net_send_noflush(&to); FD_ZERO(&rfds); FD_SET(s, &rfds); tv.tv_sec = 1; tv.tv_usec = 0; if (select(s + 1, &rfds, NULL, NULL, &tv) > -1) { if (FD_ISSET(s, &rfds)) { net_recv(&from); if (net_read_int8() == CMD_TESTP2P && net_read_int32() == start) { ret = 1; break; } } } } net_free(); PostMessage(hwnd, WM_USER + 2, ret, 0); return 0; }
int main(void) { cpu_interval = 0; int mem_load; int display_mode = mode_CPU; char tmp_value[20]; mem_tot = mem_total()/1024; lcd_line(" RPi i2c test"); lcd_line(" Copyright (C)"); lcd_line(" 2013"); lcd_line("Jesper Stockenstrand"); usleep(5000000); for(;;) { int cpu_l; switch (display_mode) { case mode_CPU: cpu_l = cpu_load(); sprintf(tmp_value," %d%%",cpu_l); lcd_line(" CPU LOAD "); lcd_line(tmp_value); lcd_line(" "); lcd_line(">CPU<[MEM][NET][UPT]"); break; case mode_MEM: mem_load = (int)(((double)mem_used()/(double)mem_tot)*100); lcd_line(" MEM USAGE "); sprintf(tmp_value," %d/%dMb",mem_used(),mem_tot); lcd_line(tmp_value); sprintf(tmp_value," %d%%",mem_load); lcd_line(tmp_value); lcd_line("[CPU]>MEM<[NET][UPT]"); break; case mode_NET: lcd_line(" IP ADDRESS "); sprintf(tmp_value," %s", net_address()); lcd_line(tmp_value); lcd_line(" "); lcd_line("[CPU][MEM]>NET<[UPT]"); break; case mode_UPT: lcd_line(" UP TIME "); sprintf(tmp_value," %d sec",uptime()); lcd_line(tmp_value); lcd_line(" "); lcd_line("[CPU][MEM][NET]>UPT<"); break; default: display_mode = mode_CPU; } switch (checkButton()) { case 1: display_mode = mode_CPU; break; case 2: display_mode = mode_MEM; break; case 3: display_mode = mode_NET; break; case 4: display_mode = mode_UPT; break; } usleep(10000); } return(0); }
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { if (fdwReason == DLL_PROCESS_ATTACH) { const char *cfg_p2p; const char *cfg_host; int s, cfg_port = 9001; #ifdef _DEBUG freopen("stdout.txt", "w", stdout); setvbuf(stdout, NULL, _IONBF, 0); #endif printf("CnCNet git~%s\n", CNCNET_REV); s = net_init(); net_opt_reuse(); if (getenv("CNCNET_HOST")) { printf("Going into online mode...\n"); /* allow CnCNet's wolapi.dll to inject itself */ if (GetFileAttributes("wolapi.dll") != INVALID_FILE_ATTRIBUTES) { printf("Loading wolapi.dll for WOL mode\n"); wolapi_dll = LoadLibrary("wolapi.dll"); } cfg_host = getenv_default("CNCNET_HOST", "server.cncnet.org"); cfg_port = atoi(getenv_default("CNCNET_PORT", "9001")); cfg_p2p = getenv_default("CNCNET_P2P", "false"); if (STR_TRUE(cfg_p2p)) { printf("Peer-to-peer is enabled\n"); my_p2p = 1; } if (cfg_port < 1024 || cfg_port > 65534) { cfg_port = 9001; } printf("Broadcasting to %s:%d\n", cfg_host, cfg_port); dedicated = 1; net_address(&server, cfg_host, cfg_port); if (my_p2p) { net_bind("0.0.0.0", 8054); } } else { printf("CnCNet: Going into LAN mode...\n"); net_address(&server, "255.255.255.255", 5000); net_opt_broadcast(s); net_bind("0.0.0.0", 5000); } } if (fdwReason == DLL_PROCESS_DETACH) { net_free(); if (wolapi_dll) FreeLibrary(wolapi_dll); } return TRUE; }