return socklen()==other.socklen() && memcmp(sockaddr_p(), other.sockaddr_p(), socklen())==0;
}
-prefix_ bool senf::BSDSocketAddress::operator!=(BSDSocketAddress const & other)
+prefix_ bool senf::BSDSocketAddress::operator<(BSDSocketAddress const & other)
const
{
- return ! operator==(other);
+ if (socklen() < other.socklen()) return true;
+ else if (socklen() > other.socklen()) return false;
+ else return memcmp(sockaddr_p(), other.sockaddr_p(), socklen()) < 0;
}
prefix_ bool senf::BSDSocketAddress::boolean_test()
// Custom includes
#include <boost/type_traits/alignment_of.hpp>
#include <boost/type_traits/type_with_alignment.hpp>
+#include <boost/operators.hpp>
#include "../../Utils/safe_bool.hh"
#include <sys/socket.h>
#include <iostream>
\ingroup addr_group
*/
class BSDSocketAddress
- : public senf::comparable_safe_bool<BSDSocketAddress>
+ : public senf::comparable_safe_bool<BSDSocketAddress>,
+ public boost::less_than_comparable<BSDSocketAddress>,
+ public boost::equality_comparable<BSDSocketAddress>
{
public:
bool operator==(BSDSocketAddress const & other) const; ///< Compare two arbitrary addresses
/**< For addresses to be considered equal, they must have
the same family, length and the data must be
identical. */
- bool operator!=(BSDSocketAddress const & other) const; ///< Inverse of operator==
+ bool operator<(BSDSocketAddress const & other) const; ///< Compare two arbitrary addresses
+ /**< Ordering is based on the in-memory representation. It
+ is primarily useful to use addresses as keys in a map
+ or set. */
bool boolean_test() const; ///< Return \c true, if address is not empty
/**< An address is considered empty if
void socklen(socklen_t len);
private:
-
// The following incantation is needed to fix the alignment of the sockaddr data members
// which will be added by the derived classes later: The alignment must be forced
// to coincide with the struct sockaddr_storage alignment (which must have the largest
return is;
}
+prefix_ std::istream & senf::operator>>(std::istream & is, INet4Network & addr)
+{
+ std::string s;
+ if (!(is >> s))
+ return is;
+ try {
+ addr = INet4Network(s);
+ }
+ catch (AddressException &) {
+ is.setstate(std::ios::failbit);
+ }
+ return is;
+}
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "INet4Address.mpp"
\related INet4Address
*/
std::ostream & operator<<(std::ostream & os, INet4Address const & addr);
- /** \brief Try to initialize INet4Address instance from a string representation
+
+ /** \brief Initialize INet4Address instance from a string representation
sets std::ios::failbit on the stream if an error occurred
\see INet4Address from_string()
\related INet4Address
*/
std::ostream & operator<<(std::ostream & os, INet4Network const & addr);
+ /** \brief Initialize INet4Address instance from a string representation
+ sets std::ios::failbit on the stream if an error occurred
+ \see INet4Address from_string()
+ \related INet4Network
+ */
+ std::istream & operator>>(std::istream & is, INet4Network & addr);
+
}
///////////////////////////////hh.e////////////////////////////////////////
const
{
init_client();
+ reuseaddr(true);
clientHandle().bind(address);
}
#include "ProgramOptions.hh"
#include "Sysdir.hh"
#include "STLSupport.hh"
+#include "UDPServer.hh"
///////////////////////////////hh.e////////////////////////////////////////
//#include "Console.cci"
///////////////////////////////cc.p////////////////////////////////////////
prefix_ senf::console::UDPServer::UDPServer(senf::INet4SocketAddress const & address)
- : replies_ (true), target_ (), handle_ (senf::UDPv4ClientSocketHandle(address)),
+ : replies_ (true), emptyReplies_ (true), target_ (),
+ handle_ (senf::UDPv4ClientSocketHandle(address)),
readevent_ ("senf::console::UDPServer::readevent",
senf::membind(&UDPServer::handleInput, this),
handle_,
return *this;
}
+prefix_ senf::console::UDPServer & senf::console::UDPServer::emptyReplies(bool enable)
+{
+ emptyReplies_ = enable;
+ return *this;
+}
+
prefix_ senf::console::DirectoryNode & senf::console::UDPServer::root()
const
{
msg = msg.substr(i+4);
stream << msg << std::endl;
}
- if (replies_) {
+ if (replies_ && (emptyReplies_ || ! stream.str().empty())) {
if (target_)
address = target_;
if (stream.str().empty())
UDPServer & replies(senf::INet6SocketAddress const & address);
///< Send replies to \a address
+ UDPServer & emptyReplies(bool enable); ///< Enable or disable empty reply packets
+
DirectoryNode & root() const; ///< Get root node
UDPServer & root(DirectoryNode & root); ///< Set root node
void handleInput(int events);
bool replies_;
+ bool emptyReplies_;
senf::GenericBSDSocketAddress target_;
Handle handle_;