acl/lib_fiber/samples/WinEchod/FiberClient.cpp
郑树新 e55a183e1e WinEchod: rename class files' name;
win32 message is OK;
2018-01-11 14:19:09 +08:00

54 lines
823 B
C++

#include "stdafx.h"
#include "ClientEcho.h"
CClientEcho::CClientEcho(acl::socket_stream* conn)
: m_conn(conn)
{
}
CClientEcho::~CClientEcho(void)
{
}
void CClientEcho::run(void)
{
socket_t sock = m_conn->sock_handle();
while (true)
{
char buf[1024];
int ret = fiber_recv(sock, buf, sizeof(buf) - 1, 0);
if (ret == -1)
{
printf("recv error\r\n");
break;
}
buf[ret] = 0;
printf("recv=%d, [%s]\r\n", ret, buf);
if (fiber_send(sock, buf, ret, 0) == -1)
{
printf("write error %s\r\n", acl::last_serror());
break;
}
}
delete m_conn;
delete this;
return;
acl::string buf;
while (true)
{
if (m_conn->gets(buf) == false)
{
printf("gets error\r\n");
break;
}
if (m_conn->write(buf) == -1)
{
printf("write error\r\n");
break;
}
}
delete m_conn;
delete this;
}