diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-02-18 18:13:30 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-02-18 18:13:30 +0000 |
commit | fadbb925a6a118790d8d661fea3956bb0f76348a (patch) | |
tree | ca4c58d32d12949e8d08cb69a652b5e3f7fd0e58 /apps/examples | |
parent | 376af5201c555ee163045a8103d8e592f9a1b1bc (diff) | |
download | nuttx-fadbb925a6a118790d8d661fea3956bb0f76348a.tar.gz nuttx-fadbb925a6a118790d8d661fea3956bb0f76348a.tar.bz2 nuttx-fadbb925a6a118790d8d661fea3956bb0f76348a.zip |
Correct and error in recv() and recvfrom() return value
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4402 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/examples')
-rwxr-xr-x | apps/examples/ftpd/ftpd_main.c | 10 | ||||
-rw-r--r-- | apps/examples/nettest/nettest_client.c | 7 | ||||
-rw-r--r-- | apps/examples/nettest/nettest_server.c | 16 | ||||
-rw-r--r-- | apps/examples/poll/host.c | 9 | ||||
-rw-r--r-- | apps/examples/poll/net_listener.c | 4 | ||||
-rw-r--r-- | apps/examples/poll/net_reader.c | 4 | ||||
-rw-r--r-- | apps/examples/udp/udp-server.c | 4 |
7 files changed, 41 insertions, 13 deletions
diff --git a/apps/examples/ftpd/ftpd_main.c b/apps/examples/ftpd/ftpd_main.c index d4808a4aa..fbabf64de 100755 --- a/apps/examples/ftpd/ftpd_main.c +++ b/apps/examples/ftpd/ftpd_main.c @@ -188,7 +188,15 @@ int ftpd_daemon(int s_argc, char **s_argv) */ ret = ftpd_session(handle, 5000); - printf("FTP daemon [%d] ftpd_session returned %d\n", g_ftpdglob.pid, ret); + + /* If any interesting happened (i.e., any thing other than a timeout), + * then report the interesting event. + */ + + if (ret != -ETIMEDOUT) + { + printf("FTP daemon [%d] ftpd_session returned %d\n", g_ftpdglob.pid, ret); + } } /* Close the FTPD server and exit (we can get here only if diff --git a/apps/examples/nettest/nettest_client.c b/apps/examples/nettest/nettest_client.c index 5f95d7b70..d498feb31 100644 --- a/apps/examples/nettest/nettest_client.c +++ b/apps/examples/nettest/nettest_client.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/nettest/nettest-client.c * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -169,6 +169,11 @@ void send_client(void) message("client: recv failed: %d\n", errno); goto errout_with_socket; } + else if (nbytesrecvd == 0) + { + message("client: The server closed the connection\n"); + goto errout_with_socket; + } totalbytesrecvd += nbytesrecvd; message("client: Received %d of %d bytes\n", totalbytesrecvd, SENDSIZE); } diff --git a/apps/examples/nettest/nettest_server.c b/apps/examples/nettest/nettest_server.c index 45ef3a39a..76a20e652 100644 --- a/apps/examples/nettest/nettest_server.c +++ b/apps/examples/nettest/nettest_server.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/nettest/nettest-server.c * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -149,11 +149,16 @@ void recv_server(void) for (;;) { nbytesread = recv(acceptsd, buffer, 2*SENDSIZE, 0); - if (nbytesread <= 0) + if (nbytesread < 0) { message("server: recv failed: %d\n", errno); goto errout_with_acceptsd; } + else if (nbytesread == 0) + { + message("server: The client broke the connection\n"); + goto errout_with_acceptsd; + } message("Received %d bytes\n", nbytesread); } #else @@ -164,11 +169,16 @@ void recv_server(void) { message("server: Reading...\n"); nbytesread = recv(acceptsd, &buffer[totalbytesread], 2*SENDSIZE - totalbytesread, 0); - if (nbytesread <= 0) + if (nbytesread < 0) { message("server: recv failed: %d\n", errno); goto errout_with_acceptsd; } + else if (nbytesread == 0) + { + message("server: The client broke the connection\n"); + goto errout_with_acceptsd; + } totalbytesread += nbytesread; message("server: Received %d of %d bytes\n", totalbytesread, SENDSIZE); diff --git a/apps/examples/poll/host.c b/apps/examples/poll/host.c index 47f2c3e53..302cceb0f 100644 --- a/apps/examples/poll/host.c +++ b/apps/examples/poll/host.c @@ -1,8 +1,8 @@ /**************************************************************************** * examples/poll/host.c * - * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2008-2009, 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -137,6 +137,11 @@ int main(int argc, char **argv, char **envp) message("client: recv failed: %d\n", errno); goto errout_with_socket; } + else if (nbytesrecvd == 0) + { + message("client: The server broke the connections\n"); + goto errout_with_socket; + } inbuf[nbytesrecvd] = '\0'; message("client: Received '%s' (%d bytes)\n", inbuf, nbytesrecvd); diff --git a/apps/examples/poll/net_listener.c b/apps/examples/poll/net_listener.c index 4d425c608..4bde567fb 100644 --- a/apps/examples/poll/net_listener.c +++ b/apps/examples/poll/net_listener.c @@ -1,8 +1,8 @@ /**************************************************************************** * examples/poll/net_listener.c * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/poll/net_reader.c b/apps/examples/poll/net_reader.c index b0cf94316..ea0accc8d 100644 --- a/apps/examples/poll/net_reader.c +++ b/apps/examples/poll/net_reader.c @@ -1,8 +1,8 @@ /**************************************************************************** * examples/poll/net_reader.c * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/apps/examples/udp/udp-server.c b/apps/examples/udp/udp-server.c index 495a71320..1f4774deb 100644 --- a/apps/examples/udp/udp-server.c +++ b/apps/examples/udp/udp-server.c @@ -1,8 +1,8 @@ /**************************************************************************** * examples/udp/udp-server.c * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2007, 2009, 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions |