From 7a21220ebd5cef442fb059c90e18ff90232d8dc9 Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 6 Nov 2007 19:58:14 +0000 Subject: Verified basic client-side network functionality git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@373 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/examples/nettest/nettest-server.c | 39 +++++++++++++++++++++++++++++++-- nuttx/examples/nettest/nettest.h | 20 +++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) (limited to 'nuttx/examples') diff --git a/nuttx/examples/nettest/nettest-server.c b/nuttx/examples/nettest/nettest-server.c index 2f398583a..98b1cc98f 100644 --- a/nuttx/examples/nettest/nettest-server.c +++ b/nuttx/examples/nettest/nettest-server.c @@ -55,6 +55,9 @@ void recv_server(void) { struct sockaddr_in myaddr; +#ifdef NETTEST_HAVE_SOLINGER + struct linger ling; +#endif char buffer[1024]; int listensd; int acceptsd; @@ -82,11 +85,11 @@ void recv_server(void) optval = 1; if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) { - message("server: setsockopt failure: %d\n", errno); + message("server: setsockopt SO_REUSEADDR failure: %d\n", errno); exit(1); } - /* Bind the TCP socket to a local address */ + /* Bind the socket to a local address */ myaddr.sin_family = AF_INET; myaddr.sin_port = HTONS(PORTNO); @@ -118,6 +121,18 @@ void recv_server(void) } message("server: Connection accepted -- receiving\n"); + /* Configure to "linger" until all data is sent when the socket is closed */ + +#ifdef NETTEST_HAVE_SOLINGER + ling.l_onoff = 1; + ling.l_linger = 30; /* timeout is seconds */ + if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)) < 0) + { + message("server: setsockopt SO_LINGER failure: %d\n", errno); + exit(1); + } +#endif + #ifdef CONFIG_NETTEST_PERFORMANCE /* Then receive data forever */ @@ -179,6 +194,17 @@ void recv_server(void) } } +#ifdef CONFIG_NETTEST_HOST + /* At present, data received by the target before it is completed the + * the write opertion and started the read operation results in a failure + * (the data is not received, but it is ACKed). This will have to be + * fixed. + */ + +# warning "FIXME: This should not be necessary" + sleep(10); +#endif + /* Then send the same data back to the client */ nbytessent = send(acceptsd, buffer, totalbytesread, 0); @@ -191,6 +217,15 @@ void recv_server(void) } message("server: Sent %d bytes\n", nbytessent); + /* If this platform only does abortive disconnects, then wait a bit to get the + * client side a change to receive the data. + */ + +#if 1 /* Do it for all platforms */ + message("server: Wait before closing\n"); + sleep(60); +#endif + close(listensd); close(acceptsd); #endif diff --git a/nuttx/examples/nettest/nettest.h b/nuttx/examples/nettest/nettest.h index b868ec90d..9fe735911 100644 --- a/nuttx/examples/nettest/nettest.h +++ b/nuttx/examples/nettest/nettest.h @@ -54,14 +54,34 @@ # define HTONS(a) htons(a) # define HTONL(a) htonl(a) + + /* Used printf for debug output */ + # define message(...) printf(__VA_ARGS__) + + /* Have SO_LINGER */ + +# define NETTEST_HAVE_SOLINGER 1 + #else + + /* Get errno using a pointer */ + # define errno *get_errno_ptr() + + /* If debug is enabled, use the synchronous lib_lowprintf so that the + * program output does not get disassociated in the debug output. + */ + # ifdef CONFIG_DEBUG # define message(...) lib_lowprintf(__VA_ARGS__) # else # define message(...) printf(__VA_ARGS__) # endif + + /* At present, uIP does only abortive disconnects */ + +# undef NETTEST_HAVE_SOLINGER #endif #define PORTNO 5471 -- cgit v1.2.3