1717#include " cuttlefish/common/libs/utils/socket2socket_proxy.h"
1818
1919#include < poll.h>
20- #include < sys/types.h>
2120#include < sys/socket.h>
21+ #include < sys/types.h>
2222
2323#include < atomic>
2424#include < cstring>
@@ -37,8 +37,7 @@ namespace {
3737
3838class ProxyPair {
3939 public:
40- ProxyPair ()
41- : stop_fd_(SharedFD::Event()) {
40+ ProxyPair () : stop_fd_(SharedFD::Event()) {
4241 if (!stop_fd_->IsOpen ()) {
4342 LOG (FATAL ) << " Failed to open eventfd: " << stop_fd_->StrError ();
4443 return ;
@@ -80,9 +79,7 @@ class ProxyPair {
8079 std::ref (t2c_running_));
8180 }
8281
83- bool Running () {
84- return c2t_running_ || t2c_running_;
85- }
82+ bool Running () { return c2t_running_ || t2c_running_; }
8683
8784 private:
8885 void Forward (const std::string& label, SharedFD from, SharedFD to,
@@ -112,22 +109,22 @@ class ProxyPair {
112109
113110} // namespace
114111
115- ProxyServer::ProxyServer (SharedFD server, std::function<SharedFD()> clients_factory)
112+ ProxyServer::ProxyServer (SharedFD server,
113+ std::function<SharedFD()> clients_factory)
116114 : stop_fd_(SharedFD::Event()) {
117115 if (!stop_fd_->IsOpen ()) {
118116 LOG (FATAL ) << " Failed to open eventfd: " << stop_fd_->StrError ();
119117 return ;
120118 }
121119 server_ = std::thread ([&, server_fd = std::move (server),
122- clients_factory = std::move (clients_factory)]() {
120+ clients_factory = std::move (clients_factory)]() {
123121 constexpr ssize_t SERVER = 0 ;
124122 constexpr ssize_t STOP = 1 ;
125123 std::list<ProxyPair> watched;
126124
127125 std::vector<PollSharedFd> server_poll = {
128- {.fd = server_fd, .events = POLLIN },
129- {.fd = stop_fd_, .events = POLLIN }
130- };
126+ {.fd = server_fd, .events = POLLIN },
127+ {.fd = stop_fd_, .events = POLLIN }};
131128
132129 while (server_fd->IsOpen ()) {
133130 server_poll[SERVER ].revents = 0 ;
@@ -151,7 +148,8 @@ ProxyServer::ProxyServer(SharedFD server, std::function<SharedFD()> clients_fact
151148 // connection without blocking on that
152149 auto client = SharedFD::Accept (*server_fd);
153150 if (!client->IsOpen ()) {
154- LOG (ERROR ) << " Failed to accept incoming connection: " << client->StrError ();
151+ LOG (ERROR ) << " Failed to accept incoming connection: "
152+ << client->StrError ();
155153 continue ;
156154 }
157155 auto target = clients_factory ();
@@ -163,13 +161,15 @@ ProxyServer::ProxyServer(SharedFD server, std::function<SharedFD()> clients_fact
163161 << " Proxy is launched. Amount of currently tracked proxy pairs: "
164162 << watched.size ();
165163 } else {
166- LOG (ERROR ) << " Cannot connect to the target to setup proxying: " << target->StrError ();
164+ LOG (ERROR ) << " Cannot connect to the target to setup proxying: "
165+ << target->StrError ();
167166 }
168167 // Unwatch completed proxy pairs
169168 watched.remove_if ([](ProxyPair& proxy) { return !proxy.Running (); });
170169 }
171170
172- // Making sure all launched proxy pairs are finished by triggering their destructor
171+ // Making sure all launched proxy pairs are finished by triggering their
172+ // destructor
173173 VLOG (0 ) << " Waiting for proxy threads to turn down" ;
174174 watched.clear ();
175175 VLOG (0 ) << " Proxy threads are successfully turned down" ;
@@ -194,8 +194,10 @@ void Proxy(SharedFD server, std::function<SharedFD()> conn_factory) {
194194 proxy.Join ();
195195}
196196
197- std::unique_ptr<ProxyServer> ProxyAsync (SharedFD server, std::function<SharedFD()> conn_factory) {
198- return std::make_unique<ProxyServer>(std::move (server), std::move (conn_factory));
197+ std::unique_ptr<ProxyServer> ProxyAsync (
198+ SharedFD server, std::function<SharedFD()> conn_factory) {
199+ return std::make_unique<ProxyServer>(std::move (server),
200+ std::move (conn_factory));
199201}
200202
201203} // namespace cuttlefish
0 commit comments