From 3f09faeeeb7c23c496df9e3790fd3425429adddc Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 18 Jul 2009 22:59:44 +0000 Subject: Still fleshing out THTTPD example git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1994 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/examples/thttpd/main.c | 17 ++++ nuttx/fs/fs_fcntl.c | 100 ++++++++++++++++++++++- nuttx/include/net/uip/thttpd.h | 1 - nuttx/include/nuttx/net.h | 6 ++ nuttx/net/Makefile | 3 +- nuttx/net/net_vfcntl.c | 177 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 298 insertions(+), 6 deletions(-) create mode 100644 nuttx/net/net_vfcntl.c (limited to 'nuttx') diff --git a/nuttx/examples/thttpd/main.c b/nuttx/examples/thttpd/main.c index 93596a3a1..1d3d847d2 100644 --- a/nuttx/examples/thttpd/main.c +++ b/nuttx/examples/thttpd/main.c @@ -72,6 +72,23 @@ * Private Data ****************************************************************************/ +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* These values must be provided by the user before the THTTPD task daemon + * is started: + * + * g_thttpdsymtab: A symbol table describing all of the symbols exported + * from the base system. These symbols are used to bind address references + * in CGI programs to NuttX. + * g_nsymbols: The number of symbols in g_thttpdsymtab[]. + */ + +#warning "Not yet initialized" +FAR const struct symtab_s *g_thttpdsymtab; +int g_thttpdnsymbols; + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/nuttx/fs/fs_fcntl.c b/nuttx/fs/fs_fcntl.c index 2ca0923d8..524bd22b0 100644 --- a/nuttx/fs/fs_fcntl.c +++ b/nuttx/fs/fs_fcntl.c @@ -40,20 +40,47 @@ #include #include +#include #include #include +#include +#include +#include + #include "fs_internal.h" /**************************************************************************** - * Global Functions + * Private Functions ****************************************************************************/ -int fcntl(int fildes, int cmd, ...) +#if CONFIG_NFILE_DESCRIPTORS > 0 +static inline int file_vfcntl(int fildes, int cmd, va_list ap) { + FAR struct filelist *list; + FAR struct file *this_file; int err = 0; + int ret = 0; + + /* Get the thread-specific file list */ + + list = sched_getfiles(); + if (!list) + { + err = EMFILE; + goto errout; + } + + /* Was this file opened ? */ -#warning "fcntl() not yet implemented" + this_file = &list->fl_files[fildes]; + if (!this_file->f_inode) + { + err = EBADF; + goto errout; + } + +#warning "Many fcntl() commands not yet implemented" switch (cmd) { case F_DUPFD: @@ -82,6 +109,9 @@ int fcntl(int fildes, int cmd, ...) * successful execution of one of the exec functions. */ + err = ENOSYS; + break; + case F_GETFL: /* Get the file status flags and file access modes, defined in , * for the file description associated with fildes. The file access modes @@ -91,6 +121,11 @@ int fcntl(int fildes, int cmd, ...) * refer to the same file with different open file descriptions. */ + { + ret = this_file->f_oflags; + } + break; + case F_SETFL: /* Set the file status flags, defined in , for the file description * associated with fildes from the corresponding bits in the third argument, @@ -100,6 +135,11 @@ int fcntl(int fildes, int cmd, ...) * by the application, the result is unspecified. */ + { + this_file->f_oflags = va_arg(ap, int); + } + break; + case F_GETOWN: /* If fildes refers to a socket, get the process or process group ID specified * to receive SIGURG signals when out-of-band data is available. Positive values @@ -115,6 +155,9 @@ int fcntl(int fildes, int cmd, ...) * fildes does not refer to a socket, the results are unspecified. */ + err = EBADF; /* Only valid on socket descriptors */ + break; + case F_GETLK: /* Get the first lock which blocks the lock description pointed to by the third * argument, arg, taken as a pointer to type struct flock, defined in . @@ -142,7 +185,7 @@ int fcntl(int fildes, int cmd, ...) * not be done. */ - err = ENOSYS; + err = ENOSYS; /* Not implemented */ break; default: @@ -150,6 +193,7 @@ int fcntl(int fildes, int cmd, ...) break; } +errout: if (err != 0) { errno = err; @@ -157,4 +201,52 @@ int fcntl(int fildes, int cmd, ...) } return OK; } +#endif /* CONFIG_NFILE_DESCRIPTORS > 0 */ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +int fcntl(int fildes, int cmd, ...) +{ + va_list ap; + int ret; + + /* Setup to access the variable argument list */ + + va_start(ap, cmd); + + /* Did we get a valid file descriptor? */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 + if ((unsigned int)fildes < CONFIG_NFILE_DESCRIPTORS) + { + /* Yes.. defer file operations to file_vfcntl() */ + + ret = file_vfcntl(fildes, cmd, ap); + } + else +#endif + { + /* No... check for operations on a socket descriptor */ + +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + if ((unsigned int)fildes < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS)) + { + /* Yes.. defer socket descriptor operations to net_vfcntl() */ + + ret = net_vfcntl(fildes, cmd, ap); + } + else +#endif + { + /* No.. this descriptor number is out of range */ + + ret = EBADF; + } + } + + va_end(ap); + return ret; +} diff --git a/nuttx/include/net/uip/thttpd.h b/nuttx/include/net/uip/thttpd.h index 1df53b333..ba23e0e1d 100644 --- a/nuttx/include/net/uip/thttpd.h +++ b/nuttx/include/net/uip/thttpd.h @@ -71,7 +71,6 @@ extern "C" { EXTERN FAR const struct symtab_s *g_thttpdsymtab; EXTERN int g_thttpdnsymbols; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/nuttx/include/nuttx/net.h b/nuttx/include/nuttx/net.h index 55ff9885e..efe897073 100644 --- a/nuttx/include/nuttx/net.h +++ b/nuttx/include/nuttx/net.h @@ -43,6 +43,7 @@ #include #ifdef CONFIG_NET +#include #include #include @@ -190,6 +191,11 @@ EXTERN int net_dup2(int sockfd1, int sockfd2); EXTERN int net_clone(FAR struct socket *psock1, FAR struct socket *psock2); +/* net_vfcntl.c **************************************************************/ +/* Performs fcntl operations on socket */ + +EXTERN int net_vfcntl(int sockfd, int cmd, va_list ap); + /* netdev-register.c *********************************************************/ /* This function is called by network interface device drivers to inform the * socket layer of their existence. This registration is necesary to support diff --git a/nuttx/net/Makefile b/nuttx/net/Makefile index 8802e01d7..203aa0e53 100644 --- a/nuttx/net/Makefile +++ b/nuttx/net/Makefile @@ -38,7 +38,8 @@ ifeq ($(CONFIG_NET),y) SOCK_ASRCS = SOCK_CSRCS = socket.c bind.c connect.c sendto.c recv.c recvfrom.c \ - net_sockets.c net_close.c net_dup.c net_dup2.c net_clone.c + net_sockets.c net_close.c net_dup.c net_dup2.c net_clone.c \ + net_vfcntl.c ifeq ($(CONFIG_NET_TCP),y) SOCK_CSRCS += send.c listen.c accept.c diff --git a/nuttx/net/net_vfcntl.c b/nuttx/net/net_vfcntl.c new file mode 100644 index 000000000..bf3e37d81 --- /dev/null +++ b/nuttx/net/net_vfcntl.c @@ -0,0 +1,177 @@ +/**************************************************************************** + * net/net_vfcntl.c + * + * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include +#include + +#include +#include "net_internal.h" + +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +int net_vfcntl(int sockfd, int cmd, va_list ap) +{ + FAR struct socket *psock = sockfd_socket(sockfd); + int err = 0; + int ret = 0; + + /* Verify that the sockfd corresponds to valid, allocated socket */ + + if (!psock || psock->s_crefs <= 0) + { + err = EBADF; + goto errout; + } + +#warning "fcntl() commands not yet implemented" + switch (cmd) + { + case F_DUPFD: + /* Return a new file descriptor which shall be the lowest numbered + * available (that is, not already open) file descriptor greater than + * or equal to the third argument, arg, taken as an integer of type + * int. The new file descriptor shall refer to the same open file + * description as the original file descriptor, and shall share any + * locks. The FD_CLOEXEC flag associated with the new file descriptor + * shall be cleared to keep the file open across calls to one of the + * exec functions. + */ + + case F_GETFD: + /* Get the file descriptor flags defined in that are associated + * with the file descriptor fildes. File descriptor flags are associated + * with a single file descriptor and do not affect other file descriptors + * that refer to the same file. + */ + + case F_SETFD: + /* Set the file descriptor flags defined in , that are associated + * with fildes, to the third argument, arg, taken as type int. If the + * FD_CLOEXEC flag in the third argument is 0, the file shall remain open + * across the exec functions; otherwise, the file shall be closed upon + * successful execution of one of the exec functions. + */ + + case F_GETFL: + /* Get the file status flags and file access modes, defined in , + * for the file description associated with fildes. The file access modes + * can be extracted from the return value using the mask O_ACCMODE, which is + * defined in . File status flags and file access modes are associated + * with the file description and do not affect other file descriptors that + * refer to the same file with different open file descriptions. + */ + + case F_SETFL: + /* Set the file status flags, defined in , for the file description + * associated with fildes from the corresponding bits in the third argument, + * arg, taken as type int. Bits corresponding to the file access mode and + * the file creation flags, as defined in , that are set in arg shall + * be ignored. If any bits in arg other than those mentioned here are changed + * by the application, the result is unspecified. + */ + + case F_GETOWN: + /* If fildes refers to a socket, get the process or process group ID specified + * to receive SIGURG signals when out-of-band data is available. Positive values + * indicate a process ID; negative values, other than -1, indicate a process group + * ID. If fildes does not refer to a socket, the results are unspecified. + */ + + case F_SETOWN: + /* If fildes refers to a socket, set the process or process group ID specified + * to receive SIGURG signals when out-of-band data is available, using the value + * of the third argument, arg, taken as type int. Positive values indicate a + * process ID; negative values, other than -1, indicate a process group ID. If + * fildes does not refer to a socket, the results are unspecified. + */ + + case F_GETLK: + /* Get the first lock which blocks the lock description pointed to by the third + * argument, arg, taken as a pointer to type struct flock, defined in . + * The information retrieved shall overwrite the information passed to fcntl() in + * the structure flock. If no lock is found that would prevent this lock from being + * created, then the structure shall be left unchanged except for the lock type + * which shall be set to F_UNLCK. + */ + + case F_SETLK: + /* Set or clear a file segment lock according to the lock description pointed to + * by the third argument, arg, taken as a pointer to type struct flock, defined in + * . F_SETLK can establish shared (or read) locks (F_RDLCK) or exclusive + * (or write) locks (F_WRLCK), as well as to remove either type of lock (F_UNLCK). + * F_RDLCK, F_WRLCK, and F_UNLCK are defined in . If a shared or exclusive + * lock cannot be set, fcntl() shall return immediately with a return value of -1. + */ + + case F_SETLKW: + /* This command shall be equivalent to F_SETLK except that if a shared or exclusive + * lock is blocked by other locks, the thread shall wait until the request can be + * satisfied. If a signal that is to be caught is received while fcntl() is waiting + * for a region, fcntl() shall be interrupted. Upon return from the signal handler, + * fcntl() shall return -1 with errno set to [EINTR], and the lock operation shall + * not be done. + */ + + err = ENOSYS; + break; + + default: + err = EINVAL; + break; + } + +errout: + if (err != 0) + { + errno = err; + return ERROR; + } + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS > 0 */ + -- cgit v1.2.3