diff --git a/.gitignore b/.gitignore index d1a5751..30653a7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ build/ libd/ general/third/ general/CMakeFiles/ +test/src/tcptest/third/ +test/src/cpp11/third/ diff --git a/general/src/net/TcpClient.cpp b/general/src/net/TcpClient.cpp index 073a7ff..8b8eb72 100644 --- a/general/src/net/TcpClient.cpp +++ b/general/src/net/TcpClient.cpp @@ -164,6 +164,7 @@ int TcpClientLibevent::ConnectServer() { bufferevent_free(bev); bev = nullptr; printf("Connect failed\n"); + return -1; } this->mStatus = TcpClientLibevent::CONNECTED; return 0; diff --git a/test/src/tcptest/tcpclient_test.cpp b/test/src/tcptest/tcpclient_test.cpp index cc29f22..c12e471 100644 --- a/test/src/tcptest/tcpclient_test.cpp +++ b/test/src/tcptest/tcpclient_test.cpp @@ -1,9 +1,34 @@ #include "TcpClient.h" #include #include +#include +#include + +extern "C"{ + #include +} using namespace std; + +class Observer: public TcpClientLibevent::TcpClientObserver { + void OnConnected() { + std::cout<<"connected"; + } + virtual void OnDisConnected() { + + } + virtual void OnData(uint8_t *dat,uint64_t len){ + + } + virtual void OnClose(){ + + } +}; + int main(){ - TcpClientLibevent mTcp("127.0.0.1",8443, nullptr); - + Observer p ; + TcpClientLibevent mTcp("127.0.0.1",8443, &p); + while(true){ + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } } \ No newline at end of file