Still fleshing out THTTPD example

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1994 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2009-07-18 22:59:44 +00:00
parent 8c7634d4a2
commit e68c54fea0
6 changed files with 298 additions and 6 deletions
+96 -4
View File
@@ -40,20 +40,47 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdarg.h>
#include <fcntl.h>
#include <errno.h>
#include <nuttx/fs.h>
#include <nuttx/net.h>
#include <nuttx/sched.h>
#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;
#warning "fcntl() not yet implemented"
/* Get the thread-specific file list */
list = sched_getfiles();
if (!list)
{
err = EMFILE;
goto errout;
}
/* Was this file opened ? */
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 <fcntl.h>,
* 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 <fcntl.h>, 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 <fcntl.h>.
@@ -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;
}