Skip to content

Commit d4b974f

Browse files
committed
translation/server/Connection: use the SocketError library instead of errno
1 parent 5206279 commit d4b974f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/translation/server/Connection.cxx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include "Handler.hxx"
77
#include "Response.hxx"
88
#include "translation/Protocol.hxx"
9+
#include "net/SocketError.hxx"
910
#include "io/Logger.hxx"
1011

1112
#include <sys/socket.h>
1213
#include <unistd.h>
13-
#include <errno.h>
1414
#include <string.h>
1515

1616
namespace Translation::Server {
@@ -52,10 +52,12 @@ Connection::TryRead() noexcept
5252
}
5353

5454
if (nbytes < 0) {
55-
if (errno == EAGAIN)
55+
const auto e = GetSocketError();
56+
if (IsSocketErrorReceiveWouldBlock(e))
5657
return true;
5758

58-
LogConcat(2, "ts", "Failed to read from client: ", strerror(errno));
59+
LogConcat(2, "ts", "Failed to read from client: ",
60+
(const char *)SocketErrorMessage{e});
5961
}
6062

6163
Destroy();
@@ -142,12 +144,14 @@ Connection::TryWrite() noexcept
142144

143145
ssize_t nbytes = event.GetSocket().WriteNoWait(output);
144146
if (nbytes < 0) {
145-
if (errno == EAGAIN) [[likely]] {
147+
const auto e = GetSocketError();
148+
if (IsSocketErrorSendWouldBlock(e)) [[likely]] {
146149
event.ScheduleWrite();
147150
return true;
148151
}
149152

150-
LogConcat(2, "ts", "Failed to write to client: ", strerror(errno));
153+
LogConcat(2, "ts", "Failed to write to client: ",
154+
(const char *)SocketErrorMessage{e});
151155
Destroy();
152156
return false;
153157
}

0 commit comments

Comments
 (0)