src/node/socket.h
author Tom Henderson <tomh@tomh.org>
Wed, 21 May 2008 22:40:18 -0700
changeset 3138 44711f06705e
parent 3127 f5971b43ee58
child 3142 1842b2f747f7
permissions -rw-r--r--
merge with ns-3-dev
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
 */
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#ifndef __SOCKET_H__
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#define __SOCKET_H__
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include "ns3/callback.h"
557
927a5bb6432a convert UdpSocket and Udp to Ptr<Node>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    27
#include "ns3/ptr.h"
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
    28
#include "ns3/tag.h"
498
5d5fe14d5751 make capabilities and sockets refcounted
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    29
#include "ns3/object.h"
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    30
#include "address.h"
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    31
#include <stdint.h>
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    33
namespace ns3 {
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    34
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
    35
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 646
diff changeset
    36
class Node;
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    37
class Packet;
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    39
/**
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    40
 * \brief Define a Socket API based on the BSD Socket API.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    41
 *
3123
fae57a467d54 undo SocketDefaults class; plumb in new UdpSocket option attributes
Tom Henderson <tomh@tomh.org>
parents: 3122
diff changeset
    42
 * In contrast to the original BSD socket API, this API is asynchronous:
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
    43
 * it does not contain blocking calls. It also uses class ns3::Packet
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
    44
 * as a fancy byte buffer, allowing data to be passed across the API
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
    45
 * using an ns3::Packet instead of a raw data pointer.  Other than that, 
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
    46
 * it tries to stick to the BSD API to make it easier for those who know 
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
    47
 * the BSD API to use this API.
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    48
 */
498
5d5fe14d5751 make capabilities and sockets refcounted
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    49
class Socket : public Object
5d5fe14d5751 make capabilities and sockets refcounted
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    50
{
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
public:
3127
f5971b43ee58 Add attributes to new abstract base class for UdpSocket
Tom Henderson <tomh@tomh.org>
parents: 3124
diff changeset
    52
// static TypeId GetTypeId (void);
f5971b43ee58 Add attributes to new abstract base class for UdpSocket
Tom Henderson <tomh@tomh.org>
parents: 3124
diff changeset
    53
3107
ec3ed34b2470 API for SocketOptions class
Tom Henderson <tomh@tomh.org>
parents: 3105
diff changeset
    54
  Socket (void);
ec3ed34b2470 API for SocketOptions class
Tom Henderson <tomh@tomh.org>
parents: 3105
diff changeset
    55
  virtual ~Socket (void);
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    56
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    57
  enum SocketErrno {
646
f7475a7c5ae6 Rename the SocketErrno enumeration values, from ESOMETHING to ERROR_SOMETHING, to avoid conflict with errno #define's; fixes compilation in mingw32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 607
diff changeset
    58
    ERROR_NOTERROR,
f7475a7c5ae6 Rename the SocketErrno enumeration values, from ESOMETHING to ERROR_SOMETHING, to avoid conflict with errno #define's; fixes compilation in mingw32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 607
diff changeset
    59
    ERROR_ISCONN,
f7475a7c5ae6 Rename the SocketErrno enumeration values, from ESOMETHING to ERROR_SOMETHING, to avoid conflict with errno #define's; fixes compilation in mingw32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 607
diff changeset
    60
    ERROR_NOTCONN,
f7475a7c5ae6 Rename the SocketErrno enumeration values, from ESOMETHING to ERROR_SOMETHING, to avoid conflict with errno #define's; fixes compilation in mingw32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 607
diff changeset
    61
    ERROR_MSGSIZE,
f7475a7c5ae6 Rename the SocketErrno enumeration values, from ESOMETHING to ERROR_SOMETHING, to avoid conflict with errno #define's; fixes compilation in mingw32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 607
diff changeset
    62
    ERROR_AGAIN,
f7475a7c5ae6 Rename the SocketErrno enumeration values, from ESOMETHING to ERROR_SOMETHING, to avoid conflict with errno #define's; fixes compilation in mingw32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 607
diff changeset
    63
    ERROR_SHUTDOWN,
f7475a7c5ae6 Rename the SocketErrno enumeration values, from ESOMETHING to ERROR_SOMETHING, to avoid conflict with errno #define's; fixes compilation in mingw32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 607
diff changeset
    64
    ERROR_OPNOTSUPP,
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1172
diff changeset
    65
    ERROR_AFNOSUPPORT,
1172
2e5b994330c7 add InetSocketAddress::IsMatchingType and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1162
diff changeset
    66
    ERROR_INVAL,
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1172
diff changeset
    67
    ERROR_BADF,
1317
82629189efff Fold the two patches for bu6 69 together, building on the bug 65 patch
Tom Henderson <tomh@tomh.org>
parents: 1308
diff changeset
    68
    ERROR_NOROUTETOHOST,
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    69
    SOCKET_ERRNO_LAST
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    70
  };
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    71
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    72
  /**
3116
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    73
   * This method wraps the creation of sockets that is performed
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    74
   * by a socket factory on a given node based on a TypeId.
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    75
   * 
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    76
   * \return A smart pointer to a newly created socket.
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    77
   * 
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    78
   * \param node The node on which to create the socket
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    79
   * \param tid The TypeId of the socket to create
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    80
   */
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    81
  static Ptr<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
    82
c33b6d2775b7 Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents: 3107
diff changeset
    83
  /**
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    84
   * \return the errno associated to the last call which failed in this
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    85
   *         socket. Each socket's errno is initialized to zero
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    86
   *         when the socket is created.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    87
   */
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    88
  virtual enum Socket::SocketErrno GetErrno (void) const = 0;
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    89
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    90
  /**
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    91
   * \returns the node this socket is associated with.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    92
   */
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 646
diff changeset
    93
  virtual Ptr<Node> GetNode (void) const = 0;
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    94
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    95
  /**
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    96
   * \param closeCompleted Callback invoked when the close operation is
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    97
   *        completed.
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    98
   */
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    99
  void SetCloseCallback (Callback<void, Ptr<Socket> > closeCompleted);
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   100
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   101
  /**
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   102
   * \param connectionSucceeded this callback is invoked when the 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   103
   *        connection request initiated by the user is successfully 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   104
   *        completed. The callback is passed  back a pointer to 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   105
   *        the same socket object.
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   106
   * \param connectionFailed this callback is invoked when the 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   107
   *        connection request initiated by the user is unsuccessfully 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   108
   *        completed. The callback is passed back a pointer to the 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   109
   *        same socket object. 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   110
   * \param halfClose XXX When exactly is this callback invoked? If 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   111
   *        it invoked when the other side closes the connection ? 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   112
   *        Or when I call Close ?
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   113
   */
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   114
  void SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded,
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   115
                           Callback<void,  Ptr<Socket> > connectionFailed,
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   116
                           Callback<void,  Ptr<Socket> > halfClose);
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   117
  /**
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   118
   * \brief Accept connection requests from remote hosts
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   119
   * \param connectionRequest Callback for connection request from peer. 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   120
   *        This user callback is passed a pointer to this socket, the 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   121
   *        ip address and the port number of the connection originator. 
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   122
   *        This callback must return true to accept the incoming connection,
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   123
   *        false otherwise. If the connection is accepted, the 
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   124
   *        "newConnectionCreated" callback will be invoked later to 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   125
   *        give access to the user to the socket created to match 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   126
   *        this new connection. If the user does not explicitly 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   127
   *        specify this callback, all incoming  connections will be refused.
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   128
   * \param newConnectionCreated Callback for new connection: when a new
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   129
   *        is accepted, it is created and the corresponding socket is passed
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   130
   *        back to the user through this callback. This user callback is 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   131
   *        passed a pointer to the new socket, and the ip address and 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   132
   *        port number of the connection originator.
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   133
   * \param closeRequested Callback for connection close request from peer.
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   134
   *        XXX: when is this callback invoked ?
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   135
   */
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   136
  void SetAcceptCallback (Callback<bool, Ptr<Socket>, 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   137
                            const Address &> connectionRequest,
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   138
                          Callback<void, Ptr<Socket>, 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   139
                            const Address&> newConnectionCreated,
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   140
                          Callback<void, Ptr<Socket> > closeRequested);
2999
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   141
  /**
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   142
   * \brief Notify application when a packet has been sent from transport 
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   143
   *        protocol (non-standard socket call)
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   144
   * \param dataSent Callback for the event that data is sent from the
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   145
   *        underlying transport protocol.  This callback is passed a
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   146
   *        pointer to the socket, and the number of bytes sent.
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   147
   * \returns whether or not this socket supports this callback.  Note 
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   148
   *        that this is a non-standard socket call.  Some socket 
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   149
   *        implementations in ns-3 may not support this call, so the
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   150
   *        user should check this return value to confirm that the
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   151
   *        callback is supported.
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   152
   */
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   153
  virtual bool SetDataSentCallback (Callback<void, Ptr<Socket>, uint32_t> dataSent);
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   154
  /**
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   155
   * \brief Notify application when space in transmit buffer is added
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   156
   *
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   157
   *        This callback is intended to notify a 
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   158
   *        socket that would have been blocked in a blocking socket model
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   159
   *        that space is available in the transmit buffer and that it
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   160
   *        can call Send() again.  
2999
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   161
   *
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   162
   * \param sendCb Callback for the event that the socket transmit buffer
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   163
   *        fill level has decreased.  This callback is passed a pointer to
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   164
   *        the socket, and the number of bytes available for writing
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   165
   *        into the buffer (an absolute value).  If there is no transmit
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   166
   *        buffer limit, a maximum-sized integer is always returned.
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   167
   */
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   168
  void SetSendCallback (Callback<void, Ptr<Socket>, uint32_t> sendCb);
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   169
  /**
3102
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   170
   * \brief Notify application when new data is available to be read.
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   171
   *
3102
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   172
   *        This callback is intended to notify a socket that would
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   173
   *        have been blocked in a blocking socket model that data
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   174
   *        is available to be read.
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   175
   */
3102
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   176
  void SetRecvCallback (Callback<void, Ptr<Socket> >);
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   177
  /** 
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   178
   * \param address the address to try to allocate
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   179
   * \returns 0 on success, -1 on failure.
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   180
   *
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   181
   * Allocate a local endpoint for this socket.
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   182
   */
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   183
  virtual int Bind (const Address &address) = 0;
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   184
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   185
  /** 
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   186
   * Allocate a local endpoint for this socket.
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   187
   *
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   188
   * \returns 0 on success, -1 on failure.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   189
   */
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   190
  virtual int Bind () = 0;
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   191
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   192
  /** 
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   193
   * \brief Close a socket.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   194
   *
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   195
   * After the Close call, the socket is no longer valid, and cannot
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   196
   * safely be used for subsequent operations.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   197
   */
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   198
  virtual int Close (void) = 0;
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   200
  /**
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   201
   * \returns zero on success, -1 on failure.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   202
   *
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   203
   * Do not allow any further Send calls. This method is typically
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   204
   * implemented for Tcp sockets by a half close.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   205
   */
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   206
  virtual int ShutdownSend (void) = 0;
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   207
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   208
  /**
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   209
   * \returns zero on success, -1 on failure.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   210
   *
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   211
   * Do not allow any further Recv calls. This method is typically
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   212
   * implemented for Tcp sockets by a half close.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   213
   */
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   214
  virtual int ShutdownRecv (void) = 0;
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   216
  /**
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   217
   * \brief Initiate a connection to a remote host
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   218
   * \param address Address of remote.
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   219
   */
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   220
  virtual int Connect (const Address &address) = 0;
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   221
    
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   222
  /**
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   223
   * \brief Listen for incoming connections.
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   224
   * \param queueLimit maximum number of incoming request to queue
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   225
   * \returns XXX an error code
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   226
   */
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   227
  virtual int Listen (uint32_t queueLimit);
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   228
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   229
  /**
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   230
   * \brief Send data (or dummy data) to the remote host
3122
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   231
   *
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   232
   * This function matches closely in semantics to the send() function
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   233
   * call in the standard C library (libc):
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   234
   *   ssize_t send (int s, const void *msg, size_t len, int flags);
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   235
   * except that the function call is asynchronous.
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   236
   * 
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   237
   * In a typical blocking sockets model, this call would block upon
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   238
   * lack of space to hold the message to be sent.  In ns-3 at this
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   239
   * API, the call returns immediately in such a case, but the callback
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   240
   * registered with SetSendCallback() is invoked when the socket
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   241
   * has space (when it conceptually unblocks); this is an asynchronous
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   242
   * I/O model for send().
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   243
   * 
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   244
   * This variant of Send() uses class ns3::Packet to encapsulate
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   245
   * data, rather than providing a raw pointer and length field.  
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   246
   * This allows an ns-3 application to attach tags if desired (such
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   247
   * as a flow ID) and may allow the simulator to avoid some data
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   248
   * copies.  Despite the appearance of sending Packets on a stream
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   249
   * socket, just think of it as a fancy byte buffer with streaming
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   250
   * semantics.    
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   251
   *
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   252
   * If either the message buffer within the Packet is too long to pass 
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   253
   * atomically through the underlying protocol (for datagram sockets), 
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   254
   * or the message buffer cannot entirely fit in the transmit buffer
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   255
   * (for stream sockets), -1 is returned and SocketErrno is set 
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   256
   * to ERROR_MSGSIZE.  If the packet does not fit, the caller can
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   257
   * split the Packet (based on information obtained from 
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   258
   * GetTxAvailable) and reattempt to send the data.
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   259
   *
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   260
   * \param p ns3::Packet to send
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   261
   * \returns the number of bytes accepted for transmission if no error
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   262
   *          occurs, and -1 otherwise.
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   263
   */
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1317
diff changeset
   264
  virtual int Send (Ptr<Packet> p) = 0;
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
  
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   266
  /**
3122
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   267
   * \brief Returns the number of bytes which can be sent in a single call
3105
682950a37ea6 Add GetTxBuffer; add some socket options; make limited UDP receive buffer functional
Tom Henderson <tomh@tomh.org>
parents: 3104
diff changeset
   268
   * to Send. 
3122
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   269
   * 
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   270
   * For datagram sockets, this returns the number of bytes that
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   271
   * can be passed atomically through the underlying protocol.
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   272
   *
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   273
   * For stream sockets, this returns the available space in bytes
dfa83ab5172d improve send semantics, documentation
Tom Henderson <tomh@tomh.org>
parents: 3120
diff changeset
   274
   * left in the transmit buffer.
3105
682950a37ea6 Add GetTxBuffer; add some socket options; make limited UDP receive buffer functional
Tom Henderson <tomh@tomh.org>
parents: 3104
diff changeset
   275
   */
682950a37ea6 Add GetTxBuffer; add some socket options; make limited UDP receive buffer functional
Tom Henderson <tomh@tomh.org>
parents: 3104
diff changeset
   276
  virtual uint32_t GetTxAvailable (void) const = 0;
682950a37ea6 Add GetTxBuffer; add some socket options; make limited UDP receive buffer functional
Tom Henderson <tomh@tomh.org>
parents: 3104
diff changeset
   277
682950a37ea6 Add GetTxBuffer; add some socket options; make limited UDP receive buffer functional
Tom Henderson <tomh@tomh.org>
parents: 3104
diff changeset
   278
  /**
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   279
   * \brief Send data (or dummy data) to the remote host
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   280
   * \param buf A pointer to a raw byte buffer of some data to send.  If this 
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   281
   * is 0, we send dummy data whose size is specified by the second parameter
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   282
   * \param size the number of bytes to copy from the buffer
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   283
   * 
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   284
   * This is provided so as to have an API which is closer in appearance 
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   285
   * to that of real network or BSD sockets.  
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   286
   */
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   287
  int 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
   288
  
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   289
  /**
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   290
   * \brief Send data to a specified peer.
3120
774b2637845e swap SendTo parameters
Tom Henderson <tomh@tomh.org>
parents: 3116
diff changeset
   291
   * \param p packet to send
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   292
   * \param address IP Address of remote host
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   293
   * \returns -1 in case of error or the number of bytes copied in the 
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   294
   *          internal buffer and accepted for transmission.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   295
   */
3120
774b2637845e swap SendTo parameters
Tom Henderson <tomh@tomh.org>
parents: 3116
diff changeset
   296
  virtual int SendTo (Ptr<Packet> p, const Address &address) = 0;
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2186
diff changeset
   297
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2186
diff changeset
   298
  /**
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   299
   * \brief Send data to a specified peer.
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   300
   * \param buf A pointer to a raw byte buffer of some data to send.  If this 
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   301
   * is 0, we send dummy data whose size is specified by the third parameter
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   302
   * \param size the number of bytes to copy from the buffer
3120
774b2637845e swap SendTo parameters
Tom Henderson <tomh@tomh.org>
parents: 3116
diff changeset
   303
   * \param address IP Address of remote host
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   304
   * \returns -1 in case of error or the number of bytes copied in the 
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   305
   *          internal buffer and accepted for transmission.
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   306
   *
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   307
   * This is provided so as to have an API which is closer in appearance 
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   308
   * to that of real network or BSD sockets.
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   309
   */
3120
774b2637845e swap SendTo parameters
Tom Henderson <tomh@tomh.org>
parents: 3116
diff changeset
   310
  int 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
   311
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   312
  /**
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   313
   * \brief Read a single packet from the socket
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   314
   * \param maxSize reader will accept packet up to maxSize
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   315
   * \param flags Socket recv flags
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   316
   * \returns Ptr<Packet> of the next in-sequence packet.  Returns
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   317
   * 0 if the socket cannot return a next in-sequence packet conforming
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   318
   * to the maxSize and flags.
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   319
   */
3097
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   320
  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags) = 0;
