Skip to content

Commit bdb0fdd

Browse files
committed
posix: treat as error if blocking sockets return EAGAIN
Signed-off-by: falkTX <falktx@falktx.com>
1 parent b29a869 commit bdb0fdd

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

posix/JackSocket.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ void JackClientSocket::SetWriteTimeOut(long sec)
114114
void JackClientSocket::SetNonBlocking(bool onoff)
115115
{
116116
if (onoff) {
117+
fNonBlocking = true;
117118
long flags = 0;
118119
if (fcntl(fSocket, F_SETFL, flags | O_NONBLOCK) < 0) {
119120
jack_error("SetNonBlocking fd = %ld err = %s", fSocket, strerror(errno));
@@ -197,10 +198,14 @@ int JackClientSocket::Read(void* data, int len)
197198
while (len != 0 && (res = read(fSocket, udata, len)) != len) {
198199
if (res <= 0) {
199200
if (errno == EWOULDBLOCK || errno == EAGAIN) {
200-
jack_log("JackClientSocket::Read time out on socket fd = %d", fSocket);
201-
// For a non blocking socket, a read failure is not considered as an error
202-
memset(data, 0, len);
203-
return 0;
201+
if (fNonBlocking) {
202+
jack_log("JackClientSocket::Read time out on non-blocking socket fd = %d", fSocket);
203+
// For a non blocking socket, a read failure is not considered as an error
204+
memset(data, 0, len);
205+
return 0;
206+
}
207+
jack_error("JackClientSocket::Read time out on blocking socket fd = %d", fSocket);
208+
return -1;
204209
}
205210
if (errno == 0 || errno == ENOTCONN) {
206211
// aborted reading due to shutdown
@@ -249,9 +254,13 @@ int JackClientSocket::Write(void* data, int len)
249254
while (len != 0 && (res = write(fSocket, udata, len)) != len) {
250255
if (res <= 0) {
251256
if (errno == EWOULDBLOCK || errno == EAGAIN) {
252-
jack_log("JackClientSocket::Write time out on socket fd = %d", fSocket);
253-
// For a non blocking socket, a write failure is not considered as an error
254-
return 0;
257+
if (fNonBlocking) {
258+
// For a non blocking socket, a write failure is not considered as an error
259+
jack_log("JackClientSocket::Write time out on non-blocking socket fd = %d", fSocket);
260+
return 0;
261+
}
262+
jack_error("JackClientSocket::Write time out on blocking socket fd = %d", fSocket);
263+
return -1;
255264
}
256265
if (errno == 0 || errno == ENOTCONN) {
257266
// aborted reading due to shutdown

posix/JackSocket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class JackClientSocket : public detail::JackClientRequestInterface
4545

4646
int fSocket;
4747
int fTimeOut;
48+
bool fNonBlocking;
4849
bool fPromiscuous;
4950
int fPromiscuousGid;
5051

0 commit comments

Comments
 (0)