99#include < brynet/net/http/HttpFormat.h>
1010#include < brynet/net/http/WebSocketFormat.h>
1111#include < brynet/net/Connector.h>
12+ #include < brynet/net/Wrapper.h>
1213
1314using namespace brynet ;
1415using namespace brynet ::net;
@@ -49,7 +50,6 @@ int main(int argc, char **argv)
4950 auto connector = brynet::net::AsyncConnector::Create ();
5051 connector->startWorkerThread ();
5152
52-
5353 auto listenThread = ListenThread::Create (false , " 0.0.0.0" , 8080 , [service](TcpSocket::Ptr socket) {
5454 std::string body = " <html>hello world </html>" ;
5555 auto enterCallback = [body](const TcpConnection::Ptr& session) {
@@ -85,6 +85,19 @@ int main(int argc, char **argv)
8585 });
8686 listenThread->startListen ();
8787
88+ wrapper::SocketConnectBuilder sb;
89+ auto s = sb.configureConnector (connector)
90+ .configureConnectOptions ({
91+ AsyncConnector::ConnectOptions::WithTimeout (std::chrono::seconds (2 )),
92+ AsyncConnector::ConnectOptions::WithAddr (" 127.0.0.1" , 8010 )
93+ })
94+ .syncConnect ();
95+ s = sb.configureConnector (connector)
96+ .configureConnectOptions ({
97+ AsyncConnector::ConnectOptions::WithAddr (" 127.0.0.1" , 8080 )
98+ })
99+ .syncConnect ();
100+
88101 HttpRequest request;
89102 request.setMethod (HttpRequest::HTTP_METHOD ::HTTP_METHOD_GET );
90103 request.setUrl (" /ISteamUserAuth/AuthenticateUserTicket/v1/" );
@@ -98,12 +111,12 @@ int main(int argc, char **argv)
98111
99112 std::string requestStr = request.getResult ();
100113
101- std::atomic<int > couner{0 };
114+ std::atomic<int > couner{ 0 };
102115
103116 for (size_t i = 0 ; i < 10 ; i++)
104117 {
105- reqHttp (service,
106- connector,
118+ reqHttp (service,
119+ connector,
107120 requestStr,
108121 {
109122 AsyncConnector::ConnectOptions::WithAddr (" 23.73.140.64" , 80 ),
@@ -115,6 +128,44 @@ int main(int argc, char **argv)
115128 std::cout << ++couner << std::endl;
116129 });
117130 }
131+
132+ wrapper::HttpConnectionBuilder ()
133+ .configureConnector (connector)
134+ .configureService (service)
135+ .configureConnectOptions ({
136+ AsyncConnector::ConnectOptions::WithAddr (" 180.97.33.108" , 80 ),
137+ AsyncConnector::ConnectOptions::WithTimeout (std::chrono::seconds (10 )),
138+ AsyncConnector::ConnectOptions::WithFailedCallback ([]() {
139+ std::cout << " failed" << std::endl;
140+ }),
141+ })
142+ .configureConnectionOptions ({
143+ TcpService::AddSocketOption::WithMaxRecvBufferSize (1024 ),
144+ TcpService::AddSocketOption::AddEnterCallback ([](const TcpConnection::Ptr& session) {
145+ // do something for session
146+ std::cout << " success" << std::endl;
147+ })
148+ })
149+ .configureEnterCallback ([](HttpSession::Ptr session) {
150+ std::cout << " success" << std::endl;
151+ })
152+ .asyncConnect ();
153+
154+ wrapper::ListenerBuilder listenBuilder;
155+ listenBuilder.configureService (service)
156+ .configureSocketOptions ({
157+ [](TcpSocket& socket) {
158+ socket.setNodelay ();
159+ },
160+ })
161+ .configureConnectionOptions ({
162+ TcpService::AddSocketOption::WithMaxRecvBufferSize (1024 ),
163+ })
164+ .configureListen ([](wrapper::BuildListenConfig builder) {
165+ builder.setAddr (false , " 0.0.0.0" , 80 );
166+ })
167+ .asyncRun ();
168+
118169 std::cin.get ();
119170 return 0 ;
120171}
0 commit comments