src/node/socket.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 03 Jun 2008 16:20:17 -0700
changeset 3208 1a754d09c4ba
parent 3167 644a220ad981
child 3213 08a0424399fb
permissions -rw-r--r--
bug 200: Packet::PrintTags is not implemented.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
     2
/*
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
     3
 * Copyright (c) 2006 Georgia Tech Research Corporation
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
     4
 *               2007 INRIA
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
     5
 *
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
     8
 * published by the Free Software Foundation;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
     9
 *
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    13
 * GNU General Public License for more details.
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    14
 *
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    15
 * You should have received a copy of the GNU General Public License
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    16
 * along with this program; if not, write to the Free Software
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    18
 *
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    19
 * Authors: George F. Riley<riley@ece.gatech.edu>
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    20
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    21
 */
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    22
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
    23
#include "ns3/log.h"
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    24
#include "ns3/packet.h"
3116
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    25
#include "node.h"
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include "socket.h"
3116
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    27
#include "socket-factory.h"
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    28
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
    29
NS_LOG_COMPONENT_DEFINE ("Socket");
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
namespace ns3 {
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
3107
ec3ed34b2470 API for SocketOptions class
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
    33
Socket::Socket (void)
ec3ed34b2470 API for SocketOptions class
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
    34
{
ec3ed34b2470 API for SocketOptions class
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
    35
  NS_LOG_FUNCTION_NOARGS ();
ec3ed34b2470 API for SocketOptions class
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
    36
}
ec3ed34b2470 API for SocketOptions class
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
    37
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
Socket::~Socket ()
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    39
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
    40
  NS_LOG_FUNCTION_NOARGS ();
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    41
}
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
3116
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    43
Ptr<Socket> 
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    44
Socket::CreateSocket (Ptr<Node> node, TypeId tid)
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    45
{
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    46
  Ptr<Socket> s;
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    47
  Ptr<SocketFactory> socketFactory = node->GetObject<SocketFactory> (tid);
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    48
  s = socketFactory->CreateSocket ();
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    49
  NS_ASSERT (s != 0);
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    50
  return s;
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    51
}
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    52
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    53
void 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    54
Socket::SetCloseCallback (Callback<void,Ptr<Socket> > closeCompleted)
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    55
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
    56
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    57
  m_closeCompleted = closeCompleted;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    58
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    59
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    60
void 
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    61
Socket::SetConnectCallback (
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    62
  Callback<void, Ptr<Socket> > connectionSucceeded,
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    63
  Callback<void, Ptr<Socket> > connectionFailed,
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    64
  Callback<void, Ptr<Socket> > halfClose)
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
    66
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    67
  m_connectionSucceeded = connectionSucceeded;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    68
  m_connectionFailed = connectionFailed;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    69
  m_halfClose = halfClose;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    70
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    71
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    72
void 
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    73
Socket::SetAcceptCallback (
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    74
  Callback<bool, Ptr<Socket>, const Address &> connectionRequest,
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    75
  Callback<void, Ptr<Socket>, const Address&> newConnectionCreated,
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    76
  Callback<void, Ptr<Socket> > closeRequested)
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    77
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
    78
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    79
  m_connectionRequest = connectionRequest;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    80
  m_newConnectionCreated = newConnectionCreated;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    81
  m_closeRequested = closeRequested;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    82
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    83
2999
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    84
bool 
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    85
Socket::SetDataSentCallback (Callback<void, Ptr<Socket>, uint32_t> dataSent)
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    86
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
    87
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    88
  m_dataSent = dataSent;
2999
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    89
  return true;
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    90
}
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    91
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    92
void
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    93
Socket::SetSendCallback (Callback<void, Ptr<Socket>, uint32_t> sendCb)
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    94
{
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    95
  NS_LOG_FUNCTION_NOARGS ();
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    96
  m_sendCb = sendCb;
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    97
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
    98
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    99
void 
3102
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   100
Socket::SetRecvCallback (Callback<void, Ptr<Socket> > receivedData)
3097
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   101
{
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   102
  NS_LOG_FUNCTION_NOARGS ();
3102
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   103
  m_receivedData = receivedData;
3097
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   104
}
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   105
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   106
int Socket::Listen (uint32_t queueLimit)
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   107
{
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   108
  return 0; //XXX the base class version does nothing
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   109
}
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   110
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   111
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   112
int Socket::Send (const uint8_t* buf, uint32_t size)
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   113
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   114
  NS_LOG_FUNCTION_NOARGS ();
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   115
  Ptr<Packet> p;
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   116
  if (buf)
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   117
    {
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   118
      p = Create<Packet> (buf, size);
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   119
    }
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   120
  else
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   121
    {
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   122
      p = Create<Packet> (size);
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   123
    }
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   124
  return Send (p);
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   125
}
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   126
3103
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   127
Ptr<Packet>
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   128
Socket::Recv (void)
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   129
{
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   130
  return Recv (std::numeric_limits<uint32_t>::max(), 0);
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   131
}
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   132
3142
1842b2f747f7 Receive raw buffer variant
Tom Henderson <tomh@tomh.org>
parents: 3139
diff changeset
   133
int 
1842b2f747f7 Receive raw buffer variant
Tom Henderson <tomh@tomh.org>
parents: 3139
diff changeset
   134
Socket::Recv (uint8_t* buf, uint32_t size, uint32_t flags)
1842b2f747f7 Receive raw buffer variant
Tom Henderson <tomh@tomh.org>
parents: 3139
diff changeset
   135
{
1842b2f747f7 Receive raw buffer variant
Tom Henderson <tomh@tomh.org>
parents: 3139
diff changeset
   136
  Ptr<Packet> p = Recv (size, flags); // read up to "size" bytes
1842b2f747f7 Receive raw buffer variant
Tom Henderson <tomh@tomh.org>
parents: 3139
diff changeset
   137
  memcpy (buf, p->PeekData (), p->GetSize());
1842b2f747f7 Receive raw buffer variant
Tom Henderson <tomh@tomh.org>
parents: 3139
diff changeset
   138
  return p->GetSize ();
1842b2f747f7 Receive raw buffer variant
Tom Henderson <tomh@tomh.org>
parents: 3139
diff changeset
   139
}
1842b2f747f7 Receive raw buffer variant
Tom Henderson <tomh@tomh.org>
parents: 3139
diff changeset
   140
3120
774b2637845e swap SendTo parameters
Tom Henderson <tomh@tomh.org>
parents: 3117
diff changeset
   141
int Socket::SendTo (const uint8_t* buf, uint32_t size, const Address &address)
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   142
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   143
  NS_LOG_FUNCTION_NOARGS ();
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   144
  Ptr<Packet> p;
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   145
  if(buf)
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   146
    {
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   147
      p = Create<Packet> (buf, size);
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   148
    }
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   149
  else
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   150
    {
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   151
      p = Create<Packet> (size);
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   152
    }
3120
774b2637845e swap SendTo parameters
Tom Henderson <tomh@tomh.org>
parents: 3117
diff changeset
   153
  return SendTo (p, address);
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   154
}
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   155
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   156
void 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   157
Socket::NotifyCloseCompleted (void)
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   159
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   160
  if (!m_closeCompleted.IsNull ())
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   161
    {
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   162
      m_closeCompleted (this);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   163
    }
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
   165
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   166
void 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   167
Socket::NotifyConnectionSucceeded (void)
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   169
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   170
  if (!m_connectionSucceeded.IsNull ())
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   171
    {
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   172
      m_connectionSucceeded (this);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   173
    }
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
   175
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   176
void 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   177
Socket::NotifyConnectionFailed (void)
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   179
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   180
  if (!m_connectionFailed.IsNull ())
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   181
    {
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   182
      m_connectionFailed (this);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   183
    }
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
   185
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
void 
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   187
Socket::NotifyHalfClose (void)
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   188
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   189
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   190
  if (!m_halfClose.IsNull ())
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   191
    {
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   192
      m_halfClose (this);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   193
    }
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   194
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
   195
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   196
bool 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   197
Socket::NotifyConnectionRequest (const Address &from)
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   198
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   199
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   200
  if (!m_connectionRequest.IsNull ())
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   201
    {
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   202
      return m_connectionRequest (this, from);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   203
    }
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   204
  else
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   205
    {
2367
904e5739f955 Undo changes to the packet sink to accept incoming connections; change the default behavior of the socket connection request notifier instead
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2224
diff changeset
   206
      // accept all incoming connections by default.
904e5739f955 Undo changes to the packet sink to accept incoming connections; change the default behavior of the socket connection request notifier instead
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2224
diff changeset
   207
      // this way people writing code don't have to do anything
904e5739f955 Undo changes to the packet sink to accept incoming connections; change the default behavior of the socket connection request notifier instead
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2224
diff changeset
   208
      // special like register a callback that returns true
904e5739f955 Undo changes to the packet sink to accept incoming connections; change the default behavior of the socket connection request notifier instead
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2224
diff changeset
   209
      // just to get incoming connections
904e5739f955 Undo changes to the packet sink to accept incoming connections; change the default behavior of the socket connection request notifier instead
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2224
diff changeset
   210
      return true;
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   211
    }
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
   213
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
void 
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   215
Socket::NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from)
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   216
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   217
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   218
  if (!m_newConnectionCreated.IsNull ())
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   219
    {
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   220
      m_newConnectionCreated (socket, from);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   221
    }
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   222
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
   223
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   224
void 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   225
Socket::NotifyCloseRequested (void)
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   227
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   228
  if (!m_closeRequested.IsNull ())
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   229
    {
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   230
      m_closeRequested (this);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   231
    }
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   232
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
   233
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   234
void 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   235
Socket::NotifyDataSent (uint32_t size)
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   236
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2367
diff changeset
   237
  NS_LOG_FUNCTION_NOARGS ();
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   238
  if (!m_dataSent.IsNull ())
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   239
    {
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   240
      m_dataSent (this, size);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   241
    }
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   242
}
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1265
diff changeset
   243
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   244
void 
2999
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   245
Socket::NotifySend (uint32_t spaceAvailable)
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   246
{
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   247
  NS_LOG_FUNCTION_NOARGS ();
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   248
  if (!m_sendCb.IsNull ())
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   249
    {
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   250
      m_sendCb (this, spaceAvailable);
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   251
    }
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   252
}
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   253
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   254
void 
3097
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   255
Socket::NotifyDataRecv (void)
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   256
{
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   257
  NS_LOG_FUNCTION_NOARGS ();
3102
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   258
  if (!m_receivedData.IsNull ())
3097
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   259
    {
3102
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   260
      m_receivedData (this);
3097
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   261
    }
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   262
}
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   263
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   264
/***************************************************************
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   265
 *           Socket Tags
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   266
 ***************************************************************/
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   267
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   268
SocketRxAddressTag::SocketRxAddressTag ()  
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   269
{
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   270
}
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   271
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   272
void 
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   273
SocketRxAddressTag::SetAddress (Address addr)
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   274
{
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   275
  m_address = addr;
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   276
}
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   277
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   278
Address 
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   279
SocketRxAddressTag::GetAddress (void) const
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   280
{
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   281
  return m_address;
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   282
}
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   283
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   284
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   285
TypeId
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   286
SocketRxAddressTag::GetTypeId (void)
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   287
{
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   288
  static TypeId tid = TypeId ("ns3::SocketRxAddressTag")
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   289
    .SetParent<Tag> ()
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   290
    .AddConstructor<SocketRxAddressTag> ()
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   291
    ;
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   292
  return tid;
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   293
}
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   294
TypeId
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   295
SocketRxAddressTag::GetInstanceTypeId (void) const
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   296
{
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   297
  return GetTypeId ();
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   298
}
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   299
uint32_t
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   300
SocketRxAddressTag::GetSerializedSize (void) const
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   301
{
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   302
  return m_address.GetSerializedSize ();
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   303
}
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   304
void
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   305
SocketRxAddressTag::Serialize (TagBuffer i) const
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   306
{
3167
644a220ad981 Fix off-by-2 errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3142
diff changeset
   307
  m_address.Serialize (i);
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   308
}
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   309
void
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   310
SocketRxAddressTag::Deserialize (TagBuffer i)
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   311
{
3167
644a220ad981 Fix off-by-2 errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3142
diff changeset
   312
  m_address.Deserialize (i);
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   313
}
3208
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   314
void
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   315
SocketRxAddressTag::Print (std::ostream &os) const
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   316
{
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   317
  os << "address=" << m_address;
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   318
}
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   319
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   320
SocketIpTtlTag::SocketIpTtlTag ()  
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   321
{
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   322
}
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   323
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   324
void 
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   325
SocketIpTtlTag::SetTtl (uint8_t ttl)
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   326
{
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   327
  m_ttl = ttl;
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   328
}
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   329
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   330
uint8_t 
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   331
SocketIpTtlTag::GetTtl (void) const
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   332
{
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   333
  return m_ttl;
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   334
}
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   335
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   336
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   337
TypeId
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   338
SocketIpTtlTag::GetTypeId (void)
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   339
{
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   340
  static TypeId tid = TypeId ("ns3::SocketIpTtlTag")
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   341
    .SetParent<Tag> ()
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   342
    .AddConstructor<SocketIpTtlTag> ()
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   343
    ;
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   344
  return tid;
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   345
}
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   346
TypeId
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   347
SocketIpTtlTag::GetInstanceTypeId (void) const
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   348
{
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   349
  return GetTypeId ();
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   350
}
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   351
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   352
uint32_t 
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   353
SocketIpTtlTag::GetSerializedSize (void) const
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   354
{ 
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   355
  return 1;
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   356
}
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   357
void 
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   358
SocketIpTtlTag::Serialize (TagBuffer i) const
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   359
{ 
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   360
  i.WriteU8 (m_ttl);
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   361
}
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   362
void 
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   363
SocketIpTtlTag::Deserialize (TagBuffer i)
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   364
{ 
3139
37deb9deaf0e Add tag serialize methods; add serialize routines to Address
Tom Henderson <tomh@tomh.org>
parents: 3138
diff changeset
   365
  m_ttl = i.ReadU8 ();
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   366
}
3208
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   367
void
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   368
SocketIpTtlTag::Print (std::ostream &os) const
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   369
{
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   370
  os << "Ttl=" << (uint32_t) m_ttl;
1a754d09c4ba bug 200: Packet::PrintTags is not implemented.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3167
diff changeset
   371
}
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   372
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   373
}//namespace ns3