mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 11:57:43 +08:00
use remote_addr@local_addr replacing the old format: local_addr@remote_addr
This commit is contained in:
parent
27c8892cec
commit
41ef6fef8f
@ -42,9 +42,9 @@ ACL_API int acl_timed_connect(ACL_SOCKET fd, const struct sockaddr * sa,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程连接网络服务器地址
|
* 远程连接网络服务器地址
|
||||||
* @param addr {const char*} 远程服务器的监听地址,如:192.168.0.1:80, 如果需
|
* @param addr {const char*} 远程服务器的监听地址,如:192.168.0.1|80, 如果需
|
||||||
* 要绑定本地的地址,则格式为: {local_ip}@{remote_addr},
|
* 要绑定本地的地址,则格式为: remote_addr@local_ip,
|
||||||
* 如: 60.28.250.199@www.sina.com:80
|
* 如: www.sina.com|80@60.28.250.199
|
||||||
* @param blocking {int} 阻塞模式还是非阻塞模式, ACL_BLOCKING 或 ACL_NON_BLOCKING
|
* @param blocking {int} 阻塞模式还是非阻塞模式, ACL_BLOCKING 或 ACL_NON_BLOCKING
|
||||||
* @param timeout {int} 连接超时时间,如果 blocking 为 ACL_NON_BLOCKING 则该值将被忽略
|
* @param timeout {int} 连接超时时间,如果 blocking 为 ACL_NON_BLOCKING 则该值将被忽略
|
||||||
* @return {ACL_SOCKET} 如果返回 ACL_SOCKET_INVALID 表示连接失败
|
* @return {ACL_SOCKET} 如果返回 ACL_SOCKET_INVALID 表示连接失败
|
||||||
@ -53,9 +53,9 @@ ACL_API ACL_SOCKET acl_inet_connect(const char *addr, int blocking, int timeout)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程连接网络服务器地址
|
* 远程连接网络服务器地址
|
||||||
* @param addr {const char*} 远程服务器的监听地址,如:192.168.0.1:80,
|
* @param addr {const char*} 远程服务器的监听地址,如:192.168.0.1|80,
|
||||||
* 当本机有多个网卡地址且想通过某个指定网卡连接服务器时的地址格式:
|
* 当本机有多个网卡地址且想通过某个指定网卡连接服务器时的地址格式:
|
||||||
* local_ip@remote_ip:remote_port,如:192.168.1.1@211.150.111.12:80
|
* remote_ip|remote_port@local_ip,如:211.150.111.12|80@192.168.1.1
|
||||||
* @param blocking {int} 阻塞模式还是非阻塞模式, ACL_BLOCKING 或 ACL_NON_BLOCKING
|
* @param blocking {int} 阻塞模式还是非阻塞模式, ACL_BLOCKING 或 ACL_NON_BLOCKING
|
||||||
* @param timeout {int} 连接超时时间,如果 blocking 为 ACL_NON_BLOCKING 则该值将被忽略
|
* @param timeout {int} 连接超时时间,如果 blocking 为 ACL_NON_BLOCKING 则该值将被忽略
|
||||||
* @param h_error {int*} 当连接失败时存储失败原因错误号
|
* @param h_error {int*} 当连接失败时存储失败原因错误号
|
||||||
@ -70,7 +70,8 @@ ACL_API ACL_SOCKET acl_inet_connect_ex(const char *addr, int blocking,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 连接监听域套接字服务器
|
* 连接监听域套接字服务器
|
||||||
* @param addr {const char*} 服务器监听的域套接字全路径, 如: /tmp/test.sock
|
* @param addr {const char*} 服务器监听的域套接字全路径, 如: /tmp/test.sock,
|
||||||
|
* 针对 Linux 平台,如果首字母为 @ 则内部自动采用抽象 UNIX 域套接口进行连接
|
||||||
* @param blocking {int} 阻塞模式还是非阻塞模式, ACL_BLOCKING 或 ACL_NON_BLOCKING
|
* @param blocking {int} 阻塞模式还是非阻塞模式, ACL_BLOCKING 或 ACL_NON_BLOCKING
|
||||||
* @param timeout {int} 连接超时时间,如果 blocking 为 ACL_NON_BLOCKING 则该值将被忽略
|
* @param timeout {int} 连接超时时间,如果 blocking 为 ACL_NON_BLOCKING 则该值将被忽略
|
||||||
* @return {ACL_SOCKET} 如果返回 ACL_SOCKET_INVALID 表示连接失败
|
* @return {ACL_SOCKET} 如果返回 ACL_SOCKET_INVALID 表示连接失败
|
||||||
|
@ -57,8 +57,10 @@ ACL_API ACL_VSTREAM *acl_vstream_accept(ACL_VSTREAM *listen_stream,
|
|||||||
/**
|
/**
|
||||||
* 远程连接服务器
|
* 远程连接服务器
|
||||||
* @param addr {const char*} 服务器地址, 如果连接一个域套接口服务器(仅UNIX平台),
|
* @param addr {const char*} 服务器地址, 如果连接一个域套接口服务器(仅UNIX平台),
|
||||||
* 域套接地址:/tmp/test.sock; 如果连接一个TCP服务器,则地址格式为:
|
* 域套接地址:/tmp/test.sock,对于 Linux 平台,如果首字母为 '@' 则表示连接本
|
||||||
* [${local_ip}@]${remote_addr}, 如: 60.28.250.199@www.sina.com:80, 意思是绑定
|
* 地的抽象UNIX域套接口(Linux abstract unix domain socket);
|
||||||
|
* 如果连接一个TCP服务器,则地址格式为:
|
||||||
|
* remote_addr[@local_ip], 如: www.sina.com|80@60.28.250.199, 意思是绑定
|
||||||
* 本的网卡地址为: 60.28.250.199, 远程连接 www.sina.com 的 80 端口, 如果由OS
|
* 本的网卡地址为: 60.28.250.199, 远程连接 www.sina.com 的 80 端口, 如果由OS
|
||||||
* 自动绑定本地 IP 地址,则可以写为:www.sina.com:80
|
* 自动绑定本地 IP 地址,则可以写为:www.sina.com:80
|
||||||
* @param block_mode {int} 阻塞连接还是非阻塞连接,ACL_BLOCKING, ACL_NON_BLOCKING
|
* @param block_mode {int} 阻塞连接还是非阻塞连接,ACL_BLOCKING, ACL_NON_BLOCKING
|
||||||
@ -73,9 +75,7 @@ ACL_API ACL_VSTREAM *acl_vstream_connect_ex(const char *addr, int block_mode,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程连接服务器
|
* 远程连接服务器
|
||||||
* @param addr {const char*} 服务器地址,格式如:127.0.0.1,
|
* @param addr {const char*} 服务器地址,含义同上
|
||||||
* 或域套接地址:/tmp/test.sock,对于 Linux 平台,如果首字母为 '@',则认为是
|
|
||||||
* Linux abstract unix domain path.
|
|
||||||
* @param block_mode {int} 阻塞连接还是非阻塞连接,ACL_BLOCKING, ACL_NON_BLOCKING
|
* @param block_mode {int} 阻塞连接还是非阻塞连接,ACL_BLOCKING, ACL_NON_BLOCKING
|
||||||
* @param connect_timeout {int} 连接超时时间(秒)
|
* @param connect_timeout {int} 连接超时时间(秒)
|
||||||
* @param rw_timeout {int} 连接流成功后的读写超时时间,单位为秒
|
* @param rw_timeout {int} 连接流成功后的读写超时时间,单位为秒
|
||||||
|
@ -39,16 +39,18 @@ static int bind_local(ACL_SOCKET sock, int family, const struct addrinfo *res0)
|
|||||||
const struct addrinfo *res;
|
const struct addrinfo *res;
|
||||||
|
|
||||||
for (res = res0; res != NULL; res = res->ai_next) {
|
for (res = res0; res != NULL; res = res->ai_next) {
|
||||||
if (res->ai_family != family)
|
if (res->ai_family != family) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ACL_WINDOWS
|
#ifdef ACL_WINDOWS
|
||||||
if (bind(sock, res->ai_addr, (int) res->ai_addrlen) == 0)
|
if (bind(sock, res->ai_addr, (int) res->ai_addrlen) == 0) {
|
||||||
#else
|
#else
|
||||||
if (bind(sock, res->ai_addr, res->ai_addrlen) == 0)
|
if (bind(sock, res->ai_addr, res->ai_addrlen) == 0) {
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -70,8 +72,10 @@ static ACL_SOCKET inet_connect_one(const struct addrinfo *peer,
|
|||||||
return ACL_SOCKET_INVALID;
|
return ACL_SOCKET_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
acl_tcp_set_rcvbuf(sock, ACL_SOCKET_RBUF_SIZE);
|
acl_tcp_set_rcvbuf(sock, ACL_SOCKET_RBUF_SIZE);
|
||||||
acl_tcp_set_sndbuf(sock, ACL_SOCKET_WBUF_SIZE);
|
acl_tcp_set_sndbuf(sock, ACL_SOCKET_WBUF_SIZE);
|
||||||
|
*/
|
||||||
|
|
||||||
on = 1;
|
on = 1;
|
||||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
||||||
@ -93,12 +97,11 @@ static ACL_SOCKET inet_connect_one(const struct addrinfo *peer,
|
|||||||
acl_non_blocking(sock, ACL_NON_BLOCKING);
|
acl_non_blocking(sock, ACL_NON_BLOCKING);
|
||||||
#ifdef ACL_WINDOWS
|
#ifdef ACL_WINDOWS
|
||||||
if (acl_timed_connect(sock, peer->ai_addr,
|
if (acl_timed_connect(sock, peer->ai_addr,
|
||||||
(socklen_t) peer->ai_addrlen, timeout) < 0)
|
(socklen_t) peer->ai_addrlen, timeout) < 0) {
|
||||||
#else
|
#else
|
||||||
if (acl_timed_connect(sock, peer->ai_addr,
|
if (acl_timed_connect(sock, peer->ai_addr,
|
||||||
peer->ai_addrlen, timeout) < 0)
|
peer->ai_addrlen, timeout) < 0) {
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
#ifdef ACL_WINDOWS
|
#ifdef ACL_WINDOWS
|
||||||
int err = acl_last_error();
|
int err = acl_last_error();
|
||||||
#endif
|
#endif
|
||||||
@ -108,8 +111,9 @@ static ACL_SOCKET inet_connect_one(const struct addrinfo *peer,
|
|||||||
#endif
|
#endif
|
||||||
return ACL_SOCKET_INVALID;
|
return ACL_SOCKET_INVALID;
|
||||||
}
|
}
|
||||||
if (blocking != ACL_NON_BLOCKING)
|
if (blocking != ACL_NON_BLOCKING) {
|
||||||
acl_non_blocking(sock, blocking);
|
acl_non_blocking(sock, blocking);
|
||||||
|
}
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,8 +139,9 @@ static ACL_SOCKET inet_connect_one(const struct addrinfo *peer,
|
|||||||
* connect and just returns EPIPE. Create a fake
|
* connect and just returns EPIPE. Create a fake
|
||||||
* error message for connect. -- fenner@parc.xerox.com
|
* error message for connect. -- fenner@parc.xerox.com
|
||||||
*/
|
*/
|
||||||
if (errno == EPIPE)
|
if (errno == EPIPE) {
|
||||||
acl_set_error(ACL_ENOTCONN);
|
acl_set_error(ACL_ENOTCONN);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ACL_WINDOWS
|
#ifdef ACL_WINDOWS
|
||||||
err = acl_last_error();
|
err = acl_last_error();
|
||||||
@ -152,11 +157,12 @@ static ACL_SOCKET inet_connect_one(const struct addrinfo *peer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ACL_WINDOWS
|
#ifdef ACL_WINDOWS
|
||||||
if (errnum == ACL_EINPROGRESS || errnum == ACL_EWOULDBLOCK)
|
if (errnum == ACL_EINPROGRESS || errnum == ACL_EWOULDBLOCK) {
|
||||||
return sock;
|
return sock;
|
||||||
#elif defined(ACL_UNIX)
|
#elif defined(ACL_UNIX)
|
||||||
if (errnum == ACL_EINPROGRESS || errnum == EISCONN)
|
if (errnum == ACL_EINPROGRESS || errnum == EISCONN) {
|
||||||
return sock;
|
return sock;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
acl_socket_close(sock);
|
acl_socket_close(sock);
|
||||||
#ifdef ACL_WINDOWS
|
#ifdef ACL_WINDOWS
|
||||||
@ -185,17 +191,27 @@ ACL_SOCKET acl_inet_connect_ex(const char *addr, int blocking,
|
|||||||
const char *peer, *local, *port;
|
const char *peer, *local, *port;
|
||||||
struct addrinfo hints, *peer_res0, *res, *local_res0;
|
struct addrinfo hints, *peer_res0, *res, *local_res0;
|
||||||
|
|
||||||
if (h_error)
|
if (h_error) {
|
||||||
*h_error = 0;
|
*h_error = 0;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf) - 1, "%s", addr);
|
snprintf(buf, sizeof(buf) - 1, "%s", addr);
|
||||||
|
peer = buf;
|
||||||
|
ptr = strchr(buf, '@');
|
||||||
|
if (ptr != NULL) {
|
||||||
|
*ptr = 0;
|
||||||
|
local = *++ptr == 0 ? NULL : ptr;
|
||||||
|
} else {
|
||||||
|
local = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (acl_valid_ipv6_hostaddr(buf, 0)) {
|
if (acl_valid_ipv6_hostaddr(peer, 0)) {
|
||||||
ptr = strrchr(buf, ACL_ADDR_SEP);
|
ptr = strrchr(peer, ACL_ADDR_SEP);
|
||||||
} else if (acl_valid_ipv4_hostaddr(buf, 0)) {
|
} else if (acl_valid_ipv4_hostaddr(peer, 0)) {
|
||||||
ptr = strrchr(buf, ACL_ADDR_SEP);
|
ptr = strrchr(peer, ACL_ADDR_SEP);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL) {
|
||||||
ptr = strrchr(buf, ':');
|
ptr = strrchr(peer, ':');
|
||||||
|
}
|
||||||
} else if (!(ptr = strrchr(buf, ACL_ADDR_SEP))) {
|
} else if (!(ptr = strrchr(buf, ACL_ADDR_SEP))) {
|
||||||
ptr = strrchr(buf, ':');
|
ptr = strrchr(buf, ':');
|
||||||
}
|
}
|
||||||
@ -215,16 +231,6 @@ ACL_SOCKET acl_inet_connect_ex(const char *addr, int blocking,
|
|||||||
return ACL_SOCKET_INVALID;
|
return ACL_SOCKET_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = strchr(buf, '@');
|
|
||||||
if (ptr != NULL) {
|
|
||||||
*ptr++ = 0;
|
|
||||||
local = buf;
|
|
||||||
peer = ptr;
|
|
||||||
} else {
|
|
||||||
local = NULL;
|
|
||||||
peer = buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(peer) == 0) {
|
if (strlen(peer) == 0) {
|
||||||
acl_msg_error("%s, %s(%d): ip buf's length is 0",
|
acl_msg_error("%s, %s(%d): ip buf's length is 0",
|
||||||
__FILE__, myname, __LINE__);
|
__FILE__, myname, __LINE__);
|
||||||
@ -255,9 +261,9 @@ ACL_SOCKET acl_inet_connect_ex(const char *addr, int blocking,
|
|||||||
return ACL_SOCKET_INVALID;
|
return ACL_SOCKET_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local == NULL)
|
if (local == NULL) {
|
||||||
local_res0 = NULL;
|
local_res0 = NULL;
|
||||||
else if ((err = getaddrinfo(local, "0", &hints, &local_res0))) {
|
} else if ((err = getaddrinfo(local, "0", &hints, &local_res0))) {
|
||||||
acl_msg_error("%s(%d), %s: getaddrinfo error %s, local=%s",
|
acl_msg_error("%s(%d), %s: getaddrinfo error %s, local=%s",
|
||||||
__FILE__, __LINE__, myname, gai_strerror(err), local);
|
__FILE__, __LINE__, myname, gai_strerror(err), local);
|
||||||
return ACL_SOCKET_INVALID;
|
return ACL_SOCKET_INVALID;
|
||||||
@ -267,18 +273,22 @@ ACL_SOCKET acl_inet_connect_ex(const char *addr, int blocking,
|
|||||||
|
|
||||||
for (res = peer_res0; res != NULL ; res = res->ai_next) {
|
for (res = peer_res0; res != NULL ; res = res->ai_next) {
|
||||||
sock = inet_connect_one(res, local_res0, blocking, timeout);
|
sock = inet_connect_one(res, local_res0, blocking, timeout);
|
||||||
if (sock != ACL_SOCKET_INVALID)
|
if (sock != ACL_SOCKET_INVALID) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sock == ACL_SOCKET_INVALID)
|
if (sock == ACL_SOCKET_INVALID) {
|
||||||
acl_msg_error("%s(%d) %s: connect error %s, addr=%s",
|
acl_msg_error("%s(%d) %s: connect error %s, addr=%s",
|
||||||
__FILE__, __LINE__, myname, acl_last_serror(), addr);
|
__FILE__, __LINE__, myname, acl_last_serror(), addr);
|
||||||
|
}
|
||||||
|
|
||||||
if (peer_res0)
|
if (peer_res0) {
|
||||||
freeaddrinfo(peer_res0);
|
freeaddrinfo(peer_res0);
|
||||||
if (local_res0)
|
}
|
||||||
|
if (local_res0) {
|
||||||
freeaddrinfo(local_res0);
|
freeaddrinfo(local_res0);
|
||||||
|
}
|
||||||
|
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
@ -59,24 +59,28 @@ int acl_stream_connect(const char *path, int block_mode, int unused_timeout)
|
|||||||
* The requested file system object must exist, otherwise we can't reach
|
* The requested file system object must exist, otherwise we can't reach
|
||||||
* the server.
|
* the server.
|
||||||
*/
|
*/
|
||||||
if ((fifo = open(path, O_WRONLY | O_NONBLOCK, 0)) < 0)
|
if ((fifo = open(path, O_WRONLY | O_NONBLOCK, 0)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a pipe, and send one pipe end to the server.
|
* Create a pipe, and send one pipe end to the server.
|
||||||
*/
|
*/
|
||||||
if (pipe(pair) < 0)
|
if (pipe(pair) < 0) {
|
||||||
acl_msg_fatal("%s: pipe: %s", myname, acl_last_serror());
|
acl_msg_fatal("%s: pipe: %s", myname, acl_last_serror());
|
||||||
if (ioctl(fifo, I_SENDFD, pair[1]) < 0)
|
}
|
||||||
|
if (ioctl(fifo, I_SENDFD, pair[1]) < 0) {
|
||||||
acl_msg_fatal("%s: send file descriptor: %s",
|
acl_msg_fatal("%s: send file descriptor: %s",
|
||||||
myname, acl_last_serror());
|
myname, acl_last_serror());
|
||||||
|
}
|
||||||
close(pair[1]);
|
close(pair[1]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is for {unix,inet}_connect() compatibility.
|
* This is for {unix,inet}_connect() compatibility.
|
||||||
*/
|
*/
|
||||||
if (block_mode == ACL_NON_BLOCKING)
|
if (block_mode == ACL_NON_BLOCKING) {
|
||||||
acl_non_blocking(pair[0], ACL_NON_BLOCKING);
|
acl_non_blocking(pair[0], ACL_NON_BLOCKING);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cleanup.
|
* Cleanup.
|
||||||
|
@ -30,31 +30,36 @@ int acl_timed_connect(ACL_SOCKET sock, const struct sockaddr * sa,
|
|||||||
* Sanity check. Just like with timed_wait(), the timeout must be a
|
* Sanity check. Just like with timed_wait(), the timeout must be a
|
||||||
* positive number.
|
* positive number.
|
||||||
*/
|
*/
|
||||||
if (timeout < 0)
|
if (timeout < 0) {
|
||||||
acl_msg_panic("timed_connect: bad timeout: %d", timeout);
|
acl_msg_panic("timed_connect: bad timeout: %d", timeout);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start the connection, and handle all possible results.
|
* Start the connection, and handle all possible results.
|
||||||
*/
|
*/
|
||||||
if (acl_sane_connect(sock, sa, len) == 0)
|
if (acl_sane_connect(sock, sa, len) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
errno = acl_last_error();
|
errno = acl_last_error();
|
||||||
|
|
||||||
#ifdef ACL_UNIX
|
#ifdef ACL_UNIX
|
||||||
if (errno != ACL_EINPROGRESS)
|
if (errno != ACL_EINPROGRESS) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
#elif defined(ACL_WINDOWS)
|
#elif defined(ACL_WINDOWS)
|
||||||
if (errno != ACL_EINPROGRESS && errno != ACL_EWOULDBLOCK)
|
if (errno != ACL_EINPROGRESS && errno != ACL_EWOULDBLOCK) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A connection is in progress. Wait for a limited amount of time for
|
* A connection is in progress. Wait for a limited amount of time for
|
||||||
* something to happen. If nothing happens, report an error.
|
* something to happen. If nothing happens, report an error.
|
||||||
*/
|
*/
|
||||||
if (acl_write_wait(sock, timeout) < 0)
|
if (acl_write_wait(sock, timeout) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Something happened. Some Solaris 2 versions have getsockopt() itself
|
* Something happened. Some Solaris 2 versions have getsockopt() itself
|
||||||
@ -69,8 +74,9 @@ int acl_timed_connect(ACL_SOCKET sock, const struct sockaddr * sa,
|
|||||||
* connect and just returns EPIPE. Create a fake
|
* connect and just returns EPIPE. Create a fake
|
||||||
* error message for connect. -- fenner@parc.xerox.com
|
* error message for connect. -- fenner@parc.xerox.com
|
||||||
*/
|
*/
|
||||||
if (errno == EPIPE)
|
if (errno == EPIPE) {
|
||||||
acl_set_error(ACL_ENOTCONN);
|
acl_set_error(ACL_ENOTCONN);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -78,6 +84,7 @@ int acl_timed_connect(ACL_SOCKET sock, const struct sockaddr * sa,
|
|||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
acl_set_error(err);
|
acl_set_error(err);
|
||||||
return -1;
|
return -1;
|
||||||
} else
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 连接远程 HTTP 服务器
|
* 连接远程 HTTP 服务器
|
||||||
* @param addr {const char*} 服务器地址,格式:IP:PORT 或 DOMAIN:PORT
|
* @param addr {const char*} 服务器地址,格式:IP|PORT 或 DOMAIN|PORT
|
||||||
* @param conn_timeout {int} 连接超时时间(秒)
|
* @param conn_timeout {int} 连接超时时间(秒)
|
||||||
* @param rw_timeout {int} 读写超时时间(秒)
|
* @param rw_timeout {int} 读写超时时间(秒)
|
||||||
* @param unzip {bool} 当服务器返回的数据体为压缩数据时是否自动解压缩
|
* @param unzip {bool} 当服务器返回的数据体为压缩数据时是否自动解压缩
|
||||||
|
@ -41,7 +41,8 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造函数:该构造函数内部创建的 socket_stream 流会自行关闭
|
* 构造函数:该构造函数内部创建的 socket_stream 流会自行关闭
|
||||||
* @param addr {const char*} WEB 服务器地址
|
* @param addr {const char*} WEB 服务器地址,地址格式:domain|port,
|
||||||
|
* 如:www.baidu.com|80
|
||||||
* @param conn_timeout {int} 远程连接服务器超时时间(秒)
|
* @param conn_timeout {int} 远程连接服务器超时时间(秒)
|
||||||
* @param rw_timeout {int} IO 读写超时时间(秒)
|
* @param rw_timeout {int} IO 读写超时时间(秒)
|
||||||
* @param unzip {bool} 是否对服务器响应的数据自动进行解压
|
* @param unzip {bool} 是否对服务器响应的数据自动进行解压
|
||||||
|
@ -47,8 +47,8 @@ public:
|
|||||||
* 在 acl 库中规定如果地址第一个字节为 @,则认为是 Linux 抽象域套接字
|
* 在 acl 库中规定如果地址第一个字节为 @,则认为是 Linux 抽象域套接字
|
||||||
* (abstract unix domain socket)不过需注意该功能仅有 Linux 平台支持,
|
* (abstract unix domain socket)不过需注意该功能仅有 Linux 平台支持,
|
||||||
* 举例,如:@/tmp/test.sock;;
|
* 举例,如:@/tmp/test.sock;;
|
||||||
* 如果连接一个TCP服务器,则地址格式为: [${local_ip}@]${remote_addr},
|
* 如果连接一个TCP服务器,则地址格式为: remote_addr[@local_ip],
|
||||||
* 如: 60.28.250.199@www.sina.com:80,
|
* 如: www.sina.com:80@60.28.250.199,
|
||||||
* 意思是绑定本的网卡地址为: 60.28.250.199, 远程连接 www.sina.com 的 80,
|
* 意思是绑定本的网卡地址为: 60.28.250.199, 远程连接 www.sina.com 的 80,
|
||||||
* 如果由OS自动绑定本地 IP 地址,则可以写为:www.sina.com:80
|
* 如果由OS自动绑定本地 IP 地址,则可以写为:www.sina.com:80
|
||||||
* @param conn_timeout {int} 连接超时时间(秒)
|
* @param conn_timeout {int} 连接超时时间(秒)
|
||||||
|
@ -99,8 +99,7 @@ static void fiber_main(ACL_FIBER *fiber acl_unused, void *ctx)
|
|||||||
char *addr = (char *) ctx;
|
char *addr = (char *) ctx;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < __max_fibers; i++)
|
for (i = 0; i < __max_fibers; i++) {
|
||||||
{
|
|
||||||
acl_fiber_create(fiber_connect, addr, 327680);
|
acl_fiber_create(fiber_connect, addr, 327680);
|
||||||
//acl_fiber_sleep(1);
|
//acl_fiber_sleep(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user