--- a/src/internet-node/tcp-socket.cc Sat May 10 20:22:27 2008 -0700
+++ b/src/internet-node/tcp-socket.cc Sat May 10 21:27:32 2008 -0700
@@ -489,7 +489,7 @@
// XXX Raj to finish
uint32_t
-TcpSocket::GetSndBuf (void)
+TcpSocket::GetSndBuf (void) const
{
return 0;
}
@@ -502,7 +502,7 @@
// XXX Raj to finish
uint32_t
-TcpSocket::GetRcvBuf (void)
+TcpSocket::GetRcvBuf (void) const
{
return 0;
}
--- a/src/internet-node/tcp-socket.h Sat May 10 20:22:27 2008 -0700
+++ b/src/internet-node/tcp-socket.h Sat May 10 21:27:32 2008 -0700
@@ -74,10 +74,11 @@
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
virtual uint32_t GetRxAvailable (void) const;
+protected:
virtual void SetSndBuf (uint32_t size);
- virtual uint32_t GetSndBuf (void);
+ virtual uint32_t GetSndBuf (void) const;
virtual void SetRcvBuf (uint32_t size);
- virtual uint32_t GetRcvBuf (void);
+ virtual uint32_t GetRcvBuf (void) const;
private:
friend class Tcp;
--- a/src/internet-node/udp-socket.cc Sat May 10 20:22:27 2008 -0700
+++ b/src/internet-node/udp-socket.cc Sat May 10 21:27:32 2008 -0700
@@ -338,7 +338,7 @@
UdpSocket::GetTxAvailable (void) const
{
// No finite send buffer is modelled
- return 0xffffffff;
+ return std::numeric_limits<uint32_t>::max ();
}
int
@@ -416,27 +416,24 @@
// return EINVAL since we are not modelling a finite send buffer
// Enforcing buffer size should be added if we ever start to model
// non-zero processing delay in the UDP/IP stack
- m_errno = ERROR_INVAL;
+ NS_LOG_WARN ("UdpSocket has infinite send buffer");
}
uint32_t
-UdpSocket::GetSndBuf (void)
+UdpSocket::GetSndBuf (void) const
{
- m_errno = ERROR_NOTERROR;
- return 0xffffffff;
+ return std::numeric_limits<uint32_t>::max ();
}
void
UdpSocket::SetRcvBuf (uint32_t size)
{
- m_errno = ERROR_NOTERROR;
m_udp_rmem = size;
}
uint32_t
-UdpSocket::GetRcvBuf (void)
+UdpSocket::GetRcvBuf (void) const
{
- m_errno = ERROR_NOTERROR;
return m_udp_rmem;
}
--- a/src/internet-node/udp-socket.h Sat May 10 20:22:27 2008 -0700
+++ b/src/internet-node/udp-socket.h Sat May 10 21:27:32 2008 -0700
@@ -63,10 +63,11 @@
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
virtual uint32_t GetRxAvailable (void) const;
+protected:
virtual void SetSndBuf (uint32_t size);
- virtual uint32_t GetSndBuf (void);
+ virtual uint32_t GetSndBuf (void) const;
virtual void SetRcvBuf (uint32_t size);
- virtual uint32_t GetRcvBuf (void);
+ virtual uint32_t GetRcvBuf (void) const;
private:
friend class Udp;
--- a/src/node/packet-socket.cc Sat May 10 20:22:27 2008 -0700
+++ b/src/node/packet-socket.cc Sat May 10 21:27:32 2008 -0700
@@ -349,19 +349,21 @@
PacketSocket::SetSndBuf (uint32_t size)
{
}
+
uint32_t
-PacketSocket::GetSndBuf (void)
+PacketSocket::GetSndBuf (void) const
{
-return 0;
+ return 0;
}
void
PacketSocket::SetRcvBuf (uint32_t size)
{
}
+
uint32_t
-PacketSocket::GetRcvBuf (void)
+PacketSocket::GetRcvBuf (void) const
{
-return 0;
+ return 0;
}
}//namespace ns3
--- a/src/node/packet-socket.h Sat May 10 20:22:27 2008 -0700
+++ b/src/node/packet-socket.h Sat May 10 21:27:32 2008 -0700
@@ -93,10 +93,11 @@
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
virtual uint32_t GetRxAvailable (void) const;
+protected:
virtual void SetSndBuf (uint32_t size);
- virtual uint32_t GetSndBuf (void);
+ virtual uint32_t GetSndBuf (void) const;
virtual void SetRcvBuf (uint32_t size);
- virtual uint32_t GetRcvBuf (void);
+ virtual uint32_t GetRcvBuf (void) const;
private:
void ForwardUp (Ptr<NetDevice> device, Ptr<Packet> packet,
--- a/src/node/socket.cc Sat May 10 20:22:27 2008 -0700
+++ b/src/node/socket.cc Sat May 10 21:27:32 2008 -0700
@@ -28,6 +28,56 @@
namespace ns3 {
+TypeId
+SocketOptions::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::SocketOptions")
+ .SetParent<Object> ()
+ .AddConstructor<SocketOptions> ()
+ ;
+ return tid;
+}
+
+SocketOptions::SocketOptions (void)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+}
+
+SocketOptions::~SocketOptions (void)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+}
+
+
+void
+SocketOptions::SetSndBuf (uint32_t size)
+{
+}
+
+uint32_t
+SocketOptions::GetSndBuf (void) const
+{
+ return 0;
+}
+
+void
+SocketOptions::SetRcvBuf (uint32_t size)
+{
+}
+
+uint32_t
+SocketOptions::GetRcvBuf (void) const
+{
+ return 0;
+}
+
+Socket::Socket (void)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ Ptr<SocketOptions> s = CreateObject<SocketOptions> ();
+ AggregateObject (s);
+}
+
Socket::~Socket ()
{
NS_LOG_FUNCTION_NOARGS ();
--- a/src/node/socket.h Sat May 10 20:22:27 2008 -0700
+++ b/src/node/socket.h Sat May 10 21:27:32 2008 -0700
@@ -37,6 +37,36 @@
class Packet;
/**
+ * \brief Support for socket options at the socket level.
+ *
+ * A SocketOptions object is aggregated to each Socket. This object
+ * can be fetched using GetObject() by any user of a Socket. An
+ * instance of SocketOptions is aggregated to each Socket when the
+ * Socket is constructed.
+ *
+ * This implements the equivalent of getsockopt() and setsockopt()
+ * function calls to manipulate the options associated with the
+ * socket at the uppermost ``socket'' level. Socket options that
+ * exist at a lower level (such as TCP socket options) are manipulated
+ * using a different aggregated class (TcpSocketOptions).
+ */
+class SocketOptions : public Object
+{
+public:
+ static TypeId GetTypeId (void);
+
+ SocketOptions (void);
+ virtual ~SocketOptions (void);
+
+ virtual void SetSndBuf (uint32_t size);
+ virtual uint32_t GetSndBuf (void) const;
+ virtual void SetRcvBuf (uint32_t size);
+ virtual uint32_t GetRcvBuf (void) const;
+
+ // all others
+};
+
+/**
* \brief Define a Socket API based on the BSD Socket API.
*
* Contrary to the original BSD socket API, this API is asynchronous:
@@ -48,8 +78,10 @@
*/
class Socket : public Object
{
+ friend class SocketOptions;
public:
- virtual ~Socket();
+ Socket (void);
+ virtual ~Socket (void);
enum SocketErrno {
ERROR_NOTERROR,
@@ -286,35 +318,6 @@
*/
virtual uint32_t GetRxAvailable (void) const = 0;
- /**
- * \brief ns-3 version of setsockopt (SO_SNDBUF)
- *
- * The error code value can be checked by calling GetErrno ()
- */
- virtual void SetSndBuf (uint32_t size) = 0;
- /**
- * \brief ns-3 version of getsockopt (SO_SNDBUF)
- *
- * The error code value can be checked by calling GetErrno ()
- *
- * \returns The size in bytes of the send buffer
- */
- virtual uint32_t GetSndBuf (void) = 0;
- /**
- * \brief ns-3 version of setsockopt (SO_RCVBUF)
- *
- * The error code value can be checked by calling GetErrno ()
- */
- virtual void SetRcvBuf (uint32_t size) = 0;
- /**
- * \brief ns-3 version of getsockopt (SO_RCVBUF)
- *
- * The error code value can be checked by calling GetErrno ()
- *
- * \returns The size in bytes of the receive buffer
- */
- virtual uint32_t GetRcvBuf (void) = 0;
-
protected:
void NotifyCloseCompleted (void);
void NotifyConnectionSucceeded (void);
@@ -337,6 +340,12 @@
Callback<void, Ptr<Socket>, uint32_t> m_dataSent;
Callback<void, Ptr<Socket>, uint32_t > m_sendCb;
Callback<void, Ptr<Socket> > m_receivedData;
+
+ // Socket options at level socket
+ virtual void SetSndBuf (uint32_t size) = 0;
+ virtual uint32_t GetSndBuf (void) const = 0;
+ virtual void SetRcvBuf (uint32_t size) = 0;
+ virtual uint32_t GetRcvBuf (void) const = 0;
};
/**