forked from Archive/PX4-Autopilot
Fix a error the telnet driver read method. Don't return if only protocol stuff is read
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4352 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
1df049bbc3
commit
7702043472
|
@ -160,7 +160,10 @@ static int telnetd_daemon(int argc, char *argv[])
|
|||
goto errout_with_socket;
|
||||
}
|
||||
|
||||
/* Now go silent */
|
||||
/* Now go silent. Only the lldbg family of debug functions should
|
||||
* be used after this point because these do not depend on stdout
|
||||
* being available.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DEBUG
|
||||
close(0);
|
||||
|
@ -172,13 +175,13 @@ static int telnetd_daemon(int argc, char *argv[])
|
|||
|
||||
for (;;)
|
||||
{
|
||||
nvdbg("Accepting connections on port %d\n", ntohs(daemon->port));
|
||||
nllvdbg("Accepting connections on port %d\n", ntohs(daemon->port));
|
||||
|
||||
addrlen = sizeof(struct sockaddr_in);
|
||||
acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen);
|
||||
if (acceptsd < 0)
|
||||
{
|
||||
ndbg("accept failed: %d\n", errno);
|
||||
nlldbg("accept failed: %d\n", errno);
|
||||
goto errout_with_socket;
|
||||
}
|
||||
|
||||
|
@ -189,28 +192,28 @@ static int telnetd_daemon(int argc, char *argv[])
|
|||
ling.l_linger = 30; /* timeout is seconds */
|
||||
if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)) < 0)
|
||||
{
|
||||
ndbg("setsockopt failed: %d\n", errno);
|
||||
nlldbg("setsockopt failed: %d\n", errno);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Create a character device to "wrap" the accepted socket descriptor */
|
||||
|
||||
nvdbg("Creating the telnet driver\n");
|
||||
nllvdbg("Creating the telnet driver\n");
|
||||
devpath = telnetd_driver(acceptsd, daemon);
|
||||
if (devpath < 0)
|
||||
{
|
||||
ndbg("telnetd_driver failed\n");
|
||||
nlldbg("telnetd_driver failed\n");
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
|
||||
/* Open the driver */
|
||||
|
||||
nvdbg("Opening the telnet driver\n");
|
||||
nllvdbg("Opening the telnet driver\n");
|
||||
drvrfd = open(devpath, O_RDWR);
|
||||
if (drvrfd < 0)
|
||||
{
|
||||
ndbg("Failed to open %s: %d\n", devpath, errno);
|
||||
nlldbg("Failed to open %s: %d\n", devpath, errno);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
|
||||
|
@ -235,12 +238,12 @@ static int telnetd_daemon(int argc, char *argv[])
|
|||
* will inherit the new stdin, stdout, and stderr.
|
||||
*/
|
||||
|
||||
nvdbg("Starting the telnet session\n");
|
||||
nllvdbg("Starting the telnet session\n");
|
||||
pid = TASK_CREATE("Telnet session", daemon->priority, daemon->stacksize,
|
||||
daemon->entry, NULL);
|
||||
if (pid < 0)
|
||||
{
|
||||
ndbg("Failed start the telnet session: %d\n", errno);
|
||||
nlldbg("Failed start the telnet session: %d\n", errno);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
|
||||
|
|
|
@ -508,29 +508,36 @@ static ssize_t telnetd_read(FAR struct file *filep, FAR char *buffer, size_t len
|
|||
nllvdbg("len: %d\n", len);
|
||||
|
||||
/* First, handle the case where there are still valid bytes left in the
|
||||
* I/O buffer from the last time that read was called.
|
||||
* I/O buffer from the last time that read was called. NOTE: Much of
|
||||
* what we read may be protocol stuff and may not correspond to user
|
||||
* data. Hence we need the loop and we need may need to call psock_recv()
|
||||
* multiple times in order to get data that the client is interested in.
|
||||
*/
|
||||
|
||||
if (priv->td_pending > 0)
|
||||
do
|
||||
{
|
||||
FAR const char *src = &priv->td_rxbuffer[priv->td_offset];
|
||||
ret = telnetd_receive(priv, src, priv->td_pending, buffer, len);
|
||||
}
|
||||
|
||||
/* Read a buffer of data from the telnet client */
|
||||
|
||||
else
|
||||
{
|
||||
ret = psock_recv(&priv->td_psock, priv->td_rxbuffer,
|
||||
CONFIG_TELNETD_RXBUFFER_SIZE, 0);
|
||||
if (ret > 0)
|
||||
if (priv->td_pending > 0)
|
||||
{
|
||||
/* Process the received telnet data */
|
||||
FAR const char *src = &priv->td_rxbuffer[priv->td_offset];
|
||||
ret = telnetd_receive(priv, src, priv->td_pending, buffer, len);
|
||||
}
|
||||
|
||||
telnetd_dumpbuffer("Received buffer", priv->td_rxbuffer, ret);
|
||||
ret = telnetd_receive(priv, priv->td_rxbuffer, ret, buffer, len);
|
||||
}
|
||||
/* Read a buffer of data from the telnet client */
|
||||
|
||||
else
|
||||
{
|
||||
ret = psock_recv(&priv->td_psock, priv->td_rxbuffer,
|
||||
CONFIG_TELNETD_RXBUFFER_SIZE, 0);
|
||||
if (ret > 0)
|
||||
{
|
||||
/* Process the received telnet data */
|
||||
|
||||
telnetd_dumpbuffer("Received buffer", priv->td_rxbuffer, ret);
|
||||
ret = telnetd_receive(priv, priv->td_rxbuffer, ret, buffer, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (ret == 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/****************************************************************************
|
||||
* lib/stdio/lib_fgets.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2007-2008, 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
|
||||
|
|
Loading…
Reference in New Issue