Skip to content

Commit cdbba5c

Browse files
committed
Final solution for stopping an interruption of data reception
1 parent 51f8d20 commit cdbba5c

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/socket/AdapterTls.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ namespace Socket
7676
record_size = length - total;
7777
}
7878

79-
// const long send_size = ::gnutls_record_send(this->session, reinterpret_cast<const uint8_t *>(buf) + total, record_size);
80-
8179
long send_size = 0;
8280

8381
do {
@@ -110,17 +108,20 @@ namespace Socket
110108

111109
long AdapterTls::nonblock_recv(void *buf, const size_t length, const std::chrono::milliseconds &timeout) const noexcept
112110
{
113-
// ::gnutls_record_set_timeout(this->session, static_cast<const unsigned int>(timeout.count() ) );
114-
115111
Socket sock(this->get_handle() );
116112

117113
long result;
118114

119115
do {
120-
sock.nonblock_recv_sync(timeout);
116+
if (sock.nonblock_recv_sync(timeout) == false) {
117+
// Timeout
118+
result = -1;
119+
break;
120+
}
121+
121122
result = ::gnutls_record_recv(this->session, buf, length);
122123
}
123-
while (result == GNUTLS_E_INTERRUPTED);
124+
while (GNUTLS_E_AGAIN == result || GNUTLS_E_INTERRUPTED == result);
124125

125126
return result;
126127
}

src/socket/Socket.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ namespace Socket
289289
return recv_len;
290290
}
291291

292-
void Socket::nonblock_recv_sync(const std::chrono::milliseconds &timeout) const noexcept
292+
bool Socket::nonblock_recv_sync(const std::chrono::milliseconds &timeout) const noexcept
293293
{
294294
#ifdef WIN32
295295
WSAPOLLFD event = {
@@ -298,15 +298,15 @@ namespace Socket
298298
0
299299
};
300300

301-
::WSAPoll(&event, 1, timeout.count() );
301+
return ::WSAPoll(&event, 1, timeout.count() ) == 1;
302302
#elif POSIX
303303
struct ::pollfd event = {
304304
this->socket_handle,
305305
POLLIN,
306306
0
307307
};
308308

309-
::poll(&event, 1, timeout.count() );
309+
return ::poll(&event, 1, timeout.count() ) == 1;
310310
#else
311311
#error "Undefine platform"
312312
#endif

src/socket/Socket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace Socket
5151
long nonblock_recv(std::vector<std::string::value_type> &buf, const std::chrono::milliseconds &timeout) const noexcept;
5252
long nonblock_recv(void *buf, const size_t length, const std::chrono::milliseconds &timeout) const noexcept;
5353

54-
void nonblock_recv_sync(const std::chrono::milliseconds &timeout) const noexcept;
54+
bool nonblock_recv_sync(const std::chrono::milliseconds &timeout) const noexcept;
5555

5656
long send(const std::string &buf) const noexcept;
5757
long send(const void *buf, const size_t length) const noexcept;

0 commit comments

Comments
 (0)