// senf::ppi::module::ActiveSocketSink<Writer>
template <class Writer>
+prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink()
+{
+ registerEvent( event_, &ActiveSocketSink::write );
+ route(input, event_);
+}
+
+template <class Writer>
+prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Writer const & writer)
+ : writer_ (writer)
+{
+ registerEvent( event_, &ActiveSocketSink::write );
+ route(input, event_);
+}
+
+template <class Writer>
prefix_ senf::ppi::module::ActiveSocketSink<Writer>::ActiveSocketSink(Handle handle)
: handle_(handle), event_(handle_, IOEvent::Write), writer_()
{
// senf::ppi::module::PassiveSocketSink<Writer>
template <class Writer>
+prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink()
+{
+ noroute(input);
+ input.onRequest(&PassiveSocketSink::write);
+ checkThrottle();
+}
+
+template <class Writer>
+prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Writer const & writer)
+ : writer_ (writer)
+{
+ noroute(input);
+ input.onRequest(&PassiveSocketSink::write);
+ checkThrottle();
+}
+
+template <class Writer>
prefix_ senf::ppi::module::PassiveSocketSink<Writer>::PassiveSocketSink(Handle handle)
: handle_(handle), writer_()
{
noroute(input);
input.onRequest(&PassiveSocketSink::write);
+ checkThrottle();
}
template <class Writer>
{
noroute(input);
input.onRequest(&PassiveSocketSink::write);
+ checkThrottle();
}
////////////////////////////////////////
writer_(handle_,input());
}
+template <class Writer>
+prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::checkThrottle()
+{
+ if (handle_)
+ input.unthrottle();
+ else
+ input.throttle();
+}
+
///////////////////////////////ct.e////////////////////////////////////////
#undef prefix_
return writer_;
}
+template <class Writer>
+prefix_ typename senf::ppi::module::ActiveSocketSink<Writer>::Handle
+senf::ppi::module::ActiveSocketSink<Writer>::handle()
+{
+ return handle_;
+}
+
+template <class Writer>
+prefix_ void senf::ppi::module::ActiveSocketSink<Writer>::handle(Handle handle)
+{
+ handle_ = handle;
+ event_.set(handle_, IOEvent::Write);
+}
+
///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::PassiveSocketSink<Writer>
}
template <class Writer>
-prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::replaceHandle(Handle handle)
+prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::handle(Handle handle)
{
handle_ = handle;
+ checkThrottle();
}
+
+#ifndef DOXYGEN
+template <class Writer>
+prefix_ void senf::ppi::module::PassiveSocketSink<Writer>::replaceHandle(Handle newHandle)
+{
+ handle(newHandle);
+}
+#endif
+
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
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 */
/**< 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();
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 */
///< 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_;