Fix a bug in recvfrom()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3670 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
33a74e2ffa
commit
3f97ba4c55
@ -166,31 +166,6 @@ static int ftpc_recvinit(struct ftpc_session_s *session, FAR const char *path,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: ftpc_waitinput
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Wait to receive data.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int ftpc_waitinput(FAR struct ftpc_session_s *session)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
do {
|
|
||||||
ret = ftpc_waitdata(session, session->data.instream, true);
|
|
||||||
if (ret == -1) {
|
|
||||||
if (errno == EINTR)
|
|
||||||
{
|
|
||||||
FTPC_SET_INTERRUPT(session);
|
|
||||||
}
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
} while(ret == 0);
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ftpc_recvbinary
|
* Name: ftpc_recvbinary
|
||||||
*
|
*
|
||||||
@ -219,16 +194,6 @@ static int ftpc_recvbinary(FAR struct ftpc_session_s *session,
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
/* Wait for input on the socket */
|
|
||||||
|
|
||||||
ret = ftpc_waitinput(session);
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
nvdbg("ftpc_waitinput() failed\n");
|
|
||||||
err = EIO;
|
|
||||||
goto errout_with_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read the data from the socket */
|
/* Read the data from the socket */
|
||||||
|
|
||||||
nread = fread(buf, sizeof(char), CONFIG_FTP_BUFSIZE, rinstream);
|
nread = fread(buf, sizeof(char), CONFIG_FTP_BUFSIZE, rinstream);
|
||||||
@ -451,15 +416,6 @@ int ftpc_recvtext(FAR struct ftpc_session_s *session,
|
|||||||
|
|
||||||
while ((ch = fgetc(rinstream)) != EOF)
|
while ((ch = fgetc(rinstream)) != EOF)
|
||||||
{
|
{
|
||||||
/* Wait for input on the socket */
|
|
||||||
|
|
||||||
ret = ftpc_waitinput(session);
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
nvdbg("ftpc_waitinput() failed\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is it a carriage return? Compress \r\n to \n */
|
/* Is it a carriage return? Compress \r\n to \n */
|
||||||
|
|
||||||
if (ch == '\r')
|
if (ch == '\r')
|
||||||
|
@ -71,30 +71,6 @@
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: ftpc_waitoutput
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Wait to send data.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int ftpc_waitoutput(FAR struct ftpc_session_s *session)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
ret = ftpc_waitdata(session, session->data.outstream, false);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(ret == 0);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ftpc_sendbinary
|
* Name: ftpc_sendbinary
|
||||||
*
|
*
|
||||||
@ -129,15 +105,6 @@ static int ftpc_sendbinary(FAR struct ftpc_session_s *session,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait to make sure that we send the data without blocking */
|
|
||||||
|
|
||||||
ret = ftpc_waitoutput(session);
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
ret = ERROR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Send the data */
|
/* Send the data */
|
||||||
|
|
||||||
nwritten = fwrite(buf, sizeof(char), nread, routstream);
|
nwritten = fwrite(buf, sizeof(char), nread, routstream);
|
||||||
@ -174,15 +141,8 @@ static int ftpc_sendtext(FAR struct ftpc_session_s *session,
|
|||||||
|
|
||||||
/* Write characters one at a time. */
|
/* Write characters one at a time. */
|
||||||
|
|
||||||
while((c = fgetc(linstream)) != EOF)
|
while ((c = fgetc(linstream)) != EOF)
|
||||||
{
|
{
|
||||||
/* Make sure that we can send the character without blocking */
|
|
||||||
|
|
||||||
if (ftpc_waitoutput(session) != 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If it is a newline, send a carriage return too */
|
/* If it is a newline, send a carriage return too */
|
||||||
|
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
|
@ -185,8 +185,8 @@ int ftpc_sockconnect(struct ftpc_socket_s *sock, struct sockaddr_in *addr)
|
|||||||
ndbg("ftpc_sockgetsockname() failed: %d\n", errno);
|
ndbg("ftpc_sockgetsockname() failed: %d\n", errno);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
sock->connected = true;
|
|
||||||
|
|
||||||
|
sock->connected = true;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <poll.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -289,8 +288,8 @@ int ftpc_xfrinit(FAR struct ftpc_session_s *session)
|
|||||||
/* Configure the data socket */
|
/* Configure the data socket */
|
||||||
|
|
||||||
ftpc_sockgetsockname(&session->cmd, &addr);
|
ftpc_sockgetsockname(&session->cmd, &addr);
|
||||||
memcpy(&addr.sin_addr, addrport, (size_t)4);
|
memcpy(&addr.sin_addr, addrport, 4);
|
||||||
memcpy(&addr.sin_port, addrport+4, (size_t)2);
|
memcpy(&addr.sin_port, addrport+4, 2);
|
||||||
|
|
||||||
/* Connect the data socket */
|
/* Connect the data socket */
|
||||||
|
|
||||||
@ -461,36 +460,6 @@ int ftpc_xfrabort(FAR struct ftpc_session_s *session, FAR FILE *stream)
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: ftpc_waitdata
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Wait for dta to be available on the provided stream.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int ftpc_waitdata(FAR struct ftpc_session_s *session, FAR FILE *stream, bool rdwait)
|
|
||||||
{
|
|
||||||
FAR struct pollfd fds;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Check the stream to see if it has input OR is ready for output */
|
|
||||||
|
|
||||||
fds.fd = fileno(stream);
|
|
||||||
fds.events = rdwait ? POLLIN : POLLOUT;
|
|
||||||
ret = poll(&fds, 1, 10*1000);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
if (errno == EINTR)
|
|
||||||
{
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ftpc_timeout
|
* Name: ftpc_timeout
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user