summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-31 15:41:07 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-31 15:41:07 +0000
commitd2dfd9fdd6cb1c57375468919c1b37e91b3a8f3e (patch)
treeffc0d9f4c58f5424a1debcd729933ce76f6c93f3
parent683c7dbd29a864ee20c792918fd32eedf9b53f69 (diff)
downloadnuttx-d2dfd9fdd6cb1c57375468919c1b37e91b3a8f3e.tar.gz
nuttx-d2dfd9fdd6cb1c57375468919c1b37e91b3a8f3e.tar.bz2
nuttx-d2dfd9fdd6cb1c57375468919c1b37e91b3a8f3e.zip
Various fixes for the telnet driver
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4351 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--apps/examples/telnetd/shell.c1
-rw-r--r--apps/netutils/telnetd/telnetd_driver.c47
-rw-r--r--nuttx/lib/stdio/lib_fprintf.c4
-rw-r--r--nuttx/lib/stdio/lib_libfflush.c4
-rw-r--r--nuttx/lib/stdio/lib_printf.c4
5 files changed, 36 insertions, 24 deletions
diff --git a/apps/examples/telnetd/shell.c b/apps/examples/telnetd/shell.c
index 356c33738..9e2a2e30e 100644
--- a/apps/examples/telnetd/shell.c
+++ b/apps/examples/telnetd/shell.c
@@ -163,6 +163,7 @@ int shell_session(int argc, char *argv[])
for(;;)
{
printf(SHELL_PROMPT);
+ fflush(stdout);
if (fgets(line, 128, stdin) == NULL)
{
diff --git a/apps/netutils/telnetd/telnetd_driver.c b/apps/netutils/telnetd/telnetd_driver.c
index 991f43705..7507ad1c0 100644
--- a/apps/netutils/telnetd/telnetd_driver.c
+++ b/apps/netutils/telnetd/telnetd_driver.c
@@ -221,10 +221,12 @@ static ssize_t telnetd_receive(struct telnetd_dev_s *priv, FAR const char *src,
int nread;
uint8_t ch;
+ nllvdbg("srclen: %d destlen: %d\n", srclen, destlen);
+
for (nread = 0; srclen > 0 && nread < destlen; srclen--)
{
ch = *src++;
- nvdbg("ch=%02x state=%d\n", ch, priv->td_state);
+ nllvdbg("ch=%02x state=%d\n", ch, priv->td_state);
switch (priv->td_state)
{
@@ -389,7 +391,7 @@ static void telnetd_sendopt(struct telnetd_dev_s *priv, uint8_t option,
telnetd_dumpbuffer("Send optbuf", optbuf, 4);
if (psock_send(&priv->td_psock, optbuf, 4, 0) < 0)
{
- ndbg("Failed to send TELNET_IAC\n");
+ nlldbg("Failed to send TELNET_IAC\n");
}
}
@@ -404,7 +406,7 @@ static int telnetd_open(FAR struct file *filep)
int tmp;
int ret;
- nvdbg("td_crefs: %d\n", priv->td_crefs);
+ nllvdbg("td_crefs: %d\n", priv->td_crefs);
/* O_NONBLOCK is not supported */
@@ -459,7 +461,7 @@ static int telnetd_close(FAR struct file *filep)
FAR struct telnetd_dev_s *priv = inode->i_private;
int ret;
- nvdbg("td_crefs: %d\n", priv->td_crefs);
+ nllvdbg("td_crefs: %d\n", priv->td_crefs);
/* Get exclusive access to the device structures */
@@ -503,6 +505,8 @@ static ssize_t telnetd_read(FAR struct file *filep, FAR char *buffer, size_t len
FAR struct telnetd_dev_s *priv = inode->i_private;
ssize_t ret;
+ 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.
*/
@@ -546,9 +550,11 @@ static ssize_t telnetd_write(FAR struct file *filep, FAR const char *buffer, siz
char ch;
bool eol;
+ nllvdbg("len: %d\n", len);
+
/* Process each character from the user buffer */
- for (nsent = 0, ncopied = 0; len > 0; len--)
+ for (nsent = 0, ncopied = 0; nsent < len; nsent++)
{
/* Get the next character from the user buffer */
@@ -569,14 +575,12 @@ static ssize_t telnetd_write(FAR struct file *filep, FAR const char *buffer, siz
ret = psock_send(&priv->td_psock, priv->td_txbuffer, ncopied, 0);
if (ret < 0)
{
- ndbg("Failed to send response: %s\n", priv->td_txbuffer);
+ nlldbg("psock_send failed '%s': %d\n", priv->td_txbuffer, ret);
+ return ret;
}
- /* Reset the index to the beginning of the TX buffer. Remember
- * the total number of bytes sent;
- */
+ /* Reset the index to the beginning of the TX buffer. */
- nsent += ret;
ncopied = 0;
}
}
@@ -588,12 +592,19 @@ static ssize_t telnetd_write(FAR struct file *filep, FAR const char *buffer, siz
ret = psock_send(&priv->td_psock, priv->td_txbuffer, ncopied, 0);
if (ret < 0)
{
- ndbg("Failed to send response: %s\n", priv->td_txbuffer);
+ nlldbg("psock_send failed '%s': %d\n", priv->td_txbuffer, ret);
+ return ret;
}
- nsent += ret;
}
- return nsent;
+ /* Notice that we don't actually return the number of bytes sent, but
+ * rather, the number of bytes that the caller asked us to send. We may
+ * have sent more bytes (because of CR-LF expansion and because of NULL
+ * termination). But it confuses some logic if you report that you sent
+ * more than you were requested to.
+ */
+
+ return len;
}
/****************************************************************************
@@ -671,7 +682,7 @@ FAR char *telnetd_driver(int sd, FAR struct telnetd_s *daemon)
priv = (FAR struct telnetd_dev_s*)malloc(sizeof(struct telnetd_dev_s));
if (!priv)
{
- ndbg("Failed to allocate the driver data structure\n");
+ nlldbg("Failed to allocate the driver data structure\n");
return NULL;
}
@@ -690,14 +701,14 @@ FAR char *telnetd_driver(int sd, FAR struct telnetd_s *daemon)
psock = sockfd_socket(sd);
if (!psock)
{
- ndbg("Failed to convert sd=%d to a socket structure\n", sd);
+ nlldbg("Failed to convert sd=%d to a socket structure\n", sd);
goto errout_with_dev;
}
ret = net_clone(psock, &priv->td_psock);
if (ret < 0)
{
- ndbg("net_clone failed: %d\n", ret);
+ nlldbg("net_clone failed: %d\n", ret);
goto errout_with_dev;
}
@@ -726,7 +737,7 @@ FAR char *telnetd_driver(int sd, FAR struct telnetd_s *daemon)
ret = asprintf(&devpath, "/dev/telnetd%d", minor);
if (ret < 0)
{
- ndbg("Failed to allocate the driver path\n");
+ nlldbg("Failed to allocate the driver path\n");
goto errout_with_dev;
}
@@ -735,7 +746,7 @@ FAR char *telnetd_driver(int sd, FAR struct telnetd_s *daemon)
ret = register_driver(devpath, &g_telnetdfops, 0666, priv);
if (ret < 0)
{
- ndbg("Failed to register the driver %s: %d\n", ret);
+ nlldbg("Failed to register the driver %s: %d\n", ret);
goto errout_with_devpath;
}
diff --git a/nuttx/lib/stdio/lib_fprintf.c b/nuttx/lib/stdio/lib_fprintf.c
index 4ebb3d7d2..a803de4bd 100644
--- a/nuttx/lib/stdio/lib_fprintf.c
+++ b/nuttx/lib/stdio/lib_fprintf.c
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_fprintf.c
*
- * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * 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
* modification, are permitted provided that the following conditions
diff --git a/nuttx/lib/stdio/lib_libfflush.c b/nuttx/lib/stdio/lib_libfflush.c
index ddfc6c8ff..5da9c763d 100644
--- a/nuttx/lib/stdio/lib_libfflush.c
+++ b/nuttx/lib/stdio/lib_libfflush.c
@@ -1,7 +1,7 @@
/****************************************************************************
* lib/stdio/lib_libfflush.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 <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -108,7 +108,7 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
#if CONFIG_STDIO_BUFFER_SIZE > 0
FAR const unsigned char *src;
ssize_t bytes_written;
- size_t nbuffer;
+ ssize_t nbuffer;
/* Return EBADF if the file is not opened for writing */
diff --git a/nuttx/lib/stdio/lib_printf.c b/nuttx/lib/stdio/lib_printf.c
index d24355f40..50db06c47 100644
--- a/nuttx/lib/stdio/lib_printf.c
+++ b/nuttx/lib/stdio/lib_printf.c
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_printf.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