acl/lib_fiber/samples/WinEchod/FiberClient.cpp
zsxxsz 400904dccf add error handling in acl_vstream.c & poll.c when operation timeout;
in fiber_win.c when calling CreateFiberEx, using size as the parameter
dwStackReserveSize;
2018-01-20 21:57:39 +08:00

67 lines
1.1 KiB
C++

#include "stdafx.h"
#include "FiberClient.h"
CFiberClient::CFiberClient(acl::socket_stream* conn)
: m_conn(conn)
{
}
CFiberClient::~CFiberClient(void)
{
}
void CFiberClient::run(void)
{
#if 0
socket_t sock = m_conn->sock_handle();
while (true)
{
char buf[1024];
int ret = acl_fiber_recv(sock, buf, sizeof(buf) - 1, 0);
if (ret <= 0)
{
int err0 = acl_fiber_last_error();
int err1 = acl::last_error();
printf("recv error: %s, %d, %d\r\n",
acl::last_serror(), err0, err1);
break;
}
buf[ret] = 0;
//printf("recv=%d, [%s]\r\n", ret, buf);
if (acl_fiber_send(sock, buf, ret, 0) == -1)
{
printf("write error %s\r\n", acl::last_serror());
break;
}
}
acl_fiber_close(sock);
m_conn->unbind();
delete m_conn;
delete this;
#else
acl::string buf;
int n = 0;
m_conn->set_rw_timeout(10);
while (true)
{
if (m_conn->read(buf, false) == false)
{
printf("read error %s, count=%d\r\n",
acl::last_serror(), n);
break;
}
//printf("read: %s\r\n", buf.c_str());
if (m_conn->write(buf) == -1)
{
printf("write error %s\r\n", acl::last_serror());
break;
}
n++;
}
delete m_conn;
delete this;
#endif
}