Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TCPSOCKET_ENDPOINT_CLOSE: Cannot accept WOULD_BLOCK #9429

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions TESTS/netsocket/tcp/tcpsocket_endpoint_close.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@

using namespace utest::v1;

namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]
}

static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}

static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket &sock)
{
SocketAddress tcp_addr;
Expand All @@ -49,7 +39,6 @@ static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket &sock)
return sock.connect(tcp_addr);
}


void TCPSOCKET_ENDPOINT_CLOSE()
{
static const int MORE_THAN_AVAILABLE = 30;
Expand All @@ -63,24 +52,16 @@ void TCPSOCKET_ENDPOINT_CLOSE()
TEST_FAIL();
return;
}
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));

int recvd = 0;
int recvd_total = 0;
while (true) {
recvd = sock.recv(&(buff[recvd_total]), MORE_THAN_AVAILABLE);
recvd = sock.recv(buff, MORE_THAN_AVAILABLE);
if (recvd_total > 0 && recvd == 0) {
break; // Endpoint closed socket, success
} else if (recvd <= 0) {
TEST_FAIL();
TEST_ASSERT_EQUAL(0, recvd);
break;
} else if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL();
break;
}
continue;
}
recvd_total += recvd;
TEST_ASSERT(recvd_total < MORE_THAN_AVAILABLE);
Expand Down