Skip to content

Commit

Permalink
use Watcher::start return value
Browse files Browse the repository at this point in the history
  • Loading branch information
xuyouqiao2005 committed Jun 25, 2024
1 parent 3d8f1bc commit 5946ee7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/io_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ qint32 RawFile::read(char *data, qint32 size)
} else {
return r;
}
watcher.start();
if (!watcher.start()) {
return -1;
}
}
#else
qint64 len = f->read(data, size);
Expand Down Expand Up @@ -131,7 +133,9 @@ qint32 RawFile::write(const char *data, qint32 size)
} else {
return r;
}
watcher.start();
if (!watcher.start()) {
return -1;
}
}
#else
qint64 len = f->write(data, size);
Expand Down
34 changes: 28 additions & 6 deletions src/socket_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ bool SocketPrivate::connect(const HostAddress &address, quint16 port)
state = Socket::UnconnectedState;
return false;
}
watcher.start();
if (!watcher.start()) {
setError(Socket::UnknownSocketError, UnknownSocketErrorString);
state = Socket::UnconnectedState;
return false;
}
}
}

Expand Down Expand Up @@ -600,7 +604,11 @@ qint32 SocketPrivate::recv(char *data, qint32 size, bool all)
return total;
}
}
watcher.start();
if (!watcher.start()) {
setError(Socket::NetworkError, InvalidSocketErrorString);
abort();
return total == 0 ? -1 : total;
}
}
return total;
}
Expand Down Expand Up @@ -683,7 +691,11 @@ qint32 SocketPrivate::send(const char *data, qint32 size, bool all)
return -1;
}
}
watcher.start();
if (!watcher.start()) {
setError(Socket::UnknownSocketError, UnknownSocketErrorString);
abort();
return -1;
}
}
return sent;
}
Expand Down Expand Up @@ -764,7 +776,11 @@ qint32 SocketPrivate::recvfrom(char *data, qint32 maxSize, HostAddress *addr, qu
// return qint64(maxSize ? recvResult : recvResult == -1 ? -1 : 0);
return static_cast<qint32>(recvResult);
}
watcher.start();
if (!watcher.start()) {
setError(Socket::NetworkError, InvalidSocketErrorString);
abort();
return -1;
}
}
}

Expand Down Expand Up @@ -847,7 +863,10 @@ qint32 SocketPrivate::sendto(const char *data, qint32 size, const HostAddress &a
}
return static_cast<qint32>(sentBytes);
}
watcher.start();
if (!watcher.start()) {
setError(Socket::NetworkError, InvalidSocketErrorString);
return -1;
}
}
}

Expand Down Expand Up @@ -1333,7 +1352,10 @@ Socket *SocketPrivate::accept()
Socket *conn = new Socket(acceptedDescriptor);
return conn;
}
watcher.start();
if (!watcher.start()) {
setError(Socket::UnknownSocketError, UnknownSocketErrorString);
return nullptr;
}
}
}

Expand Down
32 changes: 26 additions & 6 deletions src/socket_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,10 @@ bool SocketPrivate::connect(const HostAddress &address, quint16 port)
default:
return setErrorFromWASError(this, err);
}
watcher.start();
if (!watcher.start()) {
setError(Socket::UnknownSocketError, UnknownSocketErrorString);
return false;
}
} else {
state = Socket::ConnectedState;
fetchConnectionParameters();
Expand Down Expand Up @@ -894,7 +897,11 @@ qint32 SocketPrivate::recv(char *data, qint32 size, bool all)
return total;
}
}
watcher.start();
if (!watcher.start()) {
setError(Socket::UnknownSocketError, UnknownSocketErrorString);
close();
return total == 0 ? -1 : total;
}
}
return total;
}
Expand Down Expand Up @@ -994,7 +1001,11 @@ qint32 SocketPrivate::send(const char *data, qint32 size, bool all)
return -1;
}
}
watcher.start();
if (!watcher.start()) {
setError(Socket::UnknownSocketError, UnknownSocketErrorString);
close();
return -1;
}
}
return ret;
}
Expand Down Expand Up @@ -1098,7 +1109,10 @@ qint32 SocketPrivate::recvfrom(char *data, qint32 size, HostAddress *addr, quint
#endif
return ret;
} else {
watcher.start();
if (!watcher.start()) {
setError(Socket::UnknownSocketError, UnknownSocketErrorString);
return -1;
}
}
}
}
Expand Down Expand Up @@ -1183,7 +1197,10 @@ qint32 SocketPrivate::sendto(const char *data, qint32 size, const HostAddress &a
return ret;
}
}
watcher.start();
if (!watcher.start()) {
setError(Socket::UnknownSocketError, UnknownSocketErrorString);
return -1;
}
}
}

Expand Down Expand Up @@ -1520,7 +1537,10 @@ Socket *SocketPrivate::accept()
Socket *conn = new Socket(static_cast<qintptr>(acceptedDescriptor));
return conn;
}
watcher.start();
if (!watcher.start()) {
setError(Socket::UnknownSocketError, UnknownSocketErrorString);
return nullptr;
}
}
}

Expand Down

0 comments on commit 5946ee7

Please sign in to comment.