| 50 | } |
| 51 | |
| 52 | int main() { |
| 53 | |
| 54 | cppnet::CCppNet net; |
| 55 | net.Init(1); |
| 56 | |
| 57 | net.SetConnectionCallback(ConnectFunc); |
| 58 | net.SetWriteCallback(WriteFunc); |
| 59 | net.SetReadCallback(ReadFunc); |
| 60 | net.SetDisconnectionCallback(DisConnectionFunc); |
| 61 | for (size_t i = 0; i < 10000; i++) { |
| 62 | #ifndef __linux__ |
| 63 | std::string msg = GetMsg(); |
| 64 | net.Connection("127.0.0.1", 8921, msg.c_str(), msg.length()); |
| 65 | #else |
| 66 | net.Connection("127.0.0.1", 8921); |
| 67 | #endif // !__linux__ |
| 68 | } |
| 69 | |
| 70 | // wait all connect success. |
| 71 | base::CRunnable::Sleep(5000); |
| 72 | |
| 73 | while (1) { |
| 74 | // sleep 1s; |
| 75 | for (auto iter = handle_vec.begin(); iter != handle_vec.end(); ++iter) { |
| 76 | base::CRunnable::Sleep(1); |
| 77 | std::string msg = GetMsg(); |
| 78 | (*iter)->Write(msg.c_str(), msg.length()); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | net.Join(); |
| 83 | } |
nothing calls this directly
no test coverage detected