From fa113a12e700907f39888bc57d69b233fb64cec9 Mon Sep 17 00:00:00 2001 From: zsx Date: Sun, 10 Dec 2017 22:23:37 +0800 Subject: [PATCH] acl stream and servers support UNIX domain socket in UDP packet mode --- app/master/daemon/master/master_ent.cpp | 38 ++++---- app/master/daemon/master/master_listen.cpp | 2 +- dist/master/conf/main.cf | 42 ++++----- lib_acl/changes.txt | 4 + lib_acl/include/net/acl_vstream_net.h | 3 +- lib_acl/samples/ifconf/main.cpp | 16 ++++ lib_acl/src/net/acl_vstream_net.c | 23 ++--- lib_acl/src/net/listen/acl_sane_bind.c | 86 ++++++++++++++++++- lib_acl/src/stdlib/acl_vstream.c | 60 ++++++++++--- .../include/acl_cpp/stream/socket_stream.hpp | 3 +- lib_acl_cpp/samples/udp_client/main.cpp | 1 + lib_acl_cpp/samples/udp_client/t.sh | 4 + lib_acl_cpp/src/stream/socket_stream.cpp | 13 +-- 13 files changed, 228 insertions(+), 67 deletions(-) create mode 100644 lib_acl_cpp/samples/udp_client/t.sh diff --git a/app/master/daemon/master/master_ent.cpp b/app/master/daemon/master/master_ent.cpp index b11fc7a13..13f92b934 100644 --- a/app/master/daemon/master/master_ent.cpp +++ b/app/master/daemon/master/master_ent.cpp @@ -358,7 +358,7 @@ static int service_udp(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv) acl_array_append(serv->addrs, addr); serv->listen_fd_count++; acl_msg_info("%s(%d), %s: add addr=%s", __FILE__, - __LINE__, __FUNCTION__, ptr); + __LINE__, __FUNCTION__, addr->addr); } acl_argv_free(addrs); @@ -494,6 +494,13 @@ static int service_args(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv, char unprivileged, chroot_var; ACL_VSTRING *junk = acl_vstring_alloc(100); + /* + if (serv->max_proc == 1) + acl_argv_add(serv->args, "-l", (char *) 0); + if (serv->max_proc == 0) + acl_argv_add(serv->args, "-z", (char *) 0); + */ + /* * Privilege level. Default is to restrict process privileges * to those of the mail owner. @@ -559,27 +566,28 @@ static int service_args(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv, serv->args = acl_argv_alloc(0); acl_argv_add(serv->args, command, (char *) 0); - name = get_str_ent(xcp, ACL_VAR_MASTER_SERV_SERVICE, (const char *) 0); - if (name == NULL || *name == 0) { - acl_msg_error("no %s found", ACL_VAR_MASTER_SERV_SERVICE); - return -1; - } - /* add "-f configure_file_path" flag */ acl_argv_add(serv->args, "-f", path, (char *) 0); /* copy the configure filepath */ serv->conf = acl_mystrdup(path); - /* - if (serv->max_proc == 1) - acl_argv_add(serv->args, "-l", (char *) 0); - if (serv->max_proc == 0) - acl_argv_add(serv->args, "-z", (char *) 0); - */ + name = get_str_ent(xcp, ACL_VAR_MASTER_SERV_SERVICE, (const char *) 0); + if (name == NULL || *name == 0) { + acl_msg_error("no %s found", ACL_VAR_MASTER_SERV_SERVICE); + return -1; + } if (strcmp(acl_safe_basename(command), name) != 0) { - char *tmp = acl_concatenate("\"", name, "\"", 0); + const char udp[] = "@udp"; + char *tmp; + + if (acl_strrncasecmp(name, udp, sizeof(udp) - 1) == 0) + tmp = acl_concatenate("\"", acl_var_master_queue_dir, + "/", ACL_MASTER_CLASS_PUBLIC, "/", + name, "\"", 0); + else + tmp = acl_concatenate("\"", name, "\"", 0); acl_argv_add(serv->args, "-n", tmp, (char *) 0); acl_myfree(tmp); } @@ -909,7 +917,7 @@ ACL_MASTER_SERV *acl_master_ent_find(const char *path) ACL_MASTER_SERV *serv; if (acl_var_master_head == NULL) { - acl_msg_error("%s(%d), %s: acl_var_master_head null", + acl_msg_info("%s(%d), %s: acl_var_master_head null", __FILE__, __LINE__, __FUNCTION__); return NULL; } diff --git a/app/master/daemon/master/master_listen.cpp b/app/master/daemon/master/master_listen.cpp index b70a1f4bd..f15a22c93 100644 --- a/app/master/daemon/master/master_listen.cpp +++ b/app/master/daemon/master/master_listen.cpp @@ -141,7 +141,7 @@ static int master_bind_udp(ACL_MASTER_SERV *serv) switch (addr->type) { case ACL_MASTER_SERV_TYPE_UDP: serv->listen_streams[i] = acl_vstream_bind(addr->addr, - acl_var_master_rw_timeout); + acl_var_master_rw_timeout, serv->inet_flags); break; default: acl_msg_panic("invalid type: %d, addr: %s", diff --git a/dist/master/conf/main.cf b/dist/master/conf/main.cf index 1ec80f93b..dcc87261a 100644 --- a/dist/master/conf/main.cf +++ b/dist/master/conf/main.cf @@ -1,48 +1,48 @@ #inet_interfaces = all -# 默认的每个服务的最大进程数 +# 榛樿鐨勬瘡涓湇鍔$殑鏈澶ц繘绋嬫暟 default_process_limit = 250 -# 用户属主 +# 鐢ㄦ埛灞炰富 owner_user = root master_owner = root -# 当停止 master 时是否等待所有子进程退出 +# 褰撳仠姝 master 鏃舵槸鍚︾瓑寰呮墍鏈夊瓙杩涚▼閫鍑 waiting_on_stop = true -# 组主 +# 缁勪富 owner_group = root -# 如果子进程服务异常退出,重启该子进程服务的时间间隔(秒) -service_throttle_time = 60 -# 父进程进程名 +# 濡傛灉瀛愯繘绋嬫湇鍔″紓甯搁鍑猴紝閲嶅惎璇ュ瓙杩涚▼鏈嶅姟鐨勬椂闂撮棿闅(绉) +service_throttle_time = 10 +# 鐖惰繘绋嬭繘绋嬪悕 process_name = acl_master #daemon_timeout = 18000 buf_size = 81920 -# 父进程与子进程通信时的读写超时时间(秒) +# 鐖惰繘绋嬩笌瀛愯繘绋嬮氫俊鏃剁殑璇诲啓瓒呮椂鏃堕棿(绉) rw_timeout = 60 -# 父进程通知子进程重新加载配置时获得子进程反馈的超时时间(毫秒) +# 鐖惰繘绋嬮氱煡瀛愯繘绋嬮噸鏂板姞杞介厤缃椂鑾峰緱瀛愯繘绋嬪弽棣堢殑瓒呮椂鏃堕棿(姣) reload_timeout = 5000 #max_use = 100 #max_idle = 100 #in_flow_delay = 1 -# 调用 select 循环时的等待秒级值 +# 璋冪敤 select 寰幆鏃剁殑绛夊緟绉掔骇鍊 event_delay_sec = 1 -# 调用 select 循环时的等待微秒级值 +# 璋冪敤 select 寰幆鏃剁殑绛夊緟寰绾у event_delay_usec = 5000 -# 所有服务进程程序所在的默认目录 +# 鎵鏈夋湇鍔¤繘绋嬬▼搴忔墍鍦ㄧ殑榛樿鐩綍 daemon_directory = {install_path}/libexec -# acl_master 进程运行时的日志记录文件 +# acl_master 杩涚▼杩愯鏃剁殑鏃ュ織璁板綍鏂囦欢 log_file = {install_path}/var/log/acl_master -# 所有服务进程的服务配置文件所在的目录 +# 鎵鏈夋湇鍔¤繘绋嬬殑鏈嶅姟閰嶇疆鏂囦欢鎵鍦ㄧ殑鐩綍 service_directory = {install_path}/conf/service -# 是否扫描并行 {install_path}/conf/service/ 目录下的子目录服务配置文件,0 -- 否,1 -- 是 +# 鏄惁鎵弿骞惰 {install_path}/conf/service/ 鐩綍涓嬬殑瀛愮洰褰曟湇鍔¢厤缃枃浠讹紝0 -- 鍚︼紝1 -- 鏄 scan_subdir = 0 -# 扫描 service_directory 下的配置文件时,指定的文件扩展名 +# 鎵弿 service_directory 涓嬬殑閰嶇疆鏂囦欢鏃讹紝鎸囧畾鐨勬枃浠舵墿灞曞悕 file_exts = .cf, .conf -# 指定了单独要启动的服务的配置文件列表 +# 鎸囧畾浜嗗崟鐙鍚姩鐨勬湇鍔$殑閰嶇疆鏂囦欢鍒楄〃 service_file = {install_path}/conf/services.cf -# master 程序运行目录 +# master 绋嬪簭杩愯鐩綍 queue_directory = {install_path}/var -# 记录 acl_master 运行时的进程号 +# 璁板綍 acl_master 杩愯鏃剁殑杩涚▼鍙 pid_file = {install_path}/var/pid/acl_master.pid -# 是否允许自动切换用户运行身份 +# 鏄惁鍏佽鑷姩鍒囨崲鐢ㄦ埛杩愯韬唤 # limit_privilege = 0 -# acl_master 对外 WEB 管理接口地址 +# acl_master 瀵瑰 WEB 绠$悊鎺ュ彛鍦板潃 #manage_addr = 127.0.0.1:8190 manage_addr = {install_path}/var/public/master.sock diff --git a/lib_acl/changes.txt b/lib_acl/changes.txt index 9faaab4e8..d8329747c 100644 --- a/lib_acl/changes.txt +++ b/lib_acl/changes.txt @@ -1,6 +1,10 @@ 修改历史列表: ------------------------------------------------------------------------ +615) 2017.12.10 +615.1) feature: acl_udp_server.c 支持绑定 UNIX 域套接口 +615.2) feature: net 中的 udp 模块支持绑定 UNIX 域套接口传输数据 + 614) 2017.11.21 614.1) feature: acl_argv.c 增加 acl_argv_set 用于替换指定下标位置的值 diff --git a/lib_acl/include/net/acl_vstream_net.h b/lib_acl/include/net/acl_vstream_net.h index df2e1ce48..5fabd2dca 100644 --- a/lib_acl/include/net/acl_vstream_net.h +++ b/lib_acl/include/net/acl_vstream_net.h @@ -89,9 +89,10 @@ ACL_API ACL_VSTREAM *acl_vstream_connect(const char *addr, int block_mode, * @param addr {const char*} 本地 UDP 地址,格式:ip:port,可以输入地址 ip:0 来让 * 操作系统自动分配本地端口号 * @param rw_timeout {int} 读写超时时间(秒) + * @param flag {unsigned} 标志位 * @return {ACL_VSTREAM*} 返回 NULL 表示绑定失败 */ -ACL_API ACL_VSTREAM *acl_vstream_bind(const char *addr, int rw_timeout); +ACL_API ACL_VSTREAM *acl_vstream_bind(const char *addr, int rw_timeout, unsigned flag); /** * 将网络流对象设置为 UDP IO 模式 diff --git a/lib_acl/samples/ifconf/main.cpp b/lib_acl/samples/ifconf/main.cpp index 02b73751b..1340a612b 100644 --- a/lib_acl/samples/ifconf/main.cpp +++ b/lib_acl/samples/ifconf/main.cpp @@ -5,6 +5,8 @@ int main(void) ACL_IFCONF *ifconf; /* 网卡查询结果对象 */ ACL_IFADDR *ifaddr; /* 每个网卡信息对象 */ ACL_ITER iter; /* 遍历对象 */ + const char *pattern = "127.*.*.*:8290, 192.168.*.*:8290"; + ACL_ARGV *addrs; /* 查询本机所有网卡信息 */ ifconf = acl_get_ifaddrs(); @@ -23,5 +25,19 @@ int main(void) /* 释放查询结果 */ acl_free_ifaddrs(ifconf); + printf("\r\n----------------------------------------------\r\n"); + + addrs = acl_ifconf_search(pattern); + if (addrs == NULL) { + printf("acl_ifconf_search error\r\n"); + return 1; + } + acl_foreach(iter, addrs) { + const char *addr = (const char *)iter.data; + printf(">>>ip: %s\r\n", addr); + } + acl_argv_free(addrs); + + return 0; } diff --git a/lib_acl/src/net/acl_vstream_net.c b/lib_acl/src/net/acl_vstream_net.c index 4c89ddb90..c7999dc05 100644 --- a/lib_acl/src/net/acl_vstream_net.c +++ b/lib_acl/src/net/acl_vstream_net.c @@ -191,10 +191,9 @@ ACL_VSTREAM *acl_vstream_connect_ex(const char *addr, acl_msg_fatal("%s: addr null", myname); ptr = strchr(addr, ':'); - if (ptr != NULL) { + if (ptr != NULL) connfd = acl_inet_connect_ex(addr, block_mode, connect_timeout, he_errorp); - } #ifdef ACL_WINDOWS else { acl_msg_error("%s(%d): addr(%s) invalid", @@ -202,13 +201,11 @@ ACL_VSTREAM *acl_vstream_connect_ex(const char *addr, return NULL; } #elif defined(ACL_UNIX) - else { + else connfd = acl_unix_connect(addr, block_mode, connect_timeout); - } #else - else { + else connfd = ACL_SOCKET_INVALID; - } #endif if (connfd == ACL_SOCKET_INVALID) @@ -235,6 +232,8 @@ ACL_VSTREAM *acl_vstream_connect(const char *addr, int block_mode, rw_timeout, rw_bufsize, NULL); } +/****************************************************************************/ + static int udp_read(ACL_SOCKET fd, void *buf, size_t size, int timeout acl_unused, ACL_VSTREAM *stream, void *arg acl_unused) { @@ -283,6 +282,7 @@ static int udp_write(ACL_SOCKET fd, const void *buf, size_t size, return ret; } +#if 0 static ACL_SOCKET acl_bind(const char *addr, char *addr_buf, size_t size) { const char *myname = "acl_bind"; @@ -401,12 +401,14 @@ static ACL_SOCKET acl_bind(const char *addr, char *addr_buf, size_t size) return sock; } +#endif -ACL_VSTREAM *acl_vstream_bind(const char *addr, int rw_timeout) +ACL_VSTREAM *acl_vstream_bind(const char *addr, int rw_timeout, unsigned flag) { ACL_VSTREAM *stream; - char addr_buf[256]; - ACL_SOCKET sock = acl_bind(addr, addr_buf, sizeof(addr_buf)); +// char addr_buf[256]; +// ACL_SOCKET sock = acl_bind(addr, addr_buf, sizeof(addr_buf)); + ACL_SOCKET sock = acl_udp_bind(addr, flag); if (sock == ACL_SOCKET_INVALID) { acl_msg_error("%s: bind addr %s error %s", @@ -418,7 +420,8 @@ ACL_VSTREAM *acl_vstream_bind(const char *addr, int rw_timeout) stream->rw_timeout = rw_timeout; /* 设置本地绑定地址 */ - acl_vstream_set_local(stream, addr_buf); +// acl_vstream_set_local(stream, addr_buf); + acl_vstream_set_local(stream, addr); /* 注册流读写回调函数 */ acl_vstream_ctl(stream, diff --git a/lib_acl/src/net/listen/acl_sane_bind.c b/lib_acl/src/net/listen/acl_sane_bind.c index 6b2defb77..e67762490 100644 --- a/lib_acl/src/net/listen/acl_sane_bind.c +++ b/lib_acl/src/net/listen/acl_sane_bind.c @@ -66,11 +66,95 @@ ACL_SOCKET acl_inet_bind(const struct addrinfo *res, unsigned flag) return fd; } +#ifdef ACL_UNIX +static ACL_SOCKET acl_unix_bind(const char *addr, unsigned flag) +{ +#undef sun + struct sockaddr_un sun; + int len = strlen(addr); + ACL_SOCKET sock; + + /* + * Translate address information to internal form. + */ + if (len >= (int) sizeof(sun.sun_path)) { + acl_msg_error("%s: addr too long: %s", __FUNCTION__, addr); + return ACL_SOCKET_INVALID; + } + + memset((char *) &sun, 0, sizeof(sun)); + sun.sun_family = AF_UNIX; +#ifdef HAS_SUN_LEN + sun.sun_len = len + 1; +#endif + memcpy(sun.sun_path, addr, len + 1); + + /* + * Create a listener socket. Do whatever we can so we don't run into + * trouble when this process is restarted after crash. + */ + if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) == ACL_SOCKET_INVALID) { + acl_msg_error("%s: create socket error %s", + __FUNCTION__, acl_last_serror()); + return ACL_SOCKET_INVALID; + } + + (void) unlink(addr); + + if (bind(sock, (struct sockaddr *) & sun, sizeof(sun)) < 0) { + acl_msg_error("%s: bind %s error %s", + __FUNCTION__, addr, acl_last_serror()); + acl_socket_close(sock); + return ACL_SOCKET_INVALID; + } + +#ifdef FCHMOD_UNIX_SOCKETS + if (fchmod(sock, 0666) < 0) { + acl_msg_fatal("%s: fchmod socket %s: %s", + __FUNCTION__, addr, acl_last_serror()); + acl_socket_close(sock); + return ACL_SOCKET_INVALID; + } +#else + if (chmod(addr, 0666) < 0) { + acl_msg_error("%s: chmod socket error %s, addr=%s", + __FUNCTION__, acl_last_serror(), addr); + acl_socket_close(sock); + return ACL_SOCKET_INVALID; + } +#endif + acl_non_blocking(sock, flag & ACL_INET_FLAG_NBLOCK ? + ACL_NON_BLOCKING : ACL_BLOCKING); + + return sock; +} +#endif + ACL_SOCKET acl_udp_bind(const char *addr, unsigned flag) { - struct addrinfo *res0 = acl_host_addrinfo(addr, SOCK_DGRAM), *res; + struct addrinfo *res0, *res; ACL_SOCKET fd; +#ifdef ACL_UNIX + const char udp_suffix[] = "@udp"; + + if (acl_strrncasecmp(addr, udp_suffix, sizeof(udp_suffix) - 1) == 0) { + char *buf = acl_mystrdup(addr), *at = strchr(buf, '@'); + *at = 0; + if (*buf == 0) { + acl_msg_error("%s(%d): invalid addr=%s", + __FILE__, __LINE__, addr); + acl_myfree(buf); + return ACL_SOCKET_INVALID; + } + fd = acl_unix_bind(buf, flag); + printf("bind fd=%d, buf=%s\r\n", fd, buf); + acl_myfree(buf); + return fd; + } +#endif + + res0 = acl_host_addrinfo(addr, SOCK_DGRAM); if (res0 == NULL) { acl_msg_error("%s(%d): host_addrinfo NULL, addr=%s", __FILE__, __LINE__, addr); diff --git a/lib_acl/src/stdlib/acl_vstream.c b/lib_acl/src/stdlib/acl_vstream.c index 0191bcc8e..a39d9b621 100644 --- a/lib_acl/src/stdlib/acl_vstream.c +++ b/lib_acl/src/stdlib/acl_vstream.c @@ -2989,20 +2989,26 @@ int acl_vstream_close(ACL_VSTREAM *fp) static struct sockaddr *set_sock_addr(const char *addr, size_t *sa_size) { - char buf[256], *ptr; + char buf[1024], *ptr; int port; snprintf(buf, sizeof(buf), "%s", (addr)); + ptr = strchr(buf, ':'); - if (ptr == NULL) { - *sa_size = 0; - return NULL; + if (ptr == NULL) + port = -1; + else { + *ptr++ = 0; + port = atoi(ptr); } - *ptr++ = 0; - port = atoi(ptr); if (acl_is_ipv4(buf)) { - struct sockaddr_in *in = (struct sockaddr_in *) + struct sockaddr_in *in; + if (port < 0) { + *sa_size = 0; + return NULL; + } + in = (struct sockaddr_in *) acl_mycalloc(1, sizeof(struct sockaddr_in)); in->sin_family = AF_INET; in->sin_port = htons(port); @@ -3013,7 +3019,12 @@ static struct sockaddr *set_sock_addr(const char *addr, size_t *sa_size) } #ifdef AF_INET6 else if (acl_is_ipv6(buf)) { - struct sockaddr_in6 *in = (struct sockaddr_in6 *) + struct sockaddr_in6 *in; + if (port < 0) { + *sa_size = 0; + return NULL; + } + in = (struct sockaddr_in6 *) acl_mycalloc(1, sizeof(struct sockaddr_in6)); in->sin6_family = AF_INET6; in->sin6_port = htons(port); @@ -3022,10 +3033,37 @@ static struct sockaddr *set_sock_addr(const char *addr, size_t *sa_size) return (struct sockaddr *) in; } #endif - else { - *sa_size = 0; - return NULL; + +#ifdef ACL_UNIX +#define UDP_SUFFIX "@udp" + + if (acl_strrncasecmp(buf, UDP_SUFFIX, sizeof(UDP_SUFFIX) - 1) == 0) { + struct sockaddr_un *un; + char *at = strrchr(buf, '@'); + int len; + + *at = 0; + len = (int) strlen(buf); + if (len == 0) { + *sa_size = 0; + return NULL; + } + + un = (struct sockaddr_un *) + acl_mycalloc(1, sizeof(struct sockaddr_un)); + un->sun_family = AF_UNIX; +#ifdef HAS_SUN_LEN + un->sun_len = len + 1; +#endif + memcpy(un->sun_path, buf, len + 1); + *sa_size = sizeof(struct sockaddr_un); + printf("set sock addr=%s\r\n", buf); + return (struct sockaddr *) un; } +#endif + + *sa_size = 0; + return NULL; } void acl_vstream_set_local(ACL_VSTREAM *fp, const char *addr) diff --git a/lib_acl_cpp/include/acl_cpp/stream/socket_stream.hpp b/lib_acl_cpp/include/acl_cpp/stream/socket_stream.hpp index cab5db387..cf41c50d3 100644 --- a/lib_acl_cpp/include/acl_cpp/stream/socket_stream.hpp +++ b/lib_acl_cpp/include/acl_cpp/stream/socket_stream.hpp @@ -55,9 +55,10 @@ public: * 绑定本地 UDP 地址,创建 UDP 网络流对象 * @param addr {const char*} 本机地址,格式:ip:port * @param rw_timeout {int} 读写超时时间(秒) + * @param flag {unsigned} * @return {bool} 绑定是否成功 */ - bool bind_udp(const char* addr, int rw_timeout = 0); + bool bind_udp(const char* addr, int rw_timeout = 0, unsigned flag = 0); /** * 关闭套接口读操作 diff --git a/lib_acl_cpp/samples/udp_client/main.cpp b/lib_acl_cpp/samples/udp_client/main.cpp index 9967a35ee..d973b72c0 100644 --- a/lib_acl_cpp/samples/udp_client/main.cpp +++ b/lib_acl_cpp/samples/udp_client/main.cpp @@ -100,6 +100,7 @@ int main(int argc, char* argv[]) #ifdef WIN32 acl::acl_cpp_init(); #endif + acl::log::stdout_open(true); snprintf(__server_addr, sizeof(__server_addr), "127.0.0.1:8888"); snprintf(__local_addr, sizeof(__local_addr), "127.0.0.1:18888"); diff --git a/lib_acl_cpp/samples/udp_client/t.sh b/lib_acl_cpp/samples/udp_client/t.sh new file mode 100644 index 000000000..a0c0f394f --- /dev/null +++ b/lib_acl_cpp/samples/udp_client/t.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# udp transfer with UNIX domain socket +#./udp_client -s /opt/soft/acl-master/var/public/test.sock@udp -l /tmp/tt.sock@udp -n 100000 +./udp_client -s 127.0.0.1:8888 -l 127.0.0.1:8889 -n 100000 diff --git a/lib_acl_cpp/src/stream/socket_stream.cpp b/lib_acl_cpp/src/stream/socket_stream.cpp index 202adf474..72c8b6cb3 100644 --- a/lib_acl_cpp/src/stream/socket_stream.cpp +++ b/lib_acl_cpp/src/stream/socket_stream.cpp @@ -51,11 +51,12 @@ bool socket_stream::open(ACL_VSTREAM* vstream, bool udp_mode /* = false */) return true; } -bool socket_stream::bind_udp(const char* addr, int rw_timeout /* = 0 */) +bool socket_stream::bind_udp(const char* addr, int rw_timeout /* = 0 */, + unsigned flag /* = 0 */) { if (stream_) acl_vstream_close(stream_); - stream_ = acl_vstream_bind(addr, rw_timeout); + stream_ = acl_vstream_bind(addr, rw_timeout, flag); if (stream_ == NULL) return false; eof_ = false; @@ -140,8 +141,8 @@ const char* socket_stream::get_peer_ip() const if (stream_ == NULL) return dummy_; - if (peer_ip_[0] != 0) - return peer_ip_; + //if (peer_ip_[0] != 0) + // return peer_ip_; char* ptr = ACL_VSTREAM_PEER(stream_); if (ptr == NULL || *ptr == 0) @@ -203,8 +204,8 @@ const char* socket_stream::get_local_ip() const return dummy_; // xxx: acl_vstream 中没有对此地址赋值 - if (local_ip_[0] != 0) - return local_ip_; + //if (local_ip_[0] != 0) + // return local_ip_; char* ptr = ACL_VSTREAM_LOCAL(stream_); if (ptr == NULL || *ptr == 0)