mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 07:33:37 +08:00
Correct and error in recv() and recvfrom() return value
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4402 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user