3103
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   321
  /**
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   322
   * \brief Read a single packet from the socket
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   323
   *
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   324
   *      Overloaded version of Recv(maxSize, flags) with maxSize
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   325
   *      implicitly set to maximum sized integer, and flags set to zero.
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   326
   *
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   327
   * \returns Ptr<Packet> of the next in-sequence packet.  Returns
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   328
   * 0 if the socket cannot return a next in-sequence packet.
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   329
   */
91c6fce46125 overloaded Recv() method suggested by Gustavo
Tom Henderson <tomh@tomh.org>
parents: 3102
diff changeset
   330
   Ptr<Packet> Recv (void);
3104
24d9d9aa0977 Implement GetRxAvailable ()
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
   331
  /**
24d9d9aa0977 Implement GetRxAvailable ()
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
   332
   * Return number of bytes which can be returned from one or 
24d9d9aa0977 Implement GetRxAvailable ()
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
   333
   * multiple calls to Recv.
24d9d9aa0977 Implement GetRxAvailable ()
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
   334
   * Must be possible to call this method from the Recv callback.
24d9d9aa0977 Implement GetRxAvailable ()
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
   335
   */
24d9d9aa0977 Implement GetRxAvailable ()
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
   336
  virtual uint32_t GetRxAvailable (void) const = 0;
