void log::open(const char* recipients, const char* procname /* = unknown */, const char* cfg /* = NULL */) { if (m_bOpened) return; acl_assert(recipients); acl_assert(procname); const char* ptr = strrchr(procname, '/'); if (ptr) procname = ptr + 1; #ifdef ACL_WINDOWS if (ptr == NULL) { ptr = strrchr(procname, '\\'); if (ptr) procname = ptr + 1; } #endif acl_msg_open(recipients, procname); m_bOpened = true; if (cfg) acl_debug_init(cfg); }
int main(int argc, char *argv[]) { int i; acl_socket_init(); acl_msg_open("debug.txt", "proctlc"); acl_msg_info(">>> in child progname(%s), argc=%d\r\n", argv[0], argc); if (argc > 1) acl_msg_info(">>> in child progname, argv[1]=(%s)\r\n", argv[1]); acl_proctl_child(argv[0], onexit_fn, NULL); for (i = 0; i < argc; i++) { acl_msg_info(">>>argv[%d]:%s\r\n", i, argv[i]); } i = 0; while (1) { acl_msg_info("i = %d\r\n", i++); if (i == 5) sleep(1); else sleep(1); } return (-1); // 返回 -1 是为了让父进程继续启动 }
static void init(void) { #ifdef USE_LOG char logfile[] = "test.log"; char logpre[] = "thread_test"; #endif int i; if (__use_slice) acl_mem_slice_init(8, 10240, 100000, ACL_SLICE_FLAG_GC2 | ACL_SLICE_FLAG_RTGC_OFF | ACL_SLICE_FLAG_LP64_ALIGN); acl_init(); #ifdef USE_LOG acl_msg_open(logfile, logpre); #endif if (__send_size <= 0) __send_size = 100; __data = acl_mycalloc(1, __send_size); assert(__data); for (i = 0; i < __send_size - 2; i++) { __data[i] = 'i'; } __data[i++] = '\n'; __data[i] = 0; echo_server_init(__data, (int) strlen(__data), __echo_src, __line_length); }
static void init(void) { acl_socket_init(); probe_cfg_load(); if (var_probe_logfile && *var_probe_logfile) acl_msg_open(var_probe_logfile, var_probe_procname); /* daemon(1, 1); */ }
int main(int argc, char *argv[]) { test(argv[1]); return 0; ACL_VSTREAM *client; const char *addr; char buf[1024]; int ret; if (argc != 2) { printf("usage: %s addr\n", argv[0]); return (0); } addr = argv[1]; acl_msg_open("connect.log", argv[0]); printf("connecting %s ...\n", argv[1]); //acl_poll_prefered(1); for (int i = 0; i < 10000; i++) { client = acl_vstream_connect(addr, ACL_BLOCKING, 10, 10, 4096); if (client == NULL) { printf("connect %s error(%s)\n", addr, acl_last_serror()); return (1); } printf("connect %s ok, %s\n", addr, acl_last_serror()); } printf(">>>>>>connect all ok\r\n"); pause(); sleep(100); acl_vstream_fprintf(client, "%s", "line1\nline2\nline3\nline4\nline5\nline6\nline7\n"); while (1) { ret = acl_vstream_gets_nonl(client, buf, sizeof(buf)); if (ret > 0) { printf("gets from %s: %s\n", addr, buf); } else if (ret == ACL_VSTREAM_EOF) { printf("get over\r\n"); break; } } acl_vstream_close(client); return (0); }
void acl_master_log_open(const char *procname) { const char *myname = "acl_master_log_open"; char *master_log; /* use master's log before chroot */ master_log = getenv("MASTER_LOG"); if (master_log == NULL) { acl_msg_info("%s(%d): no MASTER_LOG's env value", myname, __LINE__); } else { acl_msg_open(master_log, procname); var_master_log_opened = 1; if (acl_msg_verbose) acl_msg_info("%s(%d): service: %s, log opened now.", myname, __LINE__, procname); } }
BOOL Chttp_clientApp::InitInstance() { // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControls()。否则,将无法创建窗口。 InitCommonControls(); CWinApp::InitInstance(); if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("应用程序向导生成的本地应用程序")); acl_msg_open("log.txt", "http_client"); Chttp_clientDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: 在此放置处理何时用“确定”来关闭 //对话框的代码 } else if (nResponse == IDCANCEL) { // TODO: 在此放置处理何时用“取消”来关闭 //对话框的代码 } // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return FALSE; }
static void init(int use_slice) { #if 0 char logfile[] = "test.log"; char logpre[] = "thread_test"; acl_msg_open(logfile, logpre); #endif if (use_slice) acl_mem_slice_init(8, 10240, 100000, ACL_SLICE_FLAG_GC2 | ACL_SLICE_FLAG_RTGC_OFF | ACL_SLICE_FLAG_LP64_ALIGN); acl_init(); echo_client_init(ECHO_CTL_SERV_ADDR, __svr_addr, ECHO_CTL_MAX_CONNECT, __nconnect, ECHO_CTL_MAX_LOOP, __nloop, ECHO_CTL_TIMEOUT, __timeout, ECHO_CTL_DATA_LEN, __dlen, ECHO_CTL_NCONN_PERSEC, __nconn_per_sec, ECHO_CTL_EVENT_MODE, __event_mode, ECHO_CTL_END); }