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:
patacongo 2012-01-31 17:38:45 +00:00
parent 1df049bbc3
commit 7702043472
3 changed files with 39 additions and 29 deletions

View File

@ -160,7 +160,10 @@ static int telnetd_daemon(int argc, char *argv[])
goto errout_with_socket; 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 #ifndef CONFIG_DEBUG
close(0); close(0);
@ -172,13 +175,13 @@ static int telnetd_daemon(int argc, char *argv[])
for (;;) 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); addrlen = sizeof(struct sockaddr_in);
acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen); acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen);
if (acceptsd < 0) if (acceptsd < 0)
{ {
ndbg("accept failed: %d\n", errno); nlldbg("accept failed: %d\n", errno);
goto errout_with_socket; goto errout_with_socket;
} }
@ -189,28 +192,28 @@ static int telnetd_daemon(int argc, char *argv[])
ling.l_linger = 30; /* timeout is seconds */ ling.l_linger = 30; /* timeout is seconds */
if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)) < 0) 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; goto errout_with_acceptsd;
} }
#endif #endif
/* Create a character device to "wrap" the accepted socket descriptor */ /* 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); devpath = telnetd_driver(acceptsd, daemon);
if (devpath < 0) if (devpath < 0)
{ {
ndbg("telnetd_driver failed\n"); nlldbg("telnetd_driver failed\n");
goto errout_with_acceptsd; goto errout_with_acceptsd;
} }
/* Open the driver */ /* Open the driver */
nvdbg("Opening the telnet driver\n"); nllvdbg("Opening the telnet driver\n");
drvrfd = open(devpath, O_RDWR); drvrfd = open(devpath, O_RDWR);
if (drvrfd < 0) 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; goto errout_with_acceptsd;
} }
@ -235,12 +238,12 @@ static int telnetd_daemon(int argc, char *argv[])
* will inherit the new stdin, stdout, and stderr. * 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, pid = TASK_CREATE("Telnet session", daemon->priority, daemon->stacksize,
daemon->entry, NULL); daemon->entry, NULL);
if (pid < 0) 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; goto errout_with_acceptsd;
} }

View File

@ -508,29 +508,36 @@ static ssize_t telnetd_read(FAR struct file *filep, FAR char *buffer, size_t len
nllvdbg("len: %d\n", len); nllvdbg("len: %d\n", len);
/* First, handle the case where there are still valid bytes left in the /* 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]; if (priv->td_pending > 0)
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)
{ {
/* 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); /* Read a buffer of data from the telnet client */
ret = telnetd_receive(priv, priv->td_rxbuffer, ret, buffer, len);
} 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; return ret;
} }

View File

@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* lib/stdio/lib_fgets.c * lib/stdio/lib_fgets.c
* *
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions