ARMmbed / sal-stack-lwip

LwIP package for mbed
Other
4 stars 14 forks source link

tcp_echo_server reports "Rx Would Block" on Non-Blocking socket after receiving packets larger than 1024 bytes #45

Open simonqhughes opened 8 years ago

simonqhughes commented 8 years ago

Hi

The tcp_echo_server test is currently coded to send/receive a max data buffer size of 1024 bytes, and so the test succeeds. However, if the data buffer size is increased to 2048 then the receive on the target server socket fails. This change can be done by modifying the following line in sal_tcpclient.py (currently at line 50):

for i in xrange(7): to become for i in xrange(8):

The failure is here in:

MBED: Rx Would Block

Sockets should normally be blocking by default so my expectation is that that the target socket is blocking. This report doesn't occur for sends <= 1024 bytes

$ mbedhtrun -v -d E: -f ".\build\frdm-k64f-gcc\test\sal-stack-lwip-test-tcp_echo_server.bin" -p COM40:9600 -C 4 -c default -m K64F -e test/host_tests
HOST: Inspecting 'd:\datastore\public\jobs\yr2016\2245\sdh_dev_3\sal-stack-lwip\test\host_tests' for local host tests...
HOST: Loading module 'sal_tcpclient.py':  <module 'sal_tcpclient' from 'd:\datastore\public\jobs\yr2016\2245\sdh_dev_3\sal-stack-lwip\test\host_tests\sal_tcpclient.py'>
HOST: Found host test implementation: sal_tcpclient.SalTcpClientTest -|> mbed_host_tests.host_tests.base_host_test.BaseHostTest
HOST: Registering 'sal_tcpclient.SalTcpClientTest' as 'sal_tcpclient'
HOST: Loading module 'sal_tcpserver.py':  <module 'sal_tcpserver' from 'd:\datastore\public\jobs\yr2016\2245\sdh_dev_3\sal-stack-lwip\test\host_tests\sal_tcpserver.pyc'>
HOST: Found host test implementation: sal_tcpserver.SalTcpServerTest -|> mbed_host_tests.host_tests.base_host_test.BaseHostTest
HOST: Registering 'sal_tcpserver.SalTcpServerTest' as 'sal_tcpserver'
HOST: Loading module 'sal_udpserver.py':  <module 'sal_udpserver' from 'd:\datastore\public\jobs\yr2016\2245\sdh_dev_3\sal-stack-lwip\test\host_tests\sal_udpserver.pyc'>
HOST: Found host test implementation: sal_udpserver.SalUdpServerTest -|> mbed_host_tests.host_tests.base_host_test.BaseHostTest
HOST: Registering 'sal_udpserver.SalUdpServerTest' as 'sal_udpserver'
MBED: Instrumentation: "COM40" and disk: "E:"
HOST: Copy image onto target...
        1 file(s) copied.
HOST: Initialize serial port...
...port ready!
HOST: Reset target...
HOST: Detecting test case properties...
HOST: Property 'timeout' = '20'
HOST: Property 'host_test_name' = 'sal_tcpclient'
HOST: Property 'description' = 'SalTcpClientTest'
HOST: Property 'test_id' = 'Socket Abstract Layer TCP Server Connection/Tx/Rx Socket Stream Test'
HOST: Start test...
MBED: {{start}}
MBED: {{summary socket_api_test_create_destroy [PASS] (0/30 FAILED)}}
MBED: {{summary socket_api_test_socket_str2addr [PASS] (0/46 FAILED)}}
MBED: >>> EC,10.2.203.161,32765
10.2.203.161
32765
HOST: target reported tcp server: 10.2.203.161:32765
Host: sent 16 bytes of data
MBED: received 16 bytes of data
MBED: sent 16 bytes of data
Host: recevied 16 bytes of data
Host: sent 32 bytes of data
MBED: received 32 bytes of data
MBED: sent 32 bytes of data
Host: recevied 32 bytes of data
Host: sent 64 bytes of data
MBED: received 64 bytes of data
MBED: sent 64 bytes of data
Host: recevied 64 bytes of data
Host: sent 128 bytes of data
MBED: received 128 bytes of data
MBED: sent 128 bytes of data
Host: recevied 128 bytes of data
Host: sent 256 bytes of data
MBED: received 256 bytes of data
MBED: sent 256 bytes of data
Host: recevied 256 bytes of data
Host: sent 512 bytes of data
MBED: received 512 bytes of data
MBED: sent 512 bytes of data
Host: recevied 512 bytes of data
Host: sent 1024 bytes of data
MBED: received 1024 bytes of data
MBED: sent 1024 bytes of data
Host: recevied 1024 bytes of data
Host: sent 2048 bytes of data
MBED: received 2048 bytes of data
MBED: sent 2048 bytes of data
Host: recevied 2048 bytes of data
MBED: socket_api_test_echo_server_stream:726 err==SOCKET_ERROR_WOULD_BLOCK [FAIL]
MBED: Rx Would Block
MBED: received 4 bytes of data
MBED: >>> KILL,EC
MBED: {{summary socket_api_test_echo_server_stream [FAIL] (1/42 FAILED)}}
MBED: {{failure}}
MBED: {{end}}
HOST: Terminating Test
HOST: Passive mode...```
ciarmcom commented 8 years ago

ARM Internal Ref: IOTSFW-1825

bremoran commented 8 years ago

SOCKET_ERROR_WOULD_BLOCK occurs when a read is greater than the queued data. Since TCP stream data is not a guaranteed to arrive all at once, it is legitimate for the TCP socket to generate multiple callbacks for a single logical "block".

Would it be reasonable to modify the behaviour of this test so that SOCKET_ERROR_WOULD_BLOCK is not an error, but is actually a continuation flag?

adbridge commented 8 years ago

If it's a stream then isn't the read size irrelevant? It's just the maximum size that you're able to accept at that time? Therefore less than that shouldn't be an error? Maybe a return code something like 'SOCKET_STREAM_MORE_DATA_AVAILABLE' ?