summaryrefslogtreecommitdiff
path: root/apps/examples/nettest
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-10-08 08:33:00 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-10-08 08:33:00 -0600
commitfdb1d0a4df496e7a3232a950d5c72231363cf67a (patch)
tree5d18c1b4f9241f17396ec663ff4425bf21e6b57a /apps/examples/nettest
parent1753a0251a941fa4d1a5b95aec631209e9957670 (diff)
downloadnuttx-fdb1d0a4df496e7a3232a950d5c72231363cf67a.tar.gz
nuttx-fdb1d0a4df496e7a3232a950d5c72231363cf67a.tar.bz2
nuttx-fdb1d0a4df496e7a3232a950d5c72231363cf67a.zip
Remove non-portable references to syslog from apps/examples
Diffstat (limited to 'apps/examples/nettest')
-rw-r--r--apps/examples/nettest/nettest.h21
-rw-r--r--apps/examples/nettest/nettest_client.c36
-rw-r--r--apps/examples/nettest/nettest_server.c44
3 files changed, 43 insertions, 58 deletions
diff --git a/apps/examples/nettest/nettest.h b/apps/examples/nettest/nettest.h
index c6ed3f1be..e571cb7ba 100644
--- a/apps/examples/nettest/nettest.h
+++ b/apps/examples/nettest/nettest.h
@@ -57,31 +57,16 @@
# define HTONS(a) htons(a)
# define HTONL(a) htonl(a)
- /* Used printf for debug output */
-
-# ifdef CONFIG_CPP_HAVE_VARARGS
-# define message(...) printf(__VA_ARGS__)
-# else
-# define message printf
-# endif
-
/* Have SO_LINGER */
# define NETTEST_HAVE_SOLINGER 1
#else
-
- /* Used syslog() so that there is not confusion from buffered IO */
-
-# ifdef CONFIG_CPP_HAVE_VARARGS
-# define message(...) syslog(__VA_ARGS__)
+# ifdef CONFIG_NET_SOLINGER
+# define NETTEST_HAVE_SOLINGER 1
# else
-# define message syslog
+# undef NETTEST_HAVE_SOLINGER
# endif
-
- /* At present, uIP does only abortive disconnects */
-
-# undef NETTEST_HAVE_SOLINGER
#endif
#define PORTNO 5471
diff --git a/apps/examples/nettest/nettest_client.c b/apps/examples/nettest/nettest_client.c
index 7686d0ac8..9b6b97f79 100644
--- a/apps/examples/nettest/nettest_client.c
+++ b/apps/examples/nettest/nettest_client.c
@@ -80,7 +80,7 @@ void send_client(void)
if (!outbuf)
#endif
{
- message("client: failed to allocate buffers\n");
+ printf("client: failed to allocate buffers\n");
exit(1);
}
@@ -89,7 +89,7 @@ void send_client(void)
sockfd = socket(PF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
- message("client socket failure %d\n", errno);
+ printf("client socket failure %d\n", errno);
goto errout_with_buffers;
}
@@ -103,13 +103,13 @@ void send_client(void)
myaddr.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIP);
#endif
- message("client: Connecting...\n");
+ printf("client: Connecting...\n");
if (connect( sockfd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0)
{
- message("client: connect failure: %d\n", errno);
+ printf("client: connect failure: %d\n", errno);
goto errout_with_socket;
}
- message("client: Connected\n");
+ printf("client: Connected\n");
/* Initialize the buffer */
@@ -131,64 +131,64 @@ void send_client(void)
nbytessent = send(sockfd, outbuf, SENDSIZE, 0);
if (nbytessent < 0)
{
- message("client: send failed: %d\n", errno);
+ printf("client: send failed: %d\n", errno);
goto errout_with_socket;
}
else if (nbytessent != SENDSIZE)
{
- message("client: Bad send length=%d: %d of \n",
+ printf("client: Bad send length=%d: %d of \n",
nbytessent, SENDSIZE);
goto errout_with_socket;
}
- message("Sent %d bytes\n", nbytessent);
+ printf("Sent %d bytes\n", nbytessent);
}
#else
/* Then send and receive one message */
- message("client: Sending %d bytes\n", SENDSIZE);
+ printf("client: Sending %d bytes\n", SENDSIZE);
nbytessent = send(sockfd, outbuf, SENDSIZE, 0);
- message("client: Sent %d bytes\n", nbytessent);
+ printf("client: Sent %d bytes\n", nbytessent);
if (nbytessent < 0)
{
- message("client: send failed: %d\n", errno);
+ printf("client: send failed: %d\n", errno);
goto errout_with_socket;
}
else if (nbytessent != SENDSIZE)
{
- message("client: Bad send length: %d Expected: %d\n", nbytessent, SENDSIZE);
+ printf("client: Bad send length: %d Expected: %d\n", nbytessent, SENDSIZE);
goto errout_with_socket;
}
totalbytesrecvd = 0;
do
{
- message("client: Receiving...\n");
+ printf("client: Receiving...\n");
nbytesrecvd = recv(sockfd, &inbuf[totalbytesrecvd], SENDSIZE - totalbytesrecvd, 0);
if (nbytesrecvd < 0)
{
- message("client: recv failed: %d\n", errno);
+ printf("client: recv failed: %d\n", errno);
goto errout_with_socket;
}
else if (nbytesrecvd == 0)
{
- message("client: The server closed the connection\n");
+ printf("client: The server closed the connection\n");
goto errout_with_socket;
}
totalbytesrecvd += nbytesrecvd;
- message("client: Received %d of %d bytes\n", totalbytesrecvd, SENDSIZE);
+ printf("client: Received %d of %d bytes\n", totalbytesrecvd, SENDSIZE);
}
while (totalbytesrecvd < SENDSIZE);
if (totalbytesrecvd != SENDSIZE)
{
- message("client: Bad recv length: %d Expected: %d\n", totalbytesrecvd, SENDSIZE);
+ printf("client: Bad recv length: %d Expected: %d\n", totalbytesrecvd, SENDSIZE);
goto errout_with_socket;
}
else if (memcmp(inbuf, outbuf, SENDSIZE) != 0)
{
- message("client: Received buffer does not match sent buffer\n");
+ printf("client: Received buffer does not match sent buffer\n");
goto errout_with_socket;
}
diff --git a/apps/examples/nettest/nettest_server.c b/apps/examples/nettest/nettest_server.c
index bdea83dc8..4b4a4e6db 100644
--- a/apps/examples/nettest/nettest_server.c
+++ b/apps/examples/nettest/nettest_server.c
@@ -78,7 +78,7 @@ void recv_server(void)
buffer = (char*)malloc(2*SENDSIZE);
if (!buffer)
{
- message("server: failed to allocate buffer\n");
+ printf("server: failed to allocate buffer\n");
exit(1);
}
@@ -88,7 +88,7 @@ void recv_server(void)
listensd = socket(PF_INET, SOCK_STREAM, 0);
if (listensd < 0)
{
- message("server: socket failure: %d\n", errno);
+ printf("server: socket failure: %d\n", errno);
goto errout_with_buffer;
}
@@ -97,7 +97,7 @@ void recv_server(void)
optval = 1;
if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0)
{
- message("server: setsockopt SO_REUSEADDR failure: %d\n", errno);
+ printf("server: setsockopt SO_REUSEADDR failure: %d\n", errno);
goto errout_with_listensd;
}
@@ -109,7 +109,7 @@ void recv_server(void)
if (bind(listensd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0)
{
- message("server: bind failure: %d\n", errno);
+ printf("server: bind failure: %d\n", errno);
goto errout_with_listensd;
}
@@ -117,21 +117,21 @@ void recv_server(void)
if (listen(listensd, 5) < 0)
{
- message("server: listen failure %d\n", errno);
+ printf("server: listen failure %d\n", errno);
goto errout_with_listensd;
}
/* Accept only one connection */
- message("server: Accepting connections on port %d\n", PORTNO);
+ printf("server: Accepting connections on port %d\n", PORTNO);
addrlen = sizeof(struct sockaddr_in);
acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen);
if (acceptsd < 0)
{
- message("server: accept failure: %d\n", errno);
+ printf("server: accept failure: %d\n", errno);
goto errout_with_listensd;
}
- message("server: Connection accepted -- receiving\n");
+ printf("server: Connection accepted -- receiving\n");
/* Configure to "linger" until all data is sent when the socket is closed */
@@ -141,7 +141,7 @@ void recv_server(void)
if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)) < 0)
{
- message("server: setsockopt SO_LINGER failure: %d\n", errno);
+ printf("server: setsockopt SO_LINGER failure: %d\n", errno);
goto errout_with_acceptsd;
}
#endif
@@ -154,15 +154,15 @@ void recv_server(void)
nbytesread = recv(acceptsd, buffer, 2*SENDSIZE, 0);
if (nbytesread < 0)
{
- message("server: recv failed: %d\n", errno);
+ printf("server: recv failed: %d\n", errno);
goto errout_with_acceptsd;
}
else if (nbytesread == 0)
{
- message("server: The client broke the connection\n");
+ printf("server: The client broke the connection\n");
goto errout_with_acceptsd;
}
- message("Received %d bytes\n", nbytesread);
+ printf("Received %d bytes\n", nbytesread);
}
#else
/* Receive canned message */
@@ -170,28 +170,28 @@ void recv_server(void)
totalbytesread = 0;
while (totalbytesread < SENDSIZE)
{
- message("server: Reading...\n");
+ printf("server: Reading...\n");
nbytesread = recv(acceptsd, &buffer[totalbytesread], 2*SENDSIZE - totalbytesread, 0);
if (nbytesread < 0)
{
- message("server: recv failed: %d\n", errno);
+ printf("server: recv failed: %d\n", errno);
goto errout_with_acceptsd;
}
else if (nbytesread == 0)
{
- message("server: The client broke the connection\n");
+ printf("server: The client broke the connection\n");
goto errout_with_acceptsd;
}
totalbytesread += nbytesread;
- message("server: Received %d of %d bytes\n", totalbytesread, SENDSIZE);
+ printf("server: Received %d of %d bytes\n", totalbytesread, SENDSIZE);
}
/* Verify the message */
if (totalbytesread != SENDSIZE)
{
- message("server: Received %d / Expected %d bytes\n", totalbytesread, SENDSIZE);
+ printf("server: Received %d / Expected %d bytes\n", totalbytesread, SENDSIZE);
goto errout_with_acceptsd;
}
@@ -200,7 +200,7 @@ void recv_server(void)
{
if (buffer[i] != ch)
{
- message("server: Byte %d is %02x / Expected %02x\n", i, buffer[i], ch);
+ printf("server: Byte %d is %02x / Expected %02x\n", i, buffer[i], ch);
goto errout_with_acceptsd;
}
@@ -212,21 +212,21 @@ void recv_server(void)
/* Then send the same data back to the client */
- message("server: Sending %d bytes\n", totalbytesread);
+ printf("server: Sending %d bytes\n", totalbytesread);
nbytessent = send(acceptsd, buffer, totalbytesread, 0);
if (nbytessent <= 0)
{
- message("server: send failed: %d\n", errno);
+ printf("server: send failed: %d\n", errno);
goto errout_with_acceptsd;
}
- message("server: Sent %d bytes\n", nbytessent);
+ printf("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");
+ printf("server: Wait before closing\n");
sleep(60);
#endif