A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
ns3tcp-socket-writer.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 University of Washington
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*/
6
7
#include "
ns3tcp-socket-writer.h
"
8
9
#include "ns3/packet.h"
10
#include "ns3/tcp-socket-factory.h"
11
12
namespace
ns3
13
{
14
15
SocketWriter::SocketWriter
()
16
: m_node(nullptr),
17
m_socket(nullptr),
18
m_isSetup(false),
19
m_isConnected(false)
20
{
21
}
22
23
SocketWriter::~SocketWriter
()
24
{
25
m_socket
=
nullptr
;
26
m_node
=
nullptr
;
27
}
28
29
/* static */
30
TypeId
31
SocketWriter::GetTypeId
()
32
{
33
static
TypeId
tid =
TypeId
(
"ns3::SocketWriter"
)
34
.
SetParent
<
Application
>()
35
.SetGroupName(
"Stats"
)
36
.AddConstructor<
SocketWriter
>();
37
return
tid;
38
}
39
40
void
41
SocketWriter::StartApplication
()
42
{
43
m_socket
=
Socket::CreateSocket
(
m_node
,
TcpSocketFactory::GetTypeId
());
44
m_socket
->
Bind
();
45
}
46
47
void
48
SocketWriter::StopApplication
()
49
{
50
}
51
52
void
53
SocketWriter::Setup
(
Ptr<Node>
node,
Address
peer)
54
{
55
m_peer
= peer;
56
m_node
= node;
57
m_isSetup
=
true
;
58
}
59
60
void
61
SocketWriter::Connect
()
62
{
63
if
(!
m_isSetup
)
64
{
65
NS_FATAL_ERROR
(
"Forgot to call Setup() first"
);
66
}
67
m_socket
->
Connect
(
m_peer
);
68
m_isConnected
=
true
;
69
}
70
71
void
72
SocketWriter::Write
(
uint32_t
numBytes)
73
{
74
if
(!
m_isConnected
)
75
{
76
Connect
();
77
}
78
Ptr<Packet>
packet =
Create<Packet>
(numBytes);
79
m_socket
->
Send
(packet);
80
}
81
82
void
83
SocketWriter::Close
()
84
{
85
m_socket
->
Close
();
86
}
87
}
// namespace ns3
ns3::Address
a polymophic address class
Definition
address.h:90
ns3::Application
The base class for all ns3 applications.
Definition
application.h:51
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Socket::Send
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
ns3::Socket::Connect
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
ns3::Socket::CreateSocket
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition
socket.cc:61
ns3::Socket::Close
virtual int Close()=0
Close a socket.
ns3::Socket::Bind
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
ns3::SocketWriter
Simple class to write data to sockets.
Definition
ns3tcp-socket-writer.h:22
ns3::SocketWriter::m_peer
Address m_peer
Peer's address.
Definition
ns3tcp-socket-writer.h:55
ns3::SocketWriter::SocketWriter
SocketWriter()
Definition
ns3tcp-socket-writer.cc:15
ns3::SocketWriter::~SocketWriter
~SocketWriter() override
Definition
ns3tcp-socket-writer.cc:23
ns3::SocketWriter::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition
ns3tcp-socket-writer.cc:31
ns3::SocketWriter::Connect
void Connect()
Connect the socket.
Definition
ns3tcp-socket-writer.cc:61
ns3::SocketWriter::Setup
void Setup(Ptr< Node > node, Address peer)
Setup the socket.
Definition
ns3tcp-socket-writer.cc:53
ns3::SocketWriter::Write
void Write(uint32_t numBytes)
Write to the socket.
Definition
ns3tcp-socket-writer.cc:72
ns3::SocketWriter::m_node
Ptr< Node > m_node
Node pointer.
Definition
ns3tcp-socket-writer.h:56
ns3::SocketWriter::Close
void Close()
Close the socket.
Definition
ns3tcp-socket-writer.cc:83
ns3::SocketWriter::m_isSetup
bool m_isSetup
True if the socket is connected.
Definition
ns3tcp-socket-writer.h:58
ns3::SocketWriter::StopApplication
void StopApplication() override
Application specific shutdown code.
Definition
ns3tcp-socket-writer.cc:48
ns3::SocketWriter::m_socket
Ptr< Socket > m_socket
Socket.
Definition
ns3tcp-socket-writer.h:57
ns3::SocketWriter::m_isConnected
bool m_isConnected
True if the socket setup has been done.
Definition
ns3tcp-socket-writer.h:59
ns3::SocketWriter::StartApplication
void StartApplication() override
Application specific startup code.
Definition
ns3tcp-socket-writer.cc:41
ns3::TcpSocketFactory::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
tcp-socket-factory.cc:19
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
uint32_t
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition
fatal-error.h:168
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3tcp-socket-writer.h
src
test
ns3tcp
ns3tcp-socket-writer.cc
Generated on Fri Nov 8 2024 13:59:06 for ns-3 by
1.11.0