24d9d9aa0977 Implement GetRxAvailable ()
Tom Henderson <tomh@tomh.org>
parents: 3103
diff changeset
   337
 
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   338
protected:
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   339
  void NotifyCloseCompleted (void);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   340
  void NotifyConnectionSucceeded (void);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   341
  void NotifyConnectionFailed (void);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   342
  void NotifyHalfClose (void);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   343
  bool NotifyConnectionRequest (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
   344
  void 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
   345
  void NotifyCloseRequested (void);
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   346
  void NotifyDataSent (uint32_t size);
2999
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   347
  void NotifySend (uint32_t spaceAvailable);
3097
1b1661bbfa33 Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents: 3000
diff changeset
   348
  void NotifyDataRecv (void);
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   349
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   350
  Callback<void,Ptr<Socket> >    m_closeCompleted;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   351
  Callback<void, Ptr<Socket> >   m_connectionSucceeded;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   352
  Callback<void, Ptr<Socket> >   m_connectionFailed;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   353
  Callback<void, Ptr<Socket> >   m_halfClose;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   354
  Callback<void, Ptr<Socket> >   m_closeRequested;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   355
  Callback<bool, Ptr<Socket>, const Address &>   m_connectionRequest;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   356
  Callback<void, Ptr<Socket>, const Address&>    m_newConnectionCreated;
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   357
  Callback<void, Ptr<Socket>, uint32_t>          m_dataSent;
2999
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   358
  Callback<void, Ptr<Socket>, uint32_t >         m_sendCb;
3102
a225be367c1d more cleanup
Tom Henderson <tomh@tomh.org>
parents: 3100
diff changeset
   359
  Callback<void, Ptr<Socket> > m_receivedData;
3107
ec3ed34b2470 API for SocketOptions class
Tom Henderson <tomh@tomh.org>
parents: 3105
diff changeset
   360
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
};
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   363
/**
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   364
 * \brief This class implements a tag that carries the source address
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   365
 * of a packet across the receiving socket interface.
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   366
 */
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   367
class SocketRxAddressTag : public Tag
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   368
{
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   369
public:
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   370
  SocketRxAddressTag ();
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   371
  void SetAddress (Address addr);
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   372
  Address GetAddress (void) const;
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   373
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   374
  static TypeId GetTypeId (void);  
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   375
  virtual TypeId GetInstanceTypeId (void) const;
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   376
  virtual uint32_t GetSerializedSize (void) const;
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   377
  virtual void Serialize (TagBuffer i) const;
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   378
  virtual void Deserialize (TagBuffer i);
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   379
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   380
private:
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   381
  Address m_address;
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   382
};
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 3097
diff changeset
   383
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   384
/**
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   385
 * \brief This class implements a tag that carries the socket-specific
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   386
 * TTL of a packet to the IP layer
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   387
 */
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   388
class SocketIpTtlTag : public Tag
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   389
{
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   390
public:
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   391
  SocketIpTtlTag ();
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   392
  void SetTtl (uint8_t ttl);
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   393
  uint8_t GetTtl (void) const;
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   394
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   395
  static TypeId GetTypeId (void);  
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   396
  virtual TypeId GetInstanceTypeId (void) const;
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   397
  virtual uint32_t GetSerializedSize (void) const;
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   398
  virtual void Serialize (TagBuffer i) const;
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   399
  virtual void Deserialize (TagBuffer i);
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3127
diff changeset
   400
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   401
private:
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   402
  uint8_t m_ttl;
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   403
};
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 3123
diff changeset
   404
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
} //namespace ns3
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   406
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   407
#endif /* SOCKET_H */
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   408
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409