diff -r 7f18229bae34 -r 577875bb5a65 src/node/socket.cc --- a/src/node/socket.cc Wed Aug 01 17:24:55 2007 +0200 +++ b/src/node/socket.cc Wed Aug 01 18:48:24 2007 +0200 @@ -1,79 +1,150 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 Georgia Tech Research Corporation + * 2007 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: George F. Riley + * Mathieu Lacage + */ #include "socket.h" +#include "ns3/packet.h" namespace ns3 { Socket::~Socket () {} -int -Socket::Close(Callback > closeCompleted) +void +Socket::SetCloseCallback (Callback > closeCompleted) +{ + m_closeCompleted = closeCompleted; +} +void +Socket::SetConnectCallback (Callback > connectionSucceeded, + Callback > connectionFailed, + Callback > halfClose) { - return DoClose (closeCompleted); + m_connectionSucceeded = connectionSucceeded; + m_connectionFailed = connectionFailed; + m_halfClose = halfClose; +} +void +Socket::SetAcceptCallback (Callback, const Address &> connectionRequest, + Callback, const Address&> newConnectionCreated, + Callback > closeRequested) +{ + m_connectionRequest = connectionRequest; + m_newConnectionCreated = newConnectionCreated; + m_closeRequested = closeRequested; +} +void +Socket::SetSendCallback (Callback, uint32_t> dataSent) +{ + m_dataSent = dataSent; +} +void +Socket::SetRecvCallback (Callback, const uint8_t*, uint32_t,const Address&> receivedData, + Callback, uint32_t,const Address&> receivedDummyData) +{ + m_receivedData = receivedData; + m_receivedDummyData = receivedDummyData; } -int -Socket::Connect(const Address & address, - Callback > connectionSucceeded, - Callback > connectionFailed, - Callback > halfClose) +void +Socket::NotifyCloseCompleted (void) { - return DoConnect (address, connectionSucceeded, connectionFailed, halfClose); -} -int -Socket::Accept(Callback, const Address&> connectionRequest, - Callback, const Address&> newConnectionCreated, - Callback > closeRequested) -{ - return DoAccept (connectionRequest, newConnectionCreated, closeRequested); + if (!m_closeCompleted.IsNull ()) + { + m_closeCompleted (this); + } } -int -Socket::Send (const uint8_t* buffer, - uint32_t size, - Callback, uint32_t> dataSent) +void +Socket::NotifyConnectionSucceeded (void) { - return DoSend (buffer, size, dataSent); + if (!m_connectionSucceeded.IsNull ()) + { + m_connectionSucceeded (this); + } } -int -Socket::SendTo(const Address &address, - const uint8_t *buffer, - uint32_t size, - Callback, uint32_t> dataSent) +void +Socket::NotifyConnectionFailed (void) { - return DoSendTo (address, buffer, size, dataSent); + if (!m_connectionFailed.IsNull ()) + { + m_connectionFailed (this); + } } void -Socket::Recv(Callback, const uint8_t*, uint32_t,const Address&> callback) +Socket::NotifyHalfClose (void) +{ + if (!m_halfClose.IsNull ()) + { + m_halfClose (this); + } +} +bool +Socket::NotifyConnectionRequest (const Address &from) { - DoRecv (callback); + if (!m_connectionRequest.IsNull ()) + { + return m_connectionRequest (this, from); + } + else + { + // refuse all incomming connections by default. + return false; + } } void -Socket::RecvDummy(Callback, uint32_t,const Address&> callback) +Socket::NotifyNewConnectionCreated (Ptr socket, const Address &from) +{ + if (!m_newConnectionCreated.IsNull ()) + { + m_newConnectionCreated (socket, from); + } +} +void +Socket::NotifyCloseRequested (void) { - DoRecvDummy (callback); + if (!m_closeRequested.IsNull ()) + { + m_closeRequested (this); + } +} +void +Socket::NotifyDataSent (uint32_t size) +{ + if (!m_dataSent.IsNull ()) + { + m_dataSent (this, size); + } +} +void +Socket::NotifyDataReceived (const Packet &p, const Address &from) +{ + if (!m_receivedData.IsNull ()) + { + m_receivedData (this, p.PeekData (), p.GetSize (), from); + } + if (!m_receivedDummyData.IsNull ()) + { + m_receivedDummyData (this, p.GetSize (), from); + } } -bool -Socket::RefuseAllConnections (Ptr socket, const Address& address) -{ - return false; -} -void -Socket::DummyCallbackVoidSocket (Ptr socket) -{} -void -Socket::DummyCallbackVoidSocketUi32 (Ptr socket, uint32_t) -{} -void -Socket::DummyCallbackVoidSocketUi32Address (Ptr socket, uint32_t, const Address &) -{} -void -Socket::DummyCallbackVoidSocketBufferUi32Address (Ptr socket, const uint8_t *, uint32_t, - const Address &) -{} -void -Socket::DummyCallbackVoidSocketAddress (Ptr socket, const Address &) -{} - }//namespace ns3