This file is indexed.

/usr/include/ns3.26/ns3/unix-fd-reader.h is in libns3-dev 3.26+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2010 The Boeing Company
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Tom Goff <thomas.goff@boeing.com>
 */

#ifndef UNIX_FD_READER_H
#define UNIX_FD_READER_H

#include <stdint.h>

#include "callback.h"
#include "system-thread.h"
#include "event-id.h"

/**
 * \file
 * \ingroup system
 * ns3::FdReader declaration.
 */

namespace ns3 {

/**
 * \ingroup system
 * \brief A class that asynchronously reads from a file descriptor.
 *
 * This class can be used to start a system thread that reads from a
 * given file descriptor and invokes a given callback when data is
 * received.  This class handles thread management automatically but
 * the \p DoRead() method must be implemented by a subclass.
 */
class FdReader : public SimpleRefCount<FdReader>
{
public:
  /** Constructor. */
  FdReader();
  /** Destructor. */
  virtual ~FdReader();

  /**
   * Start a new read thread.
   *
   * \param [in] fd A valid file descriptor open for reading.
   *
   * \param [in] readCallback A callback to invoke when new data is
   * available.
   */
  void Start (int fd, Callback<void, uint8_t *, ssize_t> readCallback);

  /**
   * Stop the read thread and reset internal state.  This does not
   * close the file descriptor used for reading.
   */
  void Stop (void);

protected:

  /**
   * \brief A structure representing data read.
   */
  struct Data
  {
    /** Default constructor, with null buffer and zero length. */
    Data () : m_buf (0), m_len (0) {}
    /**
     * Construct from a buffer of a given length.
     *
     * \param [in] buf The buffer.
     * \param [in] len The size of the buffer, in bytes.
     */
    Data (uint8_t *buf, ssize_t len) : m_buf (buf), m_len (len) {}
    /** The read data buffer. */
    uint8_t *m_buf;
    /** The size of the read data buffer, in bytes. */
    ssize_t m_len;
  };

  /**
   * \brief The read implementation.
   *
   * The value of \p m_len returned controls further processing.  The
   * callback function is only invoked when \p m_len is positive; any
   * data read is not processed when \p m_len is negative; reading
   * stops when \p m_len is zero.
   *
   * The management of memory associated with \p m_buf must be
   * compatible with the read callback.
   *
   * \return A structure representing what was read.
   */
  virtual FdReader::Data DoRead (void) = 0;

  /**
   * \brief The file descriptor to read from.
   */
  int m_fd;

private:

  /** The asynchronous function which performs the read. */
  void Run (void);
  /** Event handler scheduled for destroy time to halt the thread. */
  void DestroyEvent (void);

  /** The main thread callback function to invoke when we have data. */
  Callback<void, uint8_t *, ssize_t> m_readCallback;
  
  /** The thread doing the read, created and launched by Start(). */
  Ptr<SystemThread> m_readThread;

  /** Pipe used to signal events between threads. */
  int m_evpipe[2];
  /** Signal the read thread to stop. */
  bool m_stop;
  
  /**
   * The event scheduled for destroy time which will invoke DestroyEvent
   * and halt the thread.
   */
  EventId m_destroyEvent;
};

} // namespace ns3

#endif /* UNIX_FD_READER_H */