2019-07-28 10:31:56 +08:00
|
|
|
#include "stdafx.h"
|
2022-01-18 23:58:40 +08:00
|
|
|
#include "tcp_transfer.h"
|
2019-03-14 15:24:11 +08:00
|
|
|
|
2022-02-15 22:34:10 +08:00
|
|
|
tcp_transfer::tcp_transfer(acl::socket_stream& in,
|
|
|
|
acl::socket_stream& out, bool running)
|
|
|
|
: acl::fiber(running)
|
|
|
|
, in_(in), out_(out), peer_(NULL)
|
2019-03-14 15:24:11 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-19 23:47:53 +08:00
|
|
|
tcp_transfer::~tcp_transfer(void)
|
2019-03-14 15:24:11 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-19 23:47:53 +08:00
|
|
|
void tcp_transfer::set_peer(tcp_transfer& peer)
|
2019-03-14 15:24:11 +08:00
|
|
|
{
|
2022-01-19 23:47:53 +08:00
|
|
|
peer_ = &peer;
|
2019-03-14 15:24:11 +08:00
|
|
|
}
|
|
|
|
|
2022-01-18 23:58:40 +08:00
|
|
|
void tcp_transfer::wait(void)
|
2019-03-14 15:24:11 +08:00
|
|
|
{
|
|
|
|
(void) box_.pop();
|
|
|
|
}
|
|
|
|
|
2022-01-18 23:58:40 +08:00
|
|
|
void tcp_transfer::run(void)
|
2019-03-14 15:24:11 +08:00
|
|
|
{
|
|
|
|
char buf[8192];
|
|
|
|
while (true) {
|
|
|
|
int ret = in_.read(buf, sizeof(buf) - 1, false);
|
|
|
|
if (ret == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out_.write(buf, ret) == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (peer_) {
|
|
|
|
peer_->kill();
|
|
|
|
}
|
|
|
|
|
|
|
|
box_.push(NULL);
|
|
|
|
}
|