Robustness test: socket that exchanges data forever between mbed and the host.
Dependencies: PicoTCP lpc1768-picotcp-eth mbed-rtos mbed
Revision 0:b88f77e8d572, committed 2013-07-24
- Comitter:
- tass
- Date:
- Wed Jul 24 13:53:23 2013 +0000
- Commit message:
- Changed the memory test so it would exchange data forever,; if no failure appears.
Changed in this revision
diff -r 000000000000 -r b88f77e8d572 PicoTCP.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PicoTCP.lib Wed Jul 24 13:53:23 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/daniele/code/PicoTCP/#ca30069e49bb
diff -r 000000000000 -r b88f77e8d572 lpc1768-picotcp-eth.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lpc1768-picotcp-eth.lib Wed Jul 24 13:53:23 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/tass/code/lpc1768-picotcp-eth/#0b675bdd074f
diff -r 000000000000 -r b88f77e8d572 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jul 24 13:53:23 2013 +0000 @@ -0,0 +1,120 @@ +#include <mbed.h> +#include <stdarg.h> +#include "EthernetInterface.h" + +#define ECHO_SERVER_PORT 7 +#define BUFFER_QUANTITY (1024*1024) +#define MAX_NUMBER_OF_RETRIES (10u) + + +int main() { + + printf("Socket exchange data forever...\n"); + + EthernetInterface eth; + int connections = 0; + eth.init(); //Use DHCP + eth.connect(); + //printf("IP Address %s\n", eth.getIPAddress()); + + TCPSocketServer server; + server.bind(ECHO_SERVER_PORT); + server.listen(); + + while (true) { + printf("\nWait for new connection...\n"); + printf("Client number %d\n",++connections); + TCPSocketConnection client; + server.accept(client); + client.set_blocking(false, 2500); // Timeout after (1.5)s + printf("Connection from: %s\n", client.get_address()); + char buffer[1024]; + while (true) { + int retries = 0; + int dataReceived = 0; + int dataSent = 0; + + printf("\n\n\nStarting the receiving part...\n"); + while(dataReceived < BUFFER_QUANTITY) + { + int n = client.receive(buffer, sizeof(buffer)); + if (n <= 0) { + printf("Receive error\n"); + retries++; + if(retries >= MAX_NUMBER_OF_RETRIES) + break; + } + dataReceived += n; + } + + + printf("Received : %d bytes\nExpected : %d bytes\n",dataReceived,BUFFER_QUANTITY); + if(dataReceived < BUFFER_QUANTITY) + { + printf("Receiving part of the test has failed. Exiting connection.\n"); + break; + } + else{ + printf("Receiving has passed...\n"); + } + + printf("\n\n\nStarting the sending part...\n"); + retries = 0; + while(dataSent < BUFFER_QUANTITY) + { + int n = client.send_all(buffer, sizeof(buffer)); + if (n <= 0) { + printf("Send error\n"); + retries++; + if(retries >= MAX_NUMBER_OF_RETRIES) + break; + } + dataSent += n; + } + + printf("Sent : %d bytes\nExpected : %d bytes\n",dataSent,BUFFER_QUANTITY); + if(dataSent < BUFFER_QUANTITY) + { + printf("Sending part of the test has failed. Exiting connection.\n"); + break; + } + else + { + printf("Sending test has passed...\n"); + } + + + printf("\n\n\nStarting echo part...\n"); + dataReceived = dataSent = 0; + + while((dataReceived+dataSent) < 2*BUFFER_QUANTITY) + { + int n = client.receive(buffer, sizeof(buffer)); + if (n <= 0) { + printf("Receive error\n"); + } + dataReceived += n; + + n = client.send_all(buffer, n); + if (n <= 0) { + printf("Send error, returned 0\n"); + break; + } + dataSent += n; + } + + printf("Echo size : %d bytes\nExpected : %d bytes\n",(dataReceived+dataSent),2*BUFFER_QUANTITY); + if((dataReceived+dataSent) < 2*BUFFER_QUANTITY) + { + printf("Echo test has failed.Exiting connection...\n"); + break; + } + } + + client.close(); + printf("Test was finished...\n"); + + } + + return 0; +}
diff -r 000000000000 -r b88f77e8d572 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed Jul 24 13:53:23 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#58b30ac3f00e
diff -r 000000000000 -r b88f77e8d572 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jul 24 13:53:23 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17 \ No newline at end of file