source: rtems/cpukit/libcsupport/src/libio_sockets.c @ a7202f6

4.115
Last change on this file since a7202f6 was a7202f6, checked in by Joel Sherrill <joel.sherrill@…>, on 07/14/10 at 15:01:00

2010-07-14 Joel Sherrill <joel.sherrill@…>

PR 1612/networking

  • ChangeLog?, libcsupport/src/libio_sockets.c: Sockets need to have handlers in place. Null is no longer allowed.
  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2 *  This file contains the support infrastructure used to manage the
3 *  table of integer style file descriptors used by the socket calls.
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/libio_.h>             /* libio_.h pulls in rtems */
20#include <rtems.h>
21
22#include <errno.h>
23#include <rtems/seterr.h>
24
25/*
26 * Convert an RTEMS file descriptor to a BSD socket pointer.
27 */
28
29struct socket *rtems_bsdnet_fdToSocket(
30  int fd
31)
32{
33  rtems_libio_t *iop;
34
35  /* same as rtems_libio_check_fd(_fd) but different return */
36  if ((uint32_t)fd >= rtems_libio_number_iops) {
37    errno = EBADF;
38    return NULL;
39  }
40  iop = &rtems_libio_iops[fd];
41
42  /* same as rtems_libio_check_is_open(iop) but different return */
43  if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) {
44    errno = EBADF;
45    return NULL;
46  }
47
48  if (iop->data1 == NULL)
49    errno = EBADF;
50  return iop->data1;
51}
52
53/*
54 * Create an RTEMS file descriptor for a socket
55 */
56
57int rtems_bsdnet_makeFdForSocket(
58  void *so,
59  const rtems_filesystem_file_handlers_r *h
60)
61{
62  rtems_libio_t *iop;
63  int fd;
64
65  iop = rtems_libio_allocate();
66  if (iop == 0)
67      rtems_set_errno_and_return_minus_one( ENFILE );
68
69  fd = iop - rtems_libio_iops;
70  iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
71  iop->data0 = fd;
72  iop->data1 = so;
73  iop->handlers = h;
74  iop->pathinfo.handlers = rtems_filesystem_root.handlers;
75  iop->pathinfo.ops = rtems_filesystem_root.ops;
76  return fd;
77}
Note: See TracBrowser for help on using the repository browser.