summaryrefslogtreecommitdiff
path: root/nuttx/examples/nettest/nettest-server.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-11-06 19:58:14 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-11-06 19:58:14 +0000
commit7a21220ebd5cef442fb059c90e18ff90232d8dc9 (patch)
tree38277e8efa923112be23e9a0554313c0927f02e2 /nuttx/examples/nettest/nettest-server.c
parent4fc87116d818f5285403dbb37d2aa60d33e4203a (diff)
downloadpx4-nuttx-7a21220ebd5cef442fb059c90e18ff90232d8dc9.tar.gz
px4-nuttx-7a21220ebd5cef442fb059c90e18ff90232d8dc9.tar.bz2
px4-nuttx-7a21220ebd5cef442fb059c90e18ff90232d8dc9.zip
Verified basic client-side network functionalitynuttx-3.0
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@373 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples/nettest/nettest-server.c')
-rw-r--r--nuttx/examples/nettest/nettest-server.c39
1 files changed, 37 insertions, 2 deletions
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