src/node/socket.h
author Tom Henderson <tomh@tomh.org>
Tue, 22 Apr 2008 22:39:17 -0700
changeset 3000 bd2d3e32ef7b
parent 2999 0b10920623bf
child 3097 1b1661bbfa33
permissions -rw-r--r--
A few minor cleanups to socket.h/cc
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"
498
5d5fe14d5751 make capabilities and sockets refcounted
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    28
#include "ns3/object.h"
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    29
#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
    30
#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
    31
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    32
namespace ns3 {
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    33
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 646
diff changeset
    34
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
    35
class Packet;
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    37
/**
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    38
 * \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
    39
 *
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    40
 * Contrary 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
    41
 * 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
    42
 * 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
    43
 * 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
    44
 * 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
    45
 * 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
    46
 */
498
5d5fe14d5751 make capabilities and sockets refcounted
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    47
class Socket : public Object
5d5fe14d5751 make capabilities and sockets refcounted
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    48
{
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
public:
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    50
  virtual ~Socket();
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    51
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    52
  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
    53
    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
    54
    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
    55
    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
    56
    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
    57
    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
    58
    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
    59
    ERROR_OPNOTSUPP,
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1172
diff changeset
    60
    ERROR_AFNOSUPPORT,
1172
2e5b994330c7 add InetSocketAddress::IsMatchingType and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1162
diff changeset
    61
    ERROR_INVAL,
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1172
diff changeset
    62
    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
    63
    ERROR_NOROUTETOHOST,
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    64
    SOCKET_ERRNO_LAST
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    65
  };
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    66
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    67
  /**
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    68
   * \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
    69
   *         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
    70
   *         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
    71
   */
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    72
  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
    73
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    74
  /**
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
    75
   * \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
    76
   */
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 646
diff changeset
    77
  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
    78
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    79
  /**
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    80
   * \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
    81
   *        completed.
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    82
   */
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    83
  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
    84
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    85
  /**
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    86
   * \param connectionSucceeded this callback is invoked when the 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    87
   *        connection request initiated by the user is successfully 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    88
   *        completed. The callback is passed  back a pointer to 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    89
   *        the same socket object.
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    90
   * \param connectionFailed this callback is invoked when the 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    91
   *        connection request initiated by the user is unsuccessfully 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    92
   *        completed. The callback is passed back a pointer to the 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    93
   *        same socket object. 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    94
   * \param halfClose XXX When exactly is this callback invoked? If 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    95
   *        it invoked when the other side closes the connection ? 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
    96
   *        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
    97
   */
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
    98
  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
    99
                           Callback<void,  Ptr<Socket> > connectionFailed,
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   100
                           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
   101
  /**
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   102
   * \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
   103
   * \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
   104
   *        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
   105
   *        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
   106
   *        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
   107
   *        false otherwise. If the connection is accepted, the 
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   108
   *        "newConnectionCreated" callback will be invoked later to 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   109
   *        give access to the user to the socket created to match 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   110
   *        this new connection. If the user does not explicitly 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   111
   *        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
   112
   * \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
   113
   *        is accepted, it is created and the corresponding socket is passed
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   114
   *        back to the user through this callback. This user callback is 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   115
   *        passed a pointer to the new socket, and the ip address and 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   116
   *        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
   117
   * \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
   118
   *        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
   119
   */
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   120
  void SetAcceptCallback (Callback<bool, Ptr<Socket>, 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   121
                            const Address &> connectionRequest,
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   122
                          Callback<void, Ptr<Socket>, 
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   123
                            const Address&> newConnectionCreated,
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   124
                          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
   125
  /**
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   126
   * \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
   127
   *        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
   128
   * \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
   129
   *        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
   130
   *        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
   131
   * \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
   132
   *        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
   133
   *        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
   134
   *        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
   135
   *        callback is supported.
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   136
   */
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   137
  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
   138
  /**
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   139
   * \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
   140
   *
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   141
   *        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
   142
   *        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
   143
   *        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
   144
   *        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
   145
   *
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   146
   * \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
   147
   *        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
   148
   *        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
   149
   *        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
   150
   *        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
   151
   */
0b10920623bf bug 131 partial fix: split out Send and DataSent callbacks
Tom Henderson <tomh@tomh.org>
parents: 2303
diff changeset
   152
  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
   153
  /**
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   154
   * \brief Receive data
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   155
   * \param receivedData Invoked whenever new data is received.
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   156
   *
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   157
   */
2303
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   158
  void SetRecvCallback (Callback<void, Ptr<Socket>, Ptr<Packet>,
6f94834c2eee formatting cleanup
Tom Henderson <tomh@tomh.org>
parents: 2224
diff changeset
   159
                          const Address&> receivedData);
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   160
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   161
  /** 
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   162
   * \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
   163
   * \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
   164
   *
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   165
   * 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
   166
   */
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   167
  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
   168
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   169
  /** 
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   170
   * 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
   171
   *
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   172
   * \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
   173
   */
1162
10f9613bd9be convert Socket to use Address class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
   174
  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
   175
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   176
  /** 
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   177
   * \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
   178
   *
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   179
   * 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
   180
   * 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
   181
   */
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   182
  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
   183
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   184
  /**
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   185
   * \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
   186
   *
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   187
   * 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
   188
   * 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
   189
   */
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   190
  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
   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
   * \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
   194
   *
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   195
   * 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
   196
   * 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
   197
   */
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   198
  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
   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
   * \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
   202
   * \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
   203
   */
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   204
  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
   205
    
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   206
  /**
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   207
   * \brief Listen for incoming connections.
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   208
   * \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
   209
   * \returns XXX an error code
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   210
   */
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   211
  virtual int Listen (uint32_t queueLimit);
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   212
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   213
  /**
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   214
   * \brief Send data (or dummy data) to the remote host
1267
0ea5ae44f96b remove uint8_t * from the send path of the socket API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1265
diff changeset
   215
   * \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
   216
   * \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
   217
   *          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
   218
   */
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1317
diff changeset
   219
  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
   220
  
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   221
  /**
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   222
   * \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
   223
   * \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
   224
   * 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
   225
   * \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
   226
   * 
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   227
   * 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
   228
   * 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
   229
   */
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   230
  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
   231
  
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   232
  /**
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   233
   * \brief Send data to a specified peer.
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   234
   * \param address IP Address of remote host
1267
0ea5ae44f96b remove uint8_t * from the send path of the socket API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1265
diff changeset
   235
   * \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
   236
   * \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
   237
   *          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
   238
   */
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   239
  virtual int SendTo (const Address &address,Ptr<Packet> p) = 0;
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2186
diff changeset
   240
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2186
diff changeset
   241
  /**
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   242
   * \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
   243
   * \param address IP Address of remote host
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   244
   * \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
   245
   * 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
   246
   * \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
   247
   * \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
   248
   *          internal buffer and accepted for transmission.
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   249
   *
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   250
   * 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
   251
   * 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
   252
   */
3000
bd2d3e32ef7b A few minor cleanups to socket.h/cc
Tom Henderson <tomh@tomh.org>
parents: 2999
diff changeset
   253
  int SendTo (const Address &address, const uint8_t* buf, uint32_t size);
2186
69ad6ed6ccf4 Add uint8_t* based API for sockets
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1866
diff changeset
   254
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   255
protected:
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   256
  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
   257
  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
   258
  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
   259
  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
   260
  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
   261
  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
   262
  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
   263
  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
   264
  void NotifySend (uint32_t spaceAvailable);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1317
diff changeset
   265
  void NotifyDataReceived (Ptr<Packet> p, const Address &from);
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
1264
577875bb5a65 split callback registration from socket operations in socket.h API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1186
diff changeset
   267
  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
   268
  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
   269
  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
   270
  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
   271
  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
   272
  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
   273
  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
   274
  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
   275
  Callback<void, Ptr<Socket>, uint32_t >         m_sendCb;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1317
diff changeset
   276
  Callback<void, Ptr<Socket>, Ptr<Packet>,const Address&> m_receivedData;
349
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
};
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
} //namespace ns3
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 349
diff changeset
   281
#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
   282
3c91100689d7 Add base class IPAddr; L4Protocol; Protocol; OnOff Application, and base class Socket
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283