A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
core
model
unix-fd-reader.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 The Boeing Company
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Tom Goff <thomas.goff@boeing.com>
19
*/
20
21
#ifndef UNIX_FD_READER_H
22
#define UNIX_FD_READER_H
23
24
#include <stdint.h>
25
26
#include "
callback.h
"
27
#include "
system-thread.h
"
28
#include "
event-id.h
"
29
36
namespace
ns3
{
37
47
class
FdReader
:
public
SimpleRefCount
<FdReader>
48
{
49
public
:
51
FdReader
();
53
virtual
~FdReader
();
54
63
void
Start
(
int
fd,
Callback<void, uint8_t *, ssize_t>
readCallback);
64
69
void
Stop
(
void
);
70
71
protected
:
72
76
struct
Data
77
{
79
Data
() :
m_buf
(0),
m_len
(0) {}
86
Data
(uint8_t *buf, ssize_t len) :
m_buf
(buf),
m_len
(len) {}
88
uint8_t *
m_buf
;
90
ssize_t
m_len
;
91
};
92
106
virtual
FdReader::Data
DoRead
(
void
) = 0;
107
111
int
m_fd
;
112
113
private
:
114
116
void
Run
(
void
);
118
void
DestroyEvent
(
void
);
119
121
Callback<void, uint8_t *, ssize_t>
m_readCallback
;
122
124
Ptr<SystemThread>
m_readThread
;
125
127
int
m_evpipe
[2];
129
bool
m_stop
;
130
135
EventId
m_destroyEvent
;
136
};
137
138
}
// namespace ns3
139
140
#endif
/* UNIX_FD_READER_H */
ns3::FdReader::Start
void Start(int fd, Callback< void, uint8_t *, ssize_t > readCallback)
Start a new read thread.
Definition:
unix-fd-reader.cc:60
ns3::FdReader::DestroyEvent
void DestroyEvent(void)
Event handler scheduled for destroy time to halt the thread.
Definition:
unix-fd-reader.cc:112
ns3::FdReader::Data
A structure representing data read.
Definition:
unix-fd-reader.h:76
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:73
ns3::Callback< void, uint8_t *, ssize_t >
ns3::FdReader::~FdReader
virtual ~FdReader()
Destructor.
Definition:
unix-fd-reader.cc:54
system-thread.h
System-independent thread class ns3::SystemThread declaration.
ns3::FdReader::m_readCallback
Callback< void, uint8_t *, ssize_t > m_readCallback
The main thread callback function to invoke when we have data.
Definition:
unix-fd-reader.h:121
ns3::FdReader::m_stop
bool m_stop
Signal the read thread to stop.
Definition:
unix-fd-reader.h:129
ns3::FdReader::Run
void Run(void)
The asynchronous function which performs the read.
Definition:
unix-fd-reader.cc:161
ns3::FdReader
A class that asynchronously reads from a file descriptor.
Definition:
unix-fd-reader.h:47
callback.h
Declaration of the various callback functions.
ns3::FdReader::Stop
void Stop(void)
Stop the read thread and reset internal state.
Definition:
unix-fd-reader.cc:119
ns3::FdReader::m_readThread
Ptr< SystemThread > m_readThread
The thread doing the read, created and launched by Start().
Definition:
unix-fd-reader.h:124
ns3::FdReader::m_fd
int m_fd
The file descriptor to read from.
Definition:
unix-fd-reader.h:111
ns3::FdReader::FdReader
FdReader()
Constructor.
Definition:
unix-fd-reader.cc:45
ns3::FdReader::Data::m_buf
uint8_t * m_buf
The read data buffer.
Definition:
unix-fd-reader.h:88
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::FdReader::m_destroyEvent
EventId m_destroyEvent
The event scheduled for destroy time which will invoke DestroyEvent and halt the thread.
Definition:
unix-fd-reader.h:135
ns3::FdReader::Data::Data
Data(uint8_t *buf, ssize_t len)
Construct from a buffer of a given length.
Definition:
unix-fd-reader.h:86
ns3::FdReader::Data::Data
Data()
Default constructor, with null buffer and zero length.
Definition:
unix-fd-reader.h:79
ns3::EventId
An identifier for simulation events.
Definition:
event-id.h:53
ns3::FdReader::DoRead
virtual FdReader::Data DoRead(void)=0
The read implementation.
ns3::FdReader::m_evpipe
int m_evpipe[2]
Pipe used to signal events between threads.
Definition:
unix-fd-reader.h:127
event-id.h
ns3::EventId declarations.
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:73
ns3::FdReader::Data::m_len
ssize_t m_len
The size of the read data buffer, in bytes.
Definition:
unix-fd-reader.h:90
Generated on Wed Nov 7 2018 10:01:50 for ns-3 by
1.8.14