From af0200363e8d0a69648bd78fd5ee2d0ee5f40624 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 19 Mar 1999 21:51:58 +0000 Subject: Patch from Eric Norum that adds external fcntl support and an external fcntl handler for sockets. --- c/src/libnetworking/rtems/rtems_syscall.c | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'c/src/libnetworking/rtems') diff --git a/c/src/libnetworking/rtems/rtems_syscall.c b/c/src/libnetworking/rtems/rtems_syscall.c index 141b7ceeba..7797e46a2a 100644 --- a/c/src/libnetworking/rtems/rtems_syscall.c +++ b/c/src/libnetworking/rtems/rtems_syscall.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -644,14 +645,18 @@ rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count) } static int -so_ioctl (struct socket *so, unsigned32 command, void *buffer) +so_ioctl (rtems_libio_t *iop, struct socket *so, unsigned32 command, void *buffer) { switch (command) { case FIONBIO: - if (*(int *)buffer) + if (*(int *)buffer) { + iop->flags |= O_NONBLOCK; so->so_state |= SS_NBIO; - else + } + else { + iop->flags &= ~O_NONBLOCK; so->so_state &= ~SS_NBIO; + } return 0; case FIONREAD: @@ -678,7 +683,7 @@ rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer) rtems_bsdnet_semaphore_release (); return -1; } - error = so_ioctl (so, command, buffer); + error = so_ioctl (iop, so, command, buffer); rtems_bsdnet_semaphore_release (); if (error) { errno = error; @@ -687,6 +692,26 @@ rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer) return 0; } +static int +rtems_bsdnet_fcntl (int cmd, rtems_libio_t *iop) +{ + struct socket *so; + + if (cmd == F_SETFL) { + rtems_bsdnet_semaphore_obtain (); + if ((so = iop->data1) == NULL) { + rtems_bsdnet_semaphore_release (); + return EBADF; + } + if (iop->flags & O_NONBLOCK) + so->so_state |= SS_NBIO; + else + so->so_state &= ~SS_NBIO; + rtems_bsdnet_semaphore_release (); + } + return 0; +} + static int rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp) { @@ -707,4 +732,5 @@ static const rtems_filesystem_file_handlers_r socket_handlers = { NULL, /* fpathconf */ NULL, /* fsync */ NULL, /* fdatasync */ + rtems_bsdnet_fcntl, /* fcntl */ }; -- cgit v1.2.3