View | Details | Raw Unified | Return to bug 205
Collapse All | Expand All

(-)a/examples/tcp-large-transfer.cc (-3 / +2 lines)
 Lines 87-93   int main (int argc, char *argv[]) Link Here 
87
  // Users may find it convenient to turn on explicit debugging
87
  // Users may find it convenient to turn on explicit debugging
88
  // for selected modules; the below lines suggest how to do this
88
  // for selected modules; the below lines suggest how to do this
89
  //  LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL);
89
  //  LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL);
90
  //  LogComponentEnable("TcpSocket", LOG_LEVEL_ALL);
90
  //  LogComponentEnable("TcpSocketImpl", LOG_LEVEL_ALL);
91
  //  LogComponentEnable("PacketSink", LOG_LEVEL_ALL);
91
  //  LogComponentEnable("PacketSink", LOG_LEVEL_ALL);
92
  //  LogComponentEnable("TcpLargeTransfer", LOG_LEVEL_ALL);
92
  //  LogComponentEnable("TcpLargeTransfer", LOG_LEVEL_ALL);
93
93
 Lines 182-189   void StartFlow(Ptr<Socket> localSocket, Link Here 
182
 // NS_LOG_LOGIC("Starting flow at time " <<  Simulator::Now ().GetSeconds ());
182
 // NS_LOG_LOGIC("Starting flow at time " <<  Simulator::Now ().GetSeconds ());
183
  localSocket->Connect (InetSocketAddress (servAddress, servPort));//connect
183
  localSocket->Connect (InetSocketAddress (servAddress, servPort));//connect
184
  localSocket->SetConnectCallback (MakeCallback (&CloseConnection),
184
  localSocket->SetConnectCallback (MakeCallback (&CloseConnection),
185
                                   Callback<void, Ptr<Socket> > (),
185
                                   Callback<void, Ptr<Socket> > ());
186
                                       Callback<void, Ptr<Socket> > ());
187
  //we want to close as soon as the connection is established
186
  //we want to close as soon as the connection is established
188
  //the tcp state machine and outgoing buffer will assure that
187
  //the tcp state machine and outgoing buffer will assure that
189
  //all of the data is delivered
188
  //all of the data is delivered
(-)a/src/applications/packet-sink/packet-sink.cc (-7 / +5 lines)
 Lines 67-72   void Link Here 
67
void
67
void
68
PacketSink::DoDispose (void)
68
PacketSink::DoDispose (void)
69
{
69
{
70
  if (m_socket != 0)
71
    {
72
      m_socket->Close ();
73
    }
70
  m_socket = 0;
74
  m_socket = 0;
71
75
72
  // chain up
76
  // chain up
 Lines 88-95   void PacketSink::StartApplication() / Link Here 
88
  m_socket->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this));
92
  m_socket->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this));
89
  m_socket->SetAcceptCallback (
93
  m_socket->SetAcceptCallback (
90
            MakeNullCallback<bool, Ptr<Socket>, const Address &> (),
94
            MakeNullCallback<bool, Ptr<Socket>, const Address &> (),
91
            MakeNullCallback<void, Ptr<Socket>, const Address&> (),
95
            MakeNullCallback<void, Ptr<Socket>, const Address&> ());
92
            MakeCallback(&PacketSink::CloseConnection, this) );
93
}
96
}
94
97
95
void PacketSink::StopApplication()     // Called at time specified by Stop
98
void PacketSink::StopApplication()     // Called at time specified by Stop
 Lines 117-125   void PacketSink::HandleRead (Ptr<Socket> Link Here 
117
    }
120
    }
118
}
121
}
119
122
120
void PacketSink::CloseConnection (Ptr<Socket> socket)
121
{
122
  socket->Close ();
123
}
124
125
} // Namespace ns3
123
} // Namespace ns3
(-)a/src/applications/packet-sink/packet-sink.h (-3 / +1 lines)
 Lines 80-88   private: Link Here 
80
  virtual void StartApplication (void);    // Called at time specified by Start
80
  virtual void StartApplication (void);    // Called at time specified by Start
81
  virtual void StopApplication (void);     // Called at time specified by Stop
81
  virtual void StopApplication (void);     // Called at time specified by Stop
82
82
83
  virtual void HandleRead (Ptr<Socket> socket);
83
  void HandleRead (Ptr<Socket> socket);
84
85
  virtual void CloseConnection (Ptr<Socket> socket);
86
84
87
  Ptr<Socket>     m_socket;       // Associated socket
85
  Ptr<Socket>     m_socket;       // Associated socket
88
  Address         m_local;        // Local address to bind to
86
  Address         m_local;        // Local address to bind to
(-)a/src/internet-stack/tcp-socket-impl.cc (-3 / +1 lines)
 Lines 620-626   Actions_t TcpSocketImpl::ProcessEvent (E Link Here 
620
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " 
620
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " 
621
               << m_state << " event " << e << " closeNot " << m_closeNotified
621
               << m_state << " event " << e << " closeNot " << m_closeNotified
622
               << " action " << stateAction.action);
622
               << " action " << stateAction.action);
623
      NotifyCloseCompleted ();
624
      m_closeNotified = true;
623
      m_closeNotified = true;
625
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " calling Closed from PE"
624
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " calling Closed from PE"
626
              << " origState " << saveState
625
              << " origState " << saveState
 Lines 854-860   bool TcpSocketImpl::ProcessPacketAction Link Here 
854
        {
853
        {
855
          NS_LOG_LOGIC ("TCP " << this 
854
          NS_LOG_LOGIC ("TCP " << this 
856
              << " calling AppCloseRequest");
855
              << " calling AppCloseRequest");
857
          NotifyCloseRequested(); 
858
          m_closeRequestNotified = true;
856
          m_closeRequestNotified = true;
859
        }
857
        }
860
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
858
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
 Lines 1298-1304   void TcpSocketImpl::Retransmit () Link Here 
1298
    } 
1296
    } 
1299
  if (!m_pendingData)
1297
  if (!m_pendingData)
1300
    {
1298
    {
1301
      if (m_state == FIN_WAIT_1 || m_state == FIN_WAIT_2)
1299
      if (m_state == FIN_WAIT_1)
1302
        { // Must have lost FIN, re-send
1300
        { // Must have lost FIN, re-send
1303
          SendEmptyPacket (TcpHeader::FIN);
1301
          SendEmptyPacket (TcpHeader::FIN);
1304
        }
1302
        }
(-)a/src/internet-stack/udp-socket-impl.cc (-1 lines)
 Lines 199-205   UdpSocketImpl::Close(void) Link Here 
199
UdpSocketImpl::Close(void)
199
UdpSocketImpl::Close(void)
200
{
200
{
201
  NS_LOG_FUNCTION_NOARGS ();
201
  NS_LOG_FUNCTION_NOARGS ();
202
  NotifyCloseCompleted ();
203
  return 0;
202
  return 0;
204
}
203
}
205
204
(-)a/src/node/packet-socket.cc (-1 lines)
 Lines 184-190   PacketSocket::Close(void) Link Here 
184
      return -1;
184
      return -1;
185
    }
185
    }
186
  m_state = STATE_CLOSED;
186
  m_state = STATE_CLOSED;
187
  NotifyCloseCompleted ();
188
  return 0;
187
  return 0;
189
}
188
}
190
189
(-)a/src/node/socket.cc (-51 / +2 lines)
 Lines 51-84   Socket::CreateSocket (Ptr<Node> node, Ty Link Here 
51
}
51
}
52
52
53
void 
53
void 
54
Socket::SetCloseCallback (Callback<void,Ptr<Socket> > closeCompleted)
55
{
56
  NS_LOG_FUNCTION_NOARGS ();
57
  m_closeCompleted = closeCompleted;
58
}
59
60
void 
61
Socket::SetConnectCallback (
54
Socket::SetConnectCallback (
62
  Callback<void, Ptr<Socket> > connectionSucceeded,
55
  Callback<void, Ptr<Socket> > connectionSucceeded,
63
  Callback<void, Ptr<Socket> > connectionFailed,
56
  Callback<void, Ptr<Socket> > connectionFailed)
64
  Callback<void, Ptr<Socket> > halfClose)
65
{
57
{
66
  NS_LOG_FUNCTION_NOARGS ();
58
  NS_LOG_FUNCTION_NOARGS ();
67
  m_connectionSucceeded = connectionSucceeded;
59
  m_connectionSucceeded = connectionSucceeded;
68
  m_connectionFailed = connectionFailed;
60
  m_connectionFailed = connectionFailed;
69
  m_halfClose = halfClose;
70
}
61
}
71
62
72
void 
63
void 
73
Socket::SetAcceptCallback (
64
Socket::SetAcceptCallback (
74
  Callback<bool, Ptr<Socket>, const Address &> connectionRequest,
65
  Callback<bool, Ptr<Socket>, const Address &> connectionRequest,
75
  Callback<void, Ptr<Socket>, const Address&> newConnectionCreated,
66
  Callback<void, Ptr<Socket>, const Address&> newConnectionCreated)
76
  Callback<void, Ptr<Socket> > closeRequested)
77
{
67
{
78
  NS_LOG_FUNCTION_NOARGS ();
68
  NS_LOG_FUNCTION_NOARGS ();
79
  m_connectionRequest = connectionRequest;
69
  m_connectionRequest = connectionRequest;
80
  m_newConnectionCreated = newConnectionCreated;
70
  m_newConnectionCreated = newConnectionCreated;
81
  m_closeRequested = closeRequested;
82
}
71
}
83
72
84
bool 
73
bool 
 Lines 110-124   Socket::Send (Ptr<Packet> p) Link Here 
110
  return Send (p, 0);
99
  return Send (p, 0);
111
}
100
}
112
101
113
void
114
Socket::NotifyCloseUnblocks (void)
115
{
116
  NS_LOG_FUNCTION_NOARGS ();
117
  if (!m_closeUnblocks.IsNull ())
118
  {
119
    m_closeUnblocks (this);
120
  }
121
}
122
102
123
int Socket::Listen (uint32_t queueLimit)
103
int Socket::Listen (uint32_t queueLimit)
124
{
104
{
 Lines 199-213   Socket::RecvFrom (uint8_t* buf, uint32_t Link Here 
199
  return p->GetSize ();
179
  return p->GetSize ();
200
}
180
}
201
181
202
void 
203
Socket::NotifyCloseCompleted (void)
204
{
205
  NS_LOG_FUNCTION_NOARGS ();
206
  if (!m_closeCompleted.IsNull ())
207
    {
208
      m_closeCompleted (this);
209
    }
210
}
211
182
212
void 
183
void 
213
Socket::NotifyConnectionSucceeded (void)
184
Socket::NotifyConnectionSucceeded (void)
 Lines 226-241   Socket::NotifyConnectionFailed (void) Link Here 
226
  if (!m_connectionFailed.IsNull ())
197
  if (!m_connectionFailed.IsNull ())
227
    {
198
    {
228
      m_connectionFailed (this);
199
      m_connectionFailed (this);
229
    }
230
}
231
232
void 
233
Socket::NotifyHalfClose (void)
234
{
235
  NS_LOG_FUNCTION_NOARGS ();
236
  if (!m_halfClose.IsNull ())
237
    {
238
      m_halfClose (this);
239
    }
200
    }
240
}
201
}
241
202
 Lines 268-283   Socket::NotifyNewConnectionCreated (Ptr< Link Here 
268
}
229
}
269
230
270
void 
231
void 
271
Socket::NotifyCloseRequested (void)
272
{
273
  NS_LOG_FUNCTION_NOARGS ();
274
  if (!m_closeRequested.IsNull ())
275
    {
276
      m_closeRequested (this);
277
    }
278
}
279
280
void 
281
Socket::NotifyDataSent (uint32_t size)
232
Socket::NotifyDataSent (uint32_t size)
282
{
233
{
283
  NS_LOG_FUNCTION_NOARGS ();
234
  NS_LOG_FUNCTION_NOARGS ();
(-)a/src/node/socket.h (-23 / +2 lines)
 Lines 102-113   public: Link Here 
102
   * \returns the node this socket is associated with.
102
   * \returns the node this socket is associated with.
103
   */
103
   */
104
  virtual Ptr<Node> GetNode (void) const = 0;
104
  virtual Ptr<Node> GetNode (void) const = 0;
105
106
  /**
107
   * \param closeCompleted Callback invoked when the close operation is
108
   *        completed.
109
   */
110
  void SetCloseCallback (Callback<void, Ptr<Socket> > closeCompleted);
111
  /**
105
  /**
112
   * \param connectionSucceeded this callback is invoked when the 
106
   * \param connectionSucceeded this callback is invoked when the 
113
   *        connection request initiated by the user is successfully 
107
   *        connection request initiated by the user is successfully 
 Lines 117-129   public: Link Here 
117
   *        connection request initiated by the user is unsuccessfully 
111
   *        connection request initiated by the user is unsuccessfully 
118
   *        completed. The callback is passed back a pointer to the 
112
   *        completed. The callback is passed back a pointer to the 
119
   *        same socket object. 
113
   *        same socket object. 
120
   * \param halfClose XXX When exactly is this callback invoked? If 
121
   *        it invoked when the other side closes the connection ? 
122
   *        Or when I call Close ?
123
   */
114
   */
124
  void SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded,
115
  void SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded,
125
                           Callback<void,  Ptr<Socket> > connectionFailed,
116
                           Callback<void,  Ptr<Socket> > connectionFailed);
126
                           Callback<void,  Ptr<Socket> > halfClose);
127
  /**
117
  /**
128
   * \brief Accept connection requests from remote hosts
118
   * \brief Accept connection requests from remote hosts
129
   * \param connectionRequest Callback for connection request from peer. 
119
   * \param connectionRequest Callback for connection request from peer. 
 Lines 140-153   public: Link Here 
140
   *        back to the user through this callback. This user callback is 
130
   *        back to the user through this callback. This user callback is 
141
   *        passed a pointer to the new socket, and the ip address and 
131
   *        passed a pointer to the new socket, and the ip address and 
142
   *        port number of the connection originator.
132
   *        port number of the connection originator.
143
   * \param closeRequested Callback for connection close request from peer.
144
   *        XXX: when is this callback invoked ?
145
   */
133
   */
146
  void SetAcceptCallback (Callback<bool, Ptr<Socket>, 
134
  void SetAcceptCallback (Callback<bool, Ptr<Socket>, 
147
                            const Address &> connectionRequest,
135
                            const Address &> connectionRequest,
148
                          Callback<void, Ptr<Socket>, 
136
                          Callback<void, Ptr<Socket>, 
149
                            const Address&> newConnectionCreated,
137
                            const Address&> newConnectionCreated);
150
                          Callback<void, Ptr<Socket> > closeRequested);
151
  /**
138
  /**
152
   * \brief Notify application when a packet has been sent from transport 
139
   * \brief Notify application when a packet has been sent from transport 
153
   *        protocol (non-standard socket call)
140
   *        protocol (non-standard socket call)
 Lines 509-532   public: Link Here 
509
                Address &fromAddress);
496
                Address &fromAddress);
510
 
497
 
511
protected:
498
protected:
512
  void NotifyCloseUnblocks (void);
513
  void NotifyCloseCompleted (void);
514
  void NotifyConnectionSucceeded (void);
499
  void NotifyConnectionSucceeded (void);
515
  void NotifyConnectionFailed (void);
500
  void NotifyConnectionFailed (void);
516
  void NotifyHalfClose (void);
517
  bool NotifyConnectionRequest (const Address &from);
501
  bool NotifyConnectionRequest (const Address &from);
518
  void NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from);
502
  void NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from);
519
  void NotifyCloseRequested (void);
520
  void NotifyDataSent (uint32_t size);
503
  void NotifyDataSent (uint32_t size);
521
  void NotifySend (uint32_t spaceAvailable);
504
  void NotifySend (uint32_t spaceAvailable);
522
  void NotifyDataRecv (void);
505
  void NotifyDataRecv (void);
523
506
524
  Callback<void, Ptr<Socket> >   m_closeUnblocks;
525
  Callback<void,Ptr<Socket> >    m_closeCompleted;
526
  Callback<void, Ptr<Socket> >   m_connectionSucceeded;
507
  Callback<void, Ptr<Socket> >   m_connectionSucceeded;
527
  Callback<void, Ptr<Socket> >   m_connectionFailed;
508
  Callback<void, Ptr<Socket> >   m_connectionFailed;
528
  Callback<void, Ptr<Socket> >   m_halfClose;
529
  Callback<void, Ptr<Socket> >   m_closeRequested;
530
  Callback<bool, Ptr<Socket>, const Address &>   m_connectionRequest;
509
  Callback<bool, Ptr<Socket>, const Address &>   m_connectionRequest;
531
  Callback<void, Ptr<Socket>, const Address&>    m_newConnectionCreated;
510
  Callback<void, Ptr<Socket>, const Address&>    m_newConnectionCreated;
532
  Callback<void, Ptr<Socket>, uint32_t>          m_dataSent;
511
  Callback<void, Ptr<Socket>, uint32_t>          m_dataSent;

Return to bug 205