A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
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
#include <thread>
26
27
#include "
callback.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)
80
{}
87
Data
(uint8_t *buf, ssize_t len) :
m_buf
(buf),
m_len
(len)
88
{}
90
uint8_t *
m_buf
;
92
ssize_t
m_len
;
93
};
94
108
virtual
FdReader::Data
DoRead
(
void
) = 0;
109
113
int
m_fd
;
114
115
private
:
116
118
void
Run
(
void
);
120
void
DestroyEvent
(
void
);
121
123
Callback<void, uint8_t *, ssize_t>
m_readCallback
;
124
126
std::thread
m_readThread
;
127
129
int
m_evpipe
[2];
131
bool
m_stop
;
132
137
EventId
m_destroyEvent
;
138
};
139
140
}
// namespace ns3
141
142
#endif
/* UNIX_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:54
ns3::FdReader
A class that asynchronously reads from a file descriptor.
Definition:
unix-fd-reader.h:48
ns3::FdReader::m_evpipe
int m_evpipe[2]
Pipe used to signal events between threads.
Definition:
unix-fd-reader.h:129
ns3::FdReader::Stop
void Stop(void)
Stop the read thread and reset internal state.
Definition:
unix-fd-reader.cc:120
ns3::FdReader::FdReader
FdReader()
Constructor.
Definition:
unix-fd-reader.cc:47
ns3::FdReader::m_stop
bool m_stop
Signal the read thread to stop.
Definition:
unix-fd-reader.h:131
ns3::FdReader::DoRead
virtual FdReader::Data DoRead(void)=0
The read implementation.
ns3::FdReader::DestroyEvent
void DestroyEvent(void)
Event handler scheduled for destroy time to halt the thread.
Definition:
unix-fd-reader.cc:113
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:137
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::Run
void Run(void)
The asynchronous function which performs the read.
Definition:
unix-fd-reader.cc:163
ns3::FdReader::m_readThread
std::thread m_readThread
The thread doing the read, created and launched by Start().
Definition:
unix-fd-reader.h:126
ns3::FdReader::m_fd
int m_fd
The file descriptor to read from.
Definition:
unix-fd-reader.h:113
ns3::FdReader::~FdReader
virtual ~FdReader()
Destructor.
Definition:
unix-fd-reader.cc:56
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:123
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:73
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:
unix-fd-reader.h:77
ns3::FdReader::Data::m_len
ssize_t m_len
The size of the read data buffer, in bytes.
Definition:
unix-fd-reader.h:92
ns3::FdReader::Data::Data
Data(uint8_t *buf, ssize_t len)
Construct from a buffer of a given length.
Definition:
unix-fd-reader.h:87
ns3::FdReader::Data::Data
Data()
Default constructor, with null buffer and zero length.
Definition:
unix-fd-reader.h:79
ns3::FdReader::Data::m_buf
uint8_t * m_buf
The read data buffer.
Definition:
unix-fd-reader.h:90
src
core
model
unix-fd-reader.h
Generated on Tue Feb 6 2024 19:21:17 for ns-3 by
1.9.1