Skip to content

Commit 4fa9f67

Browse files
committed
clean up debug
1 parent 6dde22f commit 4fa9f67

2 files changed

Lines changed: 17 additions & 24 deletions

File tree

include/common/debug.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,16 @@ namespace love
9090
Socket(const Socket&) = delete;
9191
Socket& operator=(const Socket&) = delete;
9292

93-
Socket(Socket&&) noexcept = default;
94-
Socket& operator=(Socket&&) noexcept = default;
93+
Socket(Socket&&) noexcept = delete;
94+
Socket& operator=(Socket&&) noexcept = delete;
9595

9696
bool open(const detail::Connection& connection);
9797

9898
void restore();
9999

100100
private:
101101
static constexpr uint8_t MAX_PENDING_CONNECTIONS = 5;
102-
103-
detail::UniqueFD lsockfd;
104102
detail::UniqueFD savedfd;
105-
bool redirected = false;
106103
};
107104

108105
extern Socket g_debugSocket;

source/common/debug.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)