2014-11-19 00:25:21 +08:00
|
|
|
#include "lib_acl.h"
|
2015-04-07 23:31:31 +08:00
|
|
|
#include <list>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
static void test(const char* addr)
|
|
|
|
{
|
2015-04-07 23:31:31 +08:00
|
|
|
std::list<ACL_VSTREAM*> conns;
|
|
|
|
|
2014-11-19 00:25:21 +08:00
|
|
|
for (int i = 0; i < 10000; i++)
|
|
|
|
{
|
|
|
|
ACL_VSTREAM* client = acl_vstream_connect(addr, ACL_BLOCKING, 10, 10, 4096);
|
|
|
|
if (client == NULL)
|
|
|
|
printf("connect addr: %s error\r\n", addr);
|
|
|
|
else
|
2015-04-07 23:31:31 +08:00
|
|
|
{
|
|
|
|
printf("connect addr: %s ok, i: %d\r\n", addr, i);
|
|
|
|
conns.push_back(client);
|
|
|
|
}
|
2014-11-19 00:25:21 +08:00
|
|
|
}
|
|
|
|
|
2015-04-07 23:31:31 +08:00
|
|
|
printf("enter any key to exit\r\n");
|
2014-11-19 00:25:21 +08:00
|
|
|
getchar();
|
2015-04-07 23:31:31 +08:00
|
|
|
|
|
|
|
std::list<ACL_VSTREAM*>::iterator it = conns.begin();
|
|
|
|
for (; it != conns.end(); ++it)
|
|
|
|
acl_vstream_close(*it);
|
|
|
|
printf("Exit now ok\r\n");
|
2014-11-19 00:25:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
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);
|
|
|
|
}
|