summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/examples/README.txt8
-rw-r--r--apps/netutils/ftpc/ftpc_getfile.c10
-rw-r--r--apps/netutils/ftpc/ftpc_socket.c61
-rwxr-xr-xnuttx/configs/olimex-lpc1766stk/README.txt8
-rwxr-xr-xnuttx/configs/olimex-lpc1766stk/ftpc/defconfig5
-rw-r--r--nuttx/fs/fs_fdopen.c8
6 files changed, 60 insertions, 40 deletions
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index a67d9ad04..5a9d050b4 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -60,9 +60,11 @@ examples/ftpc
an example, your configration could have different mass storage devices,
mount paths, and FTP directories:
- mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp
- cd /tmp # cd into the /tmp directory
- ftpc xx.xx.xx.xx[:pp] # Start the FTP client
+ nsh> mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp
+ nsh> cd /tmp # cd into the /tmp directory
+ nsh> ftpc xx.xx.xx.xx[:pp] # Start the FTP client
+ nfc> login <name> <password> # Log into the FTP server
+ nfc> help # See a list of FTP commands
where xx.xx.xx.xx is the IP address of the FTP server and pp is an
optional port number.
diff --git a/apps/netutils/ftpc/ftpc_getfile.c b/apps/netutils/ftpc/ftpc_getfile.c
index 30595d942..846a1e1db 100644
--- a/apps/netutils/ftpc/ftpc_getfile.c
+++ b/apps/netutils/ftpc/ftpc_getfile.c
@@ -149,13 +149,15 @@ static int ftpc_recvinit(struct ftpc_session_s *session, FAR const char *path,
return ERROR;
}
- /* Accept a connection on the data socket */
+ /* Accept a connection on the data socket (unless passive mode then the
+ * function does nothing).
+ */
ret = ftpc_sockaccept(&session->data, FTPC_IS_PASSIVE(session));
if (ret != OK)
- {
- ndbg("Data connection not accepted\n");
- }
+ {
+ ndbg("Data connection not accepted\n");
+ }
return ret;
}
diff --git a/apps/netutils/ftpc/ftpc_socket.c b/apps/netutils/ftpc/ftpc_socket.c
index 6d917cf36..bfa8ec7c1 100644
--- a/apps/netutils/ftpc/ftpc_socket.c
+++ b/apps/netutils/ftpc/ftpc_socket.c
@@ -37,6 +37,7 @@
* Included Files
****************************************************************************/
+#include "ftpc_config.h"
#include <sys/socket.h>
#include <stdlib.h>
@@ -208,7 +209,8 @@ void ftpc_sockcopy(FAR struct ftpc_socket_s *dest,
* Name: ftpc_sockaccept
*
* Description:
- * Accept a connection from the server.
+ * Accept a connection on the data socket (unless passive mode then this
+ * function does nothing).
*
****************************************************************************/
@@ -217,16 +219,6 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
struct sockaddr addr;
socklen_t addrlen;
- /* Any previous socket should have been uninitialized (0) or explicitly
- * closed (-1). But the path to this function may include a call to
- * ftpc_sockinit().
- */
-
- if (sock->sd > 0)
- {
- ftpc_sockclose(sock);
- }
-
/* In active mode FTP the client connects from a random port (N>1023) to the
* FTP server's command port, port 21. Then, the client starts listening to
* port N+1 and sends the FTP command PORT N+1 to the FTP server. The server
@@ -246,6 +238,17 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
if (!passive)
{
+ /* Any previous socket should have been uninitialized (0) or explicitly
+ * closed (-1). But the path to this function may include a call to
+ * ftpc_sockinit(). If so... close that socket and call accept to
+ * get a new one.
+ */
+
+ if (sock->sd > 0)
+ {
+ ftpc_sockclose(sock);
+ }
+
addrlen = sizeof(addr);
sock->sd = accept(sock->sd, &addr, &addrlen);
if (sock->sd == -1)
@@ -255,26 +258,32 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
}
memcpy(&sock->laddr, &addr, sizeof(sock->laddr));
- }
- /* Create in/out C buffer I/O streams on the data channel. First, create
- * the incoming buffered stream.
- */
+ /* Create in/out C buffer I/O streams on the data channel. First,
+ * create the incoming buffered stream.
+ */
- sock->instream = fdopen(sock->sd, "r");
- if (!sock->instream)
- {
- ndbg("fdopen() failed: %d\n", errno);
- goto errout_with_sd;
- }
+ sock->instream = fdopen(sock->sd, "r");
+ if (!sock->instream)
+ {
+ ndbg("fdopen() failed: %d\n", errno);
+ goto errout_with_sd;
+ }
- /* Create the outgoing stream */
+ /* Create the outgoing stream */
- sock->outstream = fdopen(sock->sd, "w");
- if (!sock->outstream)
+ sock->outstream = fdopen(sock->sd, "w");
+ if (!sock->outstream)
+ {
+ ndbg("fdopen() failed: %d\n", errno);
+ goto errout_with_instream;
+ }
+ }
+ else
{
- ndbg("fdopen() failed: %d\n", errno);
- goto errout_with_instream;
+ /* Should already be set up from ftpc_sockinit() call */
+
+ DEBUGASSERT(sock->sd >= 0 && sock->instream && sock->outstream);
}
return OK;
diff --git a/nuttx/configs/olimex-lpc1766stk/README.txt b/nuttx/configs/olimex-lpc1766stk/README.txt
index d9368d4b7..3ee4383c0 100755
--- a/nuttx/configs/olimex-lpc1766stk/README.txt
+++ b/nuttx/configs/olimex-lpc1766stk/README.txt
@@ -789,9 +789,11 @@ Where <subdir> is one of the following:
From NSH, the startup command sequence is then:
- mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp
- cd /tmp # cd into the /tmp directory
- ftpc xx.xx.xx.xx[:pp] # Start the FTP client
+ nsh> mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp
+ nsh> cd /tmp # cd into the /tmp directory
+ nsh> ftpc xx.xx.xx.xx[:pp] # Start the FTP client
+ nfc> login <name> <password> # Log into the FTP server
+ nfc> help # See a list of FTP commands
where xx.xx.xx.xx is the IP address of the FTP server and pp is an
optional port number (default is the standard FTP port number 21).
diff --git a/nuttx/configs/olimex-lpc1766stk/ftpc/defconfig b/nuttx/configs/olimex-lpc1766stk/ftpc/defconfig
index 53301f165..2ba0a0277 100755
--- a/nuttx/configs/olimex-lpc1766stk/ftpc/defconfig
+++ b/nuttx/configs/olimex-lpc1766stk/ftpc/defconfig
@@ -435,7 +435,8 @@ CONFIG_ARCH_BZERO=n
# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
# descriptors (one for each open)
# CONFIG_NFILE_STREAMS - The maximum number of streams that
-# can be fopen'ed
+# can be fopen'ed or fdopend'ed. This needs to be pretty
+# large for ftpc because it uses two streams per socket.
# CONFIG_NAME_MAX - The maximum size of a file name.
# CONFIG_STDIO_BUFFER_SIZE - Size of the buffer to allocate
# on fopen. (Only if CONFIG_NFILE_STREAMS > 0)
@@ -461,7 +462,7 @@ CONFIG_MAX_TASKS=16
CONFIG_MAX_TASK_ARGS=4
CONFIG_NPTHREAD_KEYS=4
CONFIG_NFILE_DESCRIPTORS=8
-CONFIG_NFILE_STREAMS=8
+CONFIG_NFILE_STREAMS=12
CONFIG_NAME_MAX=32
CONFIG_STDIO_BUFFER_SIZE=256
CONFIG_NUNGET_CHARS=2
diff --git a/nuttx/fs/fs_fdopen.c b/nuttx/fs/fs_fdopen.c
index 329e4dd84..176ba1bf4 100644
--- a/nuttx/fs/fs_fdopen.c
+++ b/nuttx/fs/fs_fdopen.c
@@ -159,12 +159,12 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb)
*/
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
- ret = net_checksd;
+ ret = net_checksd(tcb, fd, oflags);
#else
/* No networking... it is just a bad descriptor */
err = EBADF;
- return ERROR;
+ goto errout;
#endif
}
@@ -244,6 +244,10 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb)
}
}
+ /* No free stream available.. report ENFILE */
+
+ err = ENFILE;
+
#if CONFIG_STDIO_BUFFER_SIZE > 0
errout_with_sem:
#endif