mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Merge pull request #9429 from SeppoTakalo/TCPSOCKET_endpoint_close
Fix TCPSOCKET_ENDPOINT_CLOSE: Cannot accept WOULD_BLOCKpull/9021/head
						commit
						2c5d246249
					
				| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue