#define IH_Server_ 1
// Custom includes
-#include <set>
-#include <boost/utility.hpp>
-#include <boost/scoped_ptr.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/iostreams/device/file_descriptor.hpp>
+#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream.hpp>
-#include "../Utils/intrusive_refcount.hh"
-#include "../Socket/Protocols/INet/TCPSocketHandle.hh"
-#include "../Socket/ServerSocketHandle.hh"
-#include "../Scheduler/Scheduler.hh"
-#include "../Scheduler/ReadHelper.hh"
-#include "Parse.hh"
-#include "Executor.hh"
///////////////////////////////ih.p////////////////////////////////////////
namespace console {
namespace detail {
- class Client;
+ /** \brief Internal: Nonblocking boost::iostreams::sink
- /** \brief
- */
- class Server
- : boost::noncopyable
- {
- SENF_LOG_CLASS_AREA();
- SENF_LOG_DEFAULT_LEVEL( senf::log::NOTICE );
- public:
- ///////////////////////////////////////////////////////////////////////////
- // Types
-
- typedef senf::ServerSocketHandle<
- senf::MakeSocketPolicy< senf::TCPv4SocketProtocol::Policy,
- senf::UnspecifiedAddressingPolicy>::policy > ServerHandle;
-
- ~Server();
-
- static void start(ServerHandle handle);
-
- protected:
-
- private:
- Server(ServerHandle handle);
-
- void newClient(Scheduler::EventId event);
- void removeClient(Client & client);
-
- ServerHandle handle_;
-
- typedef std::set< boost::intrusive_ptr<Client> > Clients;
- Clients clients_;
-
- static boost::scoped_ptr<Server> instance_;
-
- friend class Client;
- };
-
- /** \brief
+ The sink discards data if the output socket would.
*/
- class Client
- : public senf::intrusive_refcount
+ class NonblockingSocketSink
+ : public boost::iostreams::sink
{
- SENF_LOG_CLASS_AREA();
- SENF_LOG_DEFAULT_LEVEL( senf::log::NOTICE );
public:
- typedef Server::ServerHandle::ClientSocketHandle ClientHandle;
-
- ~Client();
-
- void stopClient();
+ typedef ClientSocketHandle<
+ MakeSocketPolicy<StreamFramingPolicy,
+ WriteablePolicy,
+ ConnectedCommunicationPolicy>::policy > Handle;
- protected:
+ NonblockingSocketSink(Handle handle);
+ std::streamsize write(const char * s, std::streamsize n);
private:
- Client(ClientHandle handle);
-
- void clientData(ReadHelper<ClientHandle>::ptr helper);
-
- ClientHandle handle_;
- std::string tail_;
- SingleCommandParser parser_;
- Executor executor_;
-
- typedef boost::iostreams::stream<boost::iostreams::file_descriptor_sink> fdostream;
- fdostream out_;
-
- friend class Server;
+ Handle handle_;
};
+ typedef boost::iostreams::stream<NonblockingSocketSink> NonblockingSocketOStream;
+
}}}
///////////////////////////////ih.e////////////////////////////////////////