split callback registration from socket operations in socket.h API.

This commit is contained in:
Mathieu Lacage committed 2007-08-01 18:48:24 +02:00
1 parent 21960157ae
commit 210e88b511
8 files changed
+280 -335

No files matched your search

+124 -53
View File
@@ -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<riley@ece.gatech.edu>
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "socket.h"
#include "ns3/packet.h"
namespace ns3 {
Socket::~Socket ()
{}
int
Socket::Close(Callback<void, Ptr<Socket> > closeCompleted)
void
Socket::SetCloseCallback (Callback<void,Ptr<Socket> > closeCompleted)
{
return DoClose (closeCompleted);
}
int
Socket::Connect(const Address & address,
Callback<void, Ptr<Socket> > connectionSucceeded,
Callback<void, Ptr<Socket> > connectionFailed,
Callback<void, Ptr<Socket> > halfClose)
{
return DoConnect (address, connectionSucceeded, connectionFailed, halfClose);
}
int
Socket::Accept(Callback<bool, Ptr<Socket>, const Address&> connectionRequest,
Callback<void, Ptr<Socket>, const Address&> newConnectionCreated,
Callback<void, Ptr<Socket> > closeRequested)
{
return DoAccept (connectionRequest, newConnectionCreated, closeRequested);
}
int
Socket::Send (const uint8_t* buffer,
uint32_t size,
Callback<void, Ptr<Socket>, uint32_t> dataSent)
{
return DoSend (buffer, size, dataSent);
}
int
Socket::SendTo(const Address &address,
const uint8_t *buffer,
uint32_t size,
Callback<void, Ptr<Socket>, uint32_t> dataSent)
{
return DoSendTo (address, buffer, size, dataSent);
m_closeCompleted = closeCompleted;
}
void
Socket::Recv(Callback<void, Ptr<Socket>, const uint8_t*, uint32_t,const Address&> callback)
Socket::SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded,
Callback<void, Ptr<Socket> > connectionFailed,
Callback<void, Ptr<Socket> > halfClose)
{
DoRecv (callback);
m_connectionSucceeded = connectionSucceeded;
m_connectionFailed = connectionFailed;
m_halfClose = halfClose;
}
void
Socket::RecvDummy(Callback<void, Ptr<Socket>, uint32_t,const Address&> callback)
Socket::SetAcceptCallback (Callback<bool, Ptr<Socket>, const Address &> connectionRequest,
Callback<void, Ptr<Socket>, const Address&> newConnectionCreated,
Callback<void, Ptr<Socket> > closeRequested)
{
DoRecvDummy (callback);
m_connectionRequest = connectionRequest;
m_newConnectionCreated = newConnectionCreated;
m_closeRequested = closeRequested;
}
void
Socket::SetSendCallback (Callback<void, Ptr<Socket>, uint32_t> dataSent)
{
m_dataSent = dataSent;
}
void
Socket::SetRecvCallback (Callback<void, Ptr<Socket>, const uint8_t*, uint32_t,const Address&> receivedData,
Callback<void, Ptr<Socket>, uint32_t,const Address&> receivedDummyData)
{
m_receivedData = receivedData;
m_receivedDummyData = receivedDummyData;
}
void
Socket::NotifyCloseCompleted (void)
{
if (!m_closeCompleted.IsNull ())
{
m_closeCompleted (this);
}
}
void
Socket::NotifyConnectionSucceeded (void)
{
if (!m_connectionSucceeded.IsNull ())
{
m_connectionSucceeded (this);
}
}
void
Socket::NotifyConnectionFailed (void)
{
if (!m_connectionFailed.IsNull ())
{
m_connectionFailed (this);
}
}
void
Socket::NotifyHalfClose (void)
{
if (!m_halfClose.IsNull ())
{
m_halfClose (this);
}
}
bool
Socket::RefuseAllConnections (Ptr<Socket> socket, const Address& address)
Socket::NotifyConnectionRequest (const Address &from)
{
return false;
if (!m_connectionRequest.IsNull ())
{
return m_connectionRequest (this, from);
}
else
{
// refuse all incomming connections by default.
return false;
}
}
void
Socket::DummyCallbackVoidSocket (Ptr<Socket> socket)
{}
void
Socket::DummyCallbackVoidSocketUi32 (Ptr<Socket> socket, uint32_t)
{}
Socket::NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from)
{
if (!m_newConnectionCreated.IsNull ())
{
m_newConnectionCreated (socket, from);
}
}
void
Socket::DummyCallbackVoidSocketUi32Address (Ptr<Socket> socket, uint32_t, const Address &)
{}
Socket::NotifyCloseRequested (void)
{
if (!m_closeRequested.IsNull ())
{
m_closeRequested (this);
}
}
void
Socket::DummyCallbackVoidSocketBufferUi32Address (Ptr<Socket> socket, const uint8_t *, uint32_t,
const Address &)
{}
Socket::NotifyDataSent (uint32_t size)
{
if (!m_dataSent.IsNull ())
{
m_dataSent (this, size);
}
}
void
Socket::DummyCallbackVoidSocketAddress (Ptr<Socket> socket, const Address &)
{}
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);
}
}
}//namespace ns3