X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FSocketSink.hh;h=74580cc807feb1541db394484d0d07d6027525ef;hb=81f84badf27b66dbadec9890646ca1193e998505;hp=985befdea59c0bb284db71e5bf5fafdc16ff64e5;hpb=6be307076aadc9f66bbd89b97d6e42c40f7c0187;p=senf.git diff --git a/PPI/SocketSink.hh b/PPI/SocketSink.hh index 985befd..74580cc 100644 --- a/PPI/SocketSink.hh +++ b/PPI/SocketSink.hh @@ -57,7 +57,7 @@ namespace ppi { senf::ConnectedCommunicationPolicy>::policy > Handle; ///< Handle type supported by this writer - void operator()(Handle handle, Packet packet); + void operator()(Handle handle, Packet const & packet); ///< Write \a packet to \a handle /**< Write the complete \a packet as a datagram to \a handle. @@ -65,6 +65,36 @@ namespace ppi { \param[in] packet Packet to write */ }; + /** \brief Writer sending data with ClientSocketHandle::writeto() + + This writer will send out data using ClientSocketHandle::writeto(). The target address can + be specified in the writer constructor and can be adjusted at any time. + + If no target address is set, incoming data will be silently dropped. + */ + template + class TargetDgramWriter + { + public: + typedef HandleType Handle; + + TargetDgramWriter(); ///< Create TargetDgramWriter with unset target address + TargetDgramWriter(typename Handle::Address const & target); + ///< Create TargetDgramWriter sending to \a target + + typename Handle::Address target() const; ///< Get current target address + void target(typename Handle::Address const & target); ///< Set target address + + void operator()(Handle handle, Packet const & packet); ///< Write \a packet to \a handle + /**< Write the complete \a packet as a datagram to \a + handle. + \param[in] handle Handle to write data to + \param[in] packet Packet to write */ + + private: + typename Handle::Address target_; + }; + class IPv4SourceForcingDgramWriter : ConnectedDgramWriter { public: @@ -80,7 +110,7 @@ namespace ppi { void destination(senf::INet4SocketAddress & dest); senf::INet4SocketAddress destination(); - void operator()(Handle handle, Packet packet); + void operator()(Handle handle, Packet const & packet); ///< Write \a packet to \a handle /**< Write the complete \a packet as a datagram to \a handle. @@ -91,7 +121,7 @@ namespace ppi { senf::INet4Address source_; senf::INet4Address destination_; unsigned int protocolId_; -}; + }; class IPv6SourceForcingDgramWriter : ConnectedDgramWriter { @@ -108,7 +138,7 @@ namespace ppi { void destination(senf::INet6SocketAddress & dest); senf::INet6SocketAddress destination(); - void operator()(Handle handle, Packet packet); + void operator()(Handle handle, Packet const & packet); ///< Write \a packet to \a handle /**< Write the complete \a packet as a datagram to \a handle. @@ -166,7 +196,16 @@ namespace module { connector::ActiveInput<> input; ///< Input connector from which data is received - ActiveSocketSink(Handle handle); ///< Create new writer for the given handle + ActiveSocketSink(); ///< Create non-connected writer + /**< The writer will be disabled until a socket is set + \pre Requires \a Writer to be default constructible */ + explicit ActiveSocketSink(Writer const & writer); + ///< Create non-connected writer + /**< The writer will be disabled until a socket is set + \pre Requires \a Writer to be copy constructible + \param[in] writer Writer helper writing packet date to + the socket */ + explicit ActiveSocketSink(Handle handle); ///< Create new writer for the given handle /**< Data will be written to \a handle using \a Writer. \pre Requires \a Writer to be default constructible \param[in] handle Handle to write data to */ @@ -175,10 +214,15 @@ namespace module { /**< Data will be written to \a handle using \a Writer. \pre Requires \a Writer to be copy constructible \param[in] handle Handle to write data to - \param[in] writer Writer helper writing packet date to the - socket */ + \param[in] writer Writer helper writing packet date to + the socket */ + + Writer & writer(); ///< Access the Writer + Handle handle(); ///< Access handle + void handle(Handle handle); ///< Set handle + /**< Assigning an empty or in-valid() handle will disable + the module until a new. valid handle is assigned. */ - Writer & writer(); ///< Access the Writer private: void write(); @@ -227,7 +271,16 @@ namespace module { connector::PassiveInput<> input; ///< Input connector from which data is received - PassiveSocketSink(Handle handle); ///< Create new writer for the given handle + PassiveSocketSink(); ///< Create non-connected writer + /**< The writer will be disabled until a socket is set + \pre Requires \a Writer to be default constructible */ + explicit PassiveSocketSink(Writer const & writer); + ///< Create non-connected writer + /**< The writer will be disabled until a socket is set + \pre Requires \a Writer to be copy constructible + \param[in] writer Writer helper writing packet date to + the socket */ + explicit PassiveSocketSink(Handle handle); ///< Create new writer for the given handle /**< Data will be written to \a handle using \a Writer. \pre Requires \a Writer to be default constructible \param[in] handle Handle to write data to */ @@ -235,22 +288,23 @@ namespace module { ///< Create new writer for the given handle /**< Data will be written to \a handle using \a Writer. \pre Requires \a Writer to be copy constructible - \param[in] handle Handle to write data to */ + \param[in] handle Handle to write data to + \param[in] writer Writer helper writing packet date to + the socket */ + + Writer & writer(); ///< Access the Writer + Handle & handle(); ///< Access handle + void handle(Handle handle); ///< Set handle + /**< Assigning an empty or in-valid() handle will disable + the module until a new. valid handle is assigned. */ - Writer & writer(); ///< Access the Writer - Handle & handle(); /**< Access the handle. This is intendet to be mainly used to reconnect - the underlying socket. */ - /* void reconnect(senf::SocketAddress newAddress); - ///< Reconnect the handle to which the packets are written - */ +#ifndef DOXYGEN void replaceHandle(Handle newHandle); - /**< Replace the handle to which the packets are written - * Normally you should access the handle and call connect with - * the new address. This also works for other - * (active) ConnectedSocketSinks/Sources */ +#endif private: void write(); + void checkThrottle(); Handle handle_; Writer writer_;