mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-01 11:27:40 +08:00
e55a183e1e
win32 message is OK;
54 lines
823 B
C++
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;
|
|
} |