@@ -18,44 +18,44 @@ namespace love
1818 {
1919 this ->restore ();
2020
21- this -> lsockfd . reset (socket (AF_INET , SOCK_STREAM , 0 ));
21+ detail::UniqueFD listenfd (socket (AF_INET , SOCK_STREAM , 0 ));
2222
23- if (!this -> lsockfd )
23+ if (!listenfd )
2424 return false ;
2525
26- fcntl (this -> lsockfd .get (), F_SETFD , FD_CLOEXEC );
26+ fcntl (listenfd .get (), F_SETFD , FD_CLOEXEC );
2727
2828 int yes = 1 ;
29- setsockopt (this -> lsockfd .get (), SOL_SOCKET , SO_REUSEADDR , &yes, sizeof (yes));
29+ setsockopt (listenfd .get (), SOL_SOCKET , SO_REUSEADDR , &yes, sizeof (yes));
3030
3131 sockaddr_in server {};
3232 server.sin_family = AF_INET ;
3333 server.sin_port = htons (connection.port );
3434 server.sin_addr .s_addr = INADDR_ANY ;
3535
36- if (bind (this -> lsockfd .get (), (sockaddr*)&server, sizeof (server)) < 0 )
36+ if (bind (listenfd .get (), (sockaddr*)&server, sizeof (server)) < 0 )
3737 return false ;
3838
39- if (listen (this -> lsockfd .get (), MAX_PENDING_CONNECTIONS ) < 0 )
39+ if (listen (listenfd .get (), MAX_PENDING_CONNECTIONS ) < 0 )
4040 return false ;
4141
4242 fd_set set;
4343 FD_ZERO (&set);
44- FD_SET (this -> lsockfd .get (), &set);
44+ FD_SET (listenfd .get (), &set);
4545
4646 timeval timeout {
4747 .tv_sec = connection.timeout ,
4848 .tv_usec = 0 ,
4949 };
5050
51- int ready = select (this -> lsockfd .get () + 1 , &set, nullptr , nullptr , &timeout);
51+ int ready = select (listenfd .get () + 1 , &set, nullptr , nullptr , &timeout);
5252
5353 // ready == 0: timeout, ready < 0: select() failed
5454 if (ready <= 0 )
5555 return false ;
5656
57- detail::UniqueFD client (accept (this -> lsockfd .get (), nullptr , nullptr ));
58- this -> lsockfd .reset ();
57+ detail::UniqueFD client (accept (listenfd .get (), nullptr , nullptr ));
58+ listenfd .reset ();
5959
6060 if (!client)
6161 return false ;
@@ -73,21 +73,17 @@ namespace love
7373 }
7474
7575 std::signal (SIGPIPE , SIG_IGN );
76- this ->redirected = true ;
7776 return true ;
7877 }
7978
8079 void Socket::restore ()
8180 {
82- if (this ->savedfd )
83- {
84- std::fflush (stdout);
85- dup2 (this ->savedfd .get (), STDOUT_FILENO );
86- this ->savedfd .reset ();
87- }
81+ if (!this ->savedfd )
82+ return ;
8883
89- this ->lsockfd .reset ();
90- this ->redirected = false ;
84+ std::fflush (stdout);
85+ dup2 (this ->savedfd .get (), STDOUT_FILENO );
86+ this ->savedfd .reset ();
9187 }
9288
9389 Socket g_debugSocket;
0 commit comments