Update of /cvsroot/boost/boost/boost/asio/ip/detail
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7221/boost/asio/ip/detail
Modified Files:
socket_option.hpp
Log Message:
Some fixes for Solaris, AIX and HP-UX.
Index: socket_option.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/asio/ip/detail/socket_option.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- socket_option.hpp 4 Jan 2007 08:21:33 -0000 1.3
+++ socket_option.hpp 20 Feb 2007 13:19:53 -0000 1.4
@@ -116,7 +116,7 @@
// Set the size of the boolean data.
template <typename Protocol>
- void resize(const Protocol&, std::size_t s) const
+ void resize(const Protocol&, std::size_t s)
{
if (s != sizeof(value_))
throw std::length_error("boolean socket option resize");
@@ -126,31 +126,31 @@
int value_;
};
-// Helper template for implementing integer options.
+// Helper template for implementing unicast hops options.
template <int IPv4_Level, int IPv4_Name, int IPv6_Level, int IPv6_Name>
-class integer
+class unicast_hops
{
public:
// Default constructor.
- integer()
+ unicast_hops()
: value_(0)
{
}
// Construct with a specific option value.
- explicit integer(int v)
+ explicit unicast_hops(int v)
: value_(v)
{
}
- // Set the value of the int option.
- integer& operator=(int v)
+ // Set the value of the option.
+ unicast_hops& operator=(int v)
{
value_ = v;
return *this;
}
- // Get the current value of the int option.
+ // Get the current value of the option.
int value() const
{
return value_;
@@ -174,39 +174,149 @@
return IPv4_Name;
}
- // Get the address of the int data.
+ // Get the address of the data.
template <typename Protocol>
int* data(const Protocol&)
{
return &value_;
}
- // Get the address of the int data.
+ // Get the address of the data.
template <typename Protocol>
const int* data(const Protocol&) const
{
return &value_;
}
- // Get the size of the int data.
+ // Get the size of the data.
template <typename Protocol>
std::size_t size(const Protocol&) const
{
return sizeof(value_);
}
- // Set the size of the int data.
+ // Set the size of the data.
template <typename Protocol>
- void resize(const Protocol&, std::size_t s) const
+ void resize(const Protocol&, std::size_t s)
{
if (s != sizeof(value_))
- throw std::length_error("integer socket option resize");
+ throw std::length_error("unicast hops socket option resize");
}
private:
int value_;
};
+// Helper template for implementing multicast hops options.
+template <int IPv4_Level, int IPv4_Name, int IPv6_Level, int IPv6_Name>
+class multicast_hops
+{
+public:
+ // Default constructor.
+ multicast_hops()
+ : ipv4_value_(0),
+ ipv6_value_(0)
+ {
+ }
+
+ // Construct with a specific option value.
+ explicit multicast_hops(int v)
+ {
+ if (v < 0 || v > 255)
+ throw std::out_of_range("multicast hops value out of range");
+ ipv4_value_ = static_cast<unsigned char>(v);
+ ipv6_value_ = v;
+ }
+
+ // Set the value of the option.
+ multicast_hops& operator=(int v)
+ {
+ if (v < 0 || v > 255)
+ throw std::out_of_range("multicast hops value out of range");
+ ipv4_value_ = static_cast<unsigned char>(v);
+ ipv6_value_ = v;
+ return *this;
+ }
+
+ // Get the current value of the option.
+ int value() const
+ {
+ return ipv6_value_;
+ }
+
+ // Get the level of the socket option.
+ template <typename Protocol>
+ int level(const Protocol& protocol) const
+ {
+ if (protocol.family() == PF_INET6)
+ return IPv6_Level;
+ return IPv4_Level;
+ }
+
+ // Get the name of the socket option.
+ template <typename Protocol>
+ int name(const Protocol& protocol) const
+ {
+ if (protocol.family() == PF_INET6)
+ return IPv6_Name;
+ return IPv4_Name;
+ }
+
+ // Get the address of the data.
+ template <typename Protocol>
+ void* data(const Protocol& protocol)
+ {
+ if (protocol.family() == PF_INET6)
+ return &ipv6_value_;
+ return &ipv4_value_;
+ }
+
+ // Get the address of the data.
+ template <typename Protocol>
+ const void* data(const Protocol& protocol) const
+ {
+ if (protocol.family() == PF_INET6)
+ return &ipv6_value_;
+ return &ipv4_value_;
+ }
+
+ // Get the size of the data.
+ template <typename Protocol>
+ std::size_t size(const Protocol& protocol) const
+ {
+ if (protocol.family() == PF_INET6)
+ return sizeof(ipv6_value_);
+ return sizeof(ipv4_value_);
+ }
+
+ // Set the size of the data.
+ template <typename Protocol>
+ void resize(const Protocol& protocol, std::size_t s)
+ {
+ if (protocol.family() == PF_INET6)
+ {
+ if (s != sizeof(ipv6_value_))
+ throw std::length_error("multicast hops socket option resize");
+ if (ipv6_value_ < 0)
+ ipv4_value_ = 0;
+ else if (ipv6_value_ > 255)
+ ipv4_value_ = 255;
+ else
+ ipv4_value_ = static_cast<unsigned char>(ipv6_value_);
+ }
+ else
+ {
+ if (s != sizeof(ipv4_value_))
+ throw std::length_error("multicast hops socket option resize");
+ ipv6_value_ = ipv4_value_;
+ }
+ }
+
+private:
+ unsigned char ipv4_value_;
+ int ipv6_value_;
+};
+
// Helper template for implementing ip_mreq-based options.
template <int IPv4_Level, int IPv4_Name, int IPv6_Level, int IPv6_Name>
class multicast_request
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs