Rev 1597 | Rev 1608 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1597 | Rev 1599 | ||
|---|---|---|---|
| Line 29... | Line 29... | ||
| 29 | { |
29 | { |
| 30 | } |
30 | } |
| 31 | 31 | ||
| 32 | TcpClient::~TcpClient() |
32 | TcpClient::~TcpClient() |
| 33 | { |
33 | { |
| 34 | if (this->socket_.is_open()) |
- | |
| 35 | { |
- | |
| 36 | this->socket_.cancel(); |
- | |
| 37 | this->socket_.close(); |
- | |
| 38 | } |
- | |
| 39 | - | ||
| 40 | if (this->acceptor_.use_count() != 0) |
- | |
| 41 | { |
- | |
| 42 | this->acceptor_->cancel(); |
- | |
| 43 | this->acceptor_->close(); |
- | |
| 44 | } |
- | |
| 45 | } |
34 | } |
| 46 | 35 | ||
| 47 | void TcpClient::Accept(AcceptorPointer acceptor) |
36 | void TcpClient::Accept(AcceptorPointer acceptor) |
| 48 | { |
37 | { |
| 49 | try |
38 | try |
| 50 | { |
39 | { |
| 51 | this->acceptor_ = acceptor; |
40 | this->acceptor_ = acceptor; |
| 52 | 41 | ||
| 53 | this->acceptor_->async_accept(this->socket_, |
42 | this->acceptor_->async_accept(this->socket_, |
| 54 | boost::bind(&TcpClient::AcceptHandler, |
43 | boost::bind(&TcpClient::AcceptHandler, |
| 55 | this, |
44 | this, |
| 56 | boost::asio::placeholders::error)); |
45 | boost::asio::placeholders::error)); |
| 57 | } |
46 | } |
| Line 71... | Line 60... | ||
| 71 | TcpClient::AcceptorPointer TcpClient::ReleaseAcceptor() |
60 | TcpClient::AcceptorPointer TcpClient::ReleaseAcceptor() |
| 72 | { |
61 | { |
| 73 | AcceptorPointer acceptor = this->acceptor_; |
62 | AcceptorPointer acceptor = this->acceptor_; |
| 74 | this->acceptor_.reset(); |
63 | this->acceptor_.reset(); |
| 75 | return acceptor; |
64 | return acceptor; |
| 76 | } |
65 | } |
| 77 | 66 | ||
| 78 | void TcpClient::Connect(std::string address, unsigned int port) |
67 | void TcpClient::Connect(std::string address, unsigned int port) |
| 79 | { |
68 | { |
| 80 | try |
69 | try |
| 81 | { |
70 | { |
| Line 86... | Line 75... | ||
| 86 | this->socket_.connect(*it); |
75 | this->socket_.connect(*it); |
| 87 | } |
76 | } |
| 88 | catch (std::exception e) |
77 | catch (std::exception e) |
| 89 | { |
78 | { |
| 90 | throw std::runtime_error("Error while connecting to " + address + ":" + boost::lexical_cast<std::string>(port) + ", " + std::string(e.what())); |
79 | throw std::runtime_error("Error while connecting to " + address + ":" + boost::lexical_cast<std::string>(port) + ", " + std::string(e.what())); |
| 91 | } |
80 | } |
| 92 | 81 | ||
| 93 | this->Read(); |
82 | this->Read(); |
| 94 | } |
83 | } |
| 95 | 84 | ||
| 96 | void TcpClient:: |
85 | void TcpClient::Stop() |
| 97 | { |
86 | { |
| 98 | if (this->socket_.is_open()) |
87 | if (this->socket_.is_open()) |
| 99 | { |
88 | { |
| 100 | this->socket_.cancel(); |
89 | this->socket_.cancel(); |
| 101 | this->socket_.close(); |
90 | this->socket_.close(); |
| Line 104... | Line 93... | ||
| 104 | if (this->acceptor_.use_count() != 0) |
93 | if (this->acceptor_.use_count() != 0) |
| 105 | { |
94 | { |
| 106 | this->acceptor_->cancel(); |
95 | this->acceptor_->cancel(); |
| 107 | this->acceptor_->close(); |
96 | this->acceptor_->close(); |
| 108 | } |
97 | } |
| 109 | - | ||
| 110 | Client::Disconnect(); |
- | |
| 111 | } |
98 | } |
| 112 | 99 | ||
| 113 | void TcpClient::Send(type::Byteset data) |
100 | void TcpClient::Send(type::Byteset data) |
| 114 | { |
101 | { |
| 115 | if (this->acceptor_.use_count() != 0) |
102 | if (this->acceptor_.use_count() != 0) |