SpiecsEngine
 
Loading...
Searching...
No Matches

◆ TEST() [51/59]

SpicesTest::TEST ( TcpServer_test ,
TcpServer  )

Testing Spices::Net::TcpServer.

Definition at line 65 of file TcpServer_test.h.

65 {
66
68
69 using namespace Spices::Net;
70
71 InetAddress address(8000, "127.0.0.1");
72 EventLoop* loop = nullptr;
73 std::thread t([&]() {
74
75 TcpServerTest server(address);
76 server.start();
77
78 loop = EventLoopThreadWrapper::GetInst();
79 loop->Loop();
80 });
81
82 while (!loop) {}
83
84 Socket client;
85 client.Create();
86 Channel channel(client.Fd(), loop);
87 channel.EnableWriting();
88 client.Connect(&address);
89 client.Send("Hello client!");
90
91 t.detach();
92 }
#define SPICESTEST_PROFILE_FUNCTION()
Wrapper of SOCKET'S Event.
Definition Channel.h:27
void Loop()
Start Event Loop.
Definition EventLoop.cpp:48
Wrapper of Poller and wakeup socket to acceptor(SubLoop).
Definition EventLoop.h:28
This class is Wrapper of current socket address.
Definition InetAddress.h:22
void Connect(InetAddress *connectAddress) const
Connect to socket.
Definition Socket.cpp:62
void Send(const std::string &data) const
Send data to server.
Definition Socket.cpp:106
void Create()
Create Non Blocking Socket.
Definition Socket.cpp:27
const SOCKET Fd() const
Get this socket fd.
Definition Socket.h:60
This class is Wrapper of socket.
Definition Socket.h:18

References Spices::Net::Socket::Connect(), Spices::Net::Socket::Create(), Spices::Net::Channel::EnableWriting(), Spices::Net::EventLoopThreadWrapper::GetInst(), Spices::Net::EventLoop::Loop(), SpicesTest::TcpServerTest::start(), and SpicesTest::TcpServerTest::TcpServerTest().