Skip to content

Commit

Permalink
modify client close interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
wlgq2 committed May 6, 2020
1 parent 0742f8b commit f2da6b1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/echo_client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void startClients(uv::EventLoop* loop,uv::SocketAddr& addr,std::vector<uv::TcpCl
});
client->setMessageCallback([client](const char* data,ssize_t size)
{
client->write(data,size,nullptr);
client->write(data,(unsigned)size,nullptr);
});

client->connect(addr);
Expand Down
9 changes: 4 additions & 5 deletions uv/TcpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,21 @@ void TcpClient::onMessage(shared_ptr<TcpConnection> connection,const char* buf,s
onMessageCallback_(buf,size);
}

void uv::TcpClient::close(std::function<void(std::string&)> callback)
void uv::TcpClient::close(std::function<void(uv::TcpClient*)> callback)
{
if (connection_)
{
connection_->close([this, callback](std::string& name)
connection_->close([this, callback](std::string&)
{
//onClose(name);
if (callback)
callback(name);
callback(this);
});

}
else if(callback)
{
std::string str("");
callback(str);
callback(this);
}
}

Expand Down
3 changes: 1 addition & 2 deletions uv/http/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ HttpClient::~HttpClient()
{
if (isConnected)
{
auto client = client_;
client->close([client](std::string& name)
client_->close([](uv::TcpClient* client)
{
delete client;
});
Expand Down
2 changes: 1 addition & 1 deletion uv/include/TcpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TcpClient
void onConnect(bool successed);
void onConnectClose(std::string& name);
void onMessage(TcpConnectionPtr connection,const char* buf,ssize_t size);
void close(std::function<void(std::string&)> callback);
void close(std::function<void(uv::TcpClient*)> callback);
void afterConnectFail();

void write(const char* buf, unsigned int size, AfterWriteCallback callback = nullptr);
Expand Down

0 comments on commit f2da6b1

Please sign in to comment.