A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
fd-reader.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 The Boeing Company
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Tom Goff <thomas.goff@boeing.com>
18
*/
19
20
#ifndef FD_READER_H
21
#define FD_READER_H
22
23
#include "
callback.h
"
24
#include "
event-id.h
"
25
26
#include <cstdint>
27
#include <thread>
28
29
#ifdef __WIN32__
30
#include <BaseTsd.h>
31
35
typedef
SSIZE_T ssize_t;
36
#endif
37
44
namespace
ns3
45
{
46
56
class
FdReader
:
public
SimpleRefCount
<FdReader>
57
{
58
public
:
60
FdReader
();
62
virtual
~FdReader
();
63
72
void
Start
(
int
fd,
Callback<void, uint8_t*, ssize_t>
readCallback);
73
78
void
Stop
();
79
80
#ifdef __WIN32__
84
static
bool
winsock_initialized;
85
#endif
86
protected
:
90
struct
Data
91
{
93
Data
()
94
:
m_buf
(nullptr),
95
m_len
(0)
96
{
97
}
98
105
Data
(uint8_t* buf, ssize_t len)
106
:
m_buf
(buf),
107
m_len
(len)
108
{
109
}
110
112
uint8_t*
m_buf
;
114
ssize_t
m_len
;
115
};
116
130
virtual
FdReader::Data
DoRead
() = 0;
131
135
int
m_fd
;
136
137
private
:
139
void
Run
();
141
void
DestroyEvent
();
142
144
Callback<void, uint8_t*, ssize_t>
m_readCallback
;
145
147
std::thread
m_readThread
;
148
150
int
m_evpipe
[2];
152
bool
m_stop
;
153
158
EventId
m_destroyEvent
;
159
};
160
161
}
// namespace ns3
162
163
#endif
/* FD_READER_H */
callback.h
Declaration of the various callback functions.
ns3::Callback< void, uint8_t *, ssize_t >
ns3::EventId
An identifier for simulation events.
Definition:
event-id.h:55
ns3::FdReader
A class that asynchronously reads from a file descriptor.
Definition:
fd-reader.h:57
ns3::FdReader::m_evpipe
int m_evpipe[2]
Pipe used to signal events between threads.
Definition:
fd-reader.h:150
ns3::FdReader::FdReader
FdReader()
Constructor.
Definition:
unix-fd-reader.cc:45
ns3::FdReader::Run
void Run()
The asynchronous function which performs the read.
Definition:
unix-fd-reader.cc:165
ns3::FdReader::Stop
void Stop()
Stop the read thread and reset internal state.
Definition:
unix-fd-reader.cc:121
ns3::FdReader::m_stop
bool m_stop
Signal the read thread to stop.
Definition:
fd-reader.h:152
ns3::FdReader::m_destroyEvent
EventId m_destroyEvent
The event scheduled for destroy time which will invoke DestroyEvent and halt the thread.
Definition:
fd-reader.h:158
ns3::FdReader::DoRead
virtual FdReader::Data DoRead()=0
The read implementation.
ns3::FdReader::Start
void Start(int fd, Callback< void, uint8_t *, ssize_t > readCallback)
Start a new read thread.
Definition:
unix-fd-reader.cc:62
ns3::FdReader::DestroyEvent
void DestroyEvent()
Event handler scheduled for destroy time to halt the thread.
Definition:
unix-fd-reader.cc:113
ns3::FdReader::m_readCallback
Callback< void, uint8_t *, ssize_t > m_readCallback
The main thread callback function to invoke when we have data.
Definition:
fd-reader.h:144
ns3::FdReader::m_readThread
std::thread m_readThread
The thread doing the read, created and launched by Start().
Definition:
fd-reader.h:147
ns3::FdReader::m_fd
int m_fd
The file descriptor to read from.
Definition:
fd-reader.h:135
ns3::FdReader::~FdReader
virtual ~FdReader()
Destructor.
Definition:
unix-fd-reader.cc:55
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:81
event-id.h
ns3::EventId declarations.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::FdReader::Data
A structure representing data read.
Definition:
fd-reader.h:91
ns3::FdReader::Data::m_len
ssize_t m_len
The size of the read data buffer, in bytes.
Definition:
fd-reader.h:114
ns3::FdReader::Data::Data
Data(uint8_t *buf, ssize_t len)
Construct from a buffer of a given length.
Definition:
fd-reader.h:105
ns3::FdReader::Data::Data
Data()
Default constructor, with null buffer and zero length.
Definition:
fd-reader.h:93
ns3::FdReader::Data::m_buf
uint8_t * m_buf
The read data buffer.
Definition:
fd-reader.h:112
src
core
model
fd-reader.h
Generated on Sun Mar 3 2024 17:10:55 for ns-3 by
1.9.1