X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FClientSocketHandle.hh;h=92635f956927c221c820ce60de7bc32402d7d64d;hb=b8ca4a544cce3e6023bb56b712a03d6362f2bb79;hp=e07dccf99960ff5f1156658d0d0a8e16a19197ba;hpb=7a1872f6702d6206bf1d8364c4e894f98d1c64f0;p=senf.git diff --git a/Socket/ClientSocketHandle.hh b/Socket/ClientSocketHandle.hh index e07dccf..92635f9 100644 --- a/Socket/ClientSocketHandle.hh +++ b/Socket/ClientSocketHandle.hh @@ -1,9 +1,9 @@ // $Id$ // // Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -24,12 +24,14 @@ \brief ClientSocketHandle public header */ -#ifndef HH_ClientSocketHandle_ -#define HH_ClientSocketHandle_ 1 +#ifndef HH_SENF_Socket_ClientSocketHandle_ +#define HH_SENF_Socket_ClientSocketHandle_ 1 // Custom includes #include #include +#include +#include #include "SocketHandle.hh" //#include "ClientSocketHandle.mpp" @@ -40,26 +42,27 @@ namespace senf { /// \addtogroup handle_group /// @{ - template class ServerSocketHandle; + template class ServerSocketHandle; /** \brief Generic SocketHandle with client interface This class provides the client side policy interface of the socket abstraction. ClientSocketHandle defines the complete policy interface. It does not implement - any functionality itself however. All calls are forward to the following policy classes: + any functionality itself however. The following table shows, to which policy members each + group of ClientSocketHandle members is forwardd. The last collumn shows, on which other + policies this member-group depends in the default policy classes. If you define + your own policy classes, the dependencies are up to you. - - - - - - - - - - - + + + + + + + + +
ClientSocketHandle member Policy member
read() ReadPolicy::read (\ref senf::ReadPolicyBase)
readfrom() ReadPolicy::readfrom (\ref senf::ReadPolicyBase)
write() WritePolicy::write (\ref senf::WritePolicyBase)
writeto() WritePolicy::writeto (\ref senf::WritePolicyBase)
connect() AddressingPolicy::connect (\ref senf::AddressingPolicyBase)
bind() AddressingPolicy::bind (\ref senf::AddressingPolicyBase)
peer() AddressingPolicy::peer (\ref senf::AddressingPolicyBase)
local() AddressingPolicy::local (\ref senf::AddressingPolicyBase)
rcvbuf() BufferingPolicy::sndbuf (\ref senf::BufferingPolicyBase)
sndbuf() BufferingPolicy::rcvbuf (\ref senf::BufferingPolicyBase)
ClientSocketHandle member Policy member Other policies
read() ReadPolicy::read (\ref senf::ReadPolicyBase)
readfrom() ReadPolicy::readfrom (\ref senf::ReadPolicyBase) UnconnectedCommunicationPolicy
write() WritePolicy::write (\ref senf::WritePolicyBase) ConnectedCommunicationPolicy
writeto() WritePolicy::writeto (\ref senf::WritePolicyBase) UnconnectedCommunicationPolicy
connect() AddressingPolicy::connect (\ref senf::AddressingPolicyBase)
bind() AddressingPolicy::bind (\ref senf::AddressingPolicyBase)
peer() AddressingPolicy::peer (\ref senf::AddressingPolicyBase)
local() AddressingPolicy::local (\ref senf::AddressingPolicyBase)
It is important to note, that not all members are always accessible. Which are depends on @@ -79,26 +82,19 @@ namespace senf { typelist of Poclicy classes which can be accessed. You use protocol() to access a protocol class. \c Policies can of course be underspecified or even empty. - \idea add more flexible read/write members for a) boost::arrays and arrays of other types b) - std::vector (which uses contiguous memory ..) c) other random-access containers (we should - use some configurable trait class to identify containers with contiguous storage). Probably - we should just use a generic Boost.Range interface. Here we again come to the point: make - all except the most basic members be non-member algorithms ? this would make the - configuration of such extenden members more flexible. - \see \ref policy_group \n \ref protocol_group */ - template + template class ClientSocketHandle - : public SocketHandle + : public SocketHandle { public: /////////////////////////////////////////////////////////////////////////// // Types /// Address type from the addressing policy - typedef typename Policy::AddressingPolicy::Address Address; + typedef typename SPolicy::AddressingPolicy::Address Address; /// 'Best' type for passing address as parameter /** Depending on the type of \c Address, this will be either Address or Address const &. See ServerSocketHandle; + typedef ServerSocketHandle ServerHandle; /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ - // no default constructor + // default default constructor // default copy constructor // default copy assignment // default destructor + // here to implement + ClientSocketHandle(); + // conversion constructors +# ifndef DOXYGEN template ClientSocketHandle(ClientSocketHandle other, - typename SocketHandle::template IsCompatible::type * = 0); + typename SocketHandle::template IsCompatible::type * = 0); +# else + ClientSocketHandle(ClientSocketHandle other); +# endif +# ifndef DOXYGEN template - typename SocketHandle::template IsCompatible::type const & + typename SocketHandle::template IsCompatible::type const & operator=(ClientSocketHandle other); +# else + template + ClientSocketHandle const & operator=(ClientSocketHandle other); +# endif ///@} /////////////////////////////////////////////////////////////////////////// @@ -169,6 +177,11 @@ namespace senf { */ std::string read (unsigned limit=0); template +# ifndef DOXYGEN + typename boost::range_iterator::type + read (ForwardWritableRange const & range, + typename boost::disable_if< boost::is_convertible >::type * = 0); +# else typename boost::range_iterator::type read (ForwardWritableRange const & range); ///< Read data into range @@ -178,17 +191,26 @@ namespace senf { range. read returns a past-the-end iterator after the last character read. This iterator will point to somewhere within the input range. - \param[in/out] range Range to store data in + \param[in,out] range Range to store data in \returns past-the-end iterator pointer to after the last read character - \see \ref read() */ + \see \ref read() \n + Boost.Range */ +# endif +# ifndef DOXYGEN + template + typename boost::range_iterator::type + read (ForwardWritableRange & range, + typename boost::disable_if< boost::is_convertible >::type * = 0); +# else template typename boost::range_iterator::type read (ForwardWritableRange & range); ///< Read data into range - /**< \see - read(ForwardWritableRange const &) \n - read() */ + /**< \see read(ForwardWritableRange const &) \n + read() \n + Boost.Range */ +# endif template void read (Sequence & container, unsigned limit); ///< Read data into container @@ -229,7 +251,7 @@ namespace senf { std::pair readfrom (unsigned limit=0); template - typename boost::range_iterator::type + typename boost::range_iterator::type readfrom (ForwardWritableRange const & range, Address & from); ///< Read data into range /**< Read data into the given range. At most @@ -238,19 +260,20 @@ namespace senf { range. read returns a past-the-end iterator after the last character read. This iterator will point to somewhere within the input range. - \param[in/out] range Range to store data in + \param[in,out] range Range to store data in \param[out] from peers address from which the data was received \returns past-the-end iterator pointer to after the last read character - \see \ref readfrom() */ + \see \ref readfrom() \n + Boost.Range */ template typename boost::range_iterator::type readfrom (ForwardWritableRange & range, Address & from); ///< Read data into range - /**< \see - readfrom(ForwardWritableRange const&,Address&) \n - readfrom() */ + /**< \see readfrom(ForwardWritableRange const&,Address&) \n + readfrom() \n + Boost.Range */ template void readfrom (Sequence & container, Address & from, unsigned limit); ///< Read data into container @@ -265,14 +288,15 @@ namespace senf { \see \ref readfrom() */ char * readfrom (char * start, char * end, Address & from); ///< Read data into memory buffer - /**< This variant will read data into the memory area at \c - buffer of size \c size. This is the most performant - version of readfrom(). - \param[in] buffer address of buffer to store data at - \param[in] size size of buffer - \param[out] from peer address - \returns Number of bytes read - \see \ref readfrom() */ + /**< This variant will read data into the memory area from + \a start to before \a end. This is guaranteed to be the + most efficient version of readfrom(). + \param[in] start address of buffer to store data at + \param[in] end address one past the end of the buffer + \param[out] from peers address from which the data was + received + \returns pointer past the end of the data read + \see \ref read() */ /** \brief Write data to socket @@ -288,20 +312,23 @@ namespace senf { \throws senf::SystemException - This variant will write out the string \c data. + This variant will write out the range \c data. - \param[in] data Data to write - \returns number of bytes written + \param[in] range Data to write + \returns past-the-end iterator after last element written \implementation The write() family of members will use POSIX \c write calls, not \c send. */ - unsigned write (std::string const & data); - unsigned write (char const * buffer, unsigned size); + template + typename boost::range_const_iterator::type + write (ForwardReadableRange const & range); + char const * write (char const * start, char const * end); ///< Write data to socket from memory buffer - /**< \param[in] buffer address of buffer to write - \param[in] size amount of data to write - \returns Number of bytes written - \see \ref write() */ + /**< \param[in] start beginning of area to write + \param[in] end past-the-end pointer to area to write + \returns past-the-end pointer after last byte written + \see \ref write() \n + Boost.Range */ /** \brief Write data to unconnected socket @@ -315,20 +342,23 @@ namespace senf { \throw senf::SystemException - This variant will send the string \c data to the peer \c addr. + This variant will send the range \c range to peer \c addr. \param[in] addr Address of peer to send data to - \param[in] data data to send + \param[in] range data to send \returns Number of bytes written */ - unsigned writeto (AddressParam addr, std::string const & data); - unsigned writeto (AddressParam addr, char const * buffer, unsigned size); + template + typename boost::range_const_iterator::type + writeto (AddressParam addr, ForwardReadableRange const & range); + char const * writeto (AddressParam addr, char const * start, char const * end); ///< Write data from memory buffer to unconnected socket /**< \param[in] addr Address of peer to send data to - \param[in] buffer address of buffer to write - \param[in] size amount of data to write - \returns Number of bytes written - \see \ref writeto() */ + \param[in] start address of buffer to write + \param[in] end past-the-end pointer after data to write + \returns past-the-end iterator after last byte written + \see \ref writeto() \n + Boost.Range */ /////////////////////////////////////////////////////////////////////////// ///\name Addressing @@ -344,18 +374,18 @@ namespace senf { \throws senf::SystemException */ - void connect (AddressParam addr); + void connect (AddressParam addr) const; /** \brief Set local address For addressable protocols (AddressingPolicy is not NoAddressingPolicy), bind() will set the local address of the socket. - \param[in] addr Local socket address to asign + \param[in] addr Local socket address to assign \throws senf::SystemException */ - void bind (AddressParam addr); + void bind (AddressParam addr) const; /** \brief Query remote address @@ -368,8 +398,8 @@ namespace senf { \throws senf::SystemException */ - Address peer (); - void peer (Address & addr); + Address peer () const; + void peer (Address & addr) const; ///< Query remote address /**< \see \ref peer() */ @@ -383,31 +413,13 @@ namespace senf { \throws senf::SystemException */ - Address local (); - void local (Address & addr); + Address local () const; + void local (Address & addr) const; ///< Query local address /**< \see \ref local() */ ///@} - /////////////////////////////////////////////////////////////////////////// - ///\name Buffering - ///@{ - - unsigned rcvbuf (); ///< Check size of receive buffer - /**< \returns size of receive buffer in bytes */ - void rcvbuf (unsigned size); - ///< Set size of receive buffer - /**< \param[in] size size of receive buffer in bytes */ - - unsigned sndbuf (); ///< Check size of send buffer - /**< \returns size of send buffer in bytes */ - void sndbuf (unsigned size); - ///< Set size of send buffer - /**< \param[in] size size of send buffer in bytes */ - - ///@} - static ClientSocketHandle cast_static(FileHandle handle); static ClientSocketHandle cast_dynamic(FileHandle handle); @@ -415,15 +427,14 @@ namespace senf { void state(SocketStateMap & map, unsigned lod=0); std::string dumpState(unsigned lod=0); + unsigned available(); + protected: ClientSocketHandle(FileHandle other, bool isChecked); - explicit ClientSocketHandle(std::auto_ptr protocol, - int fd = -1); + explicit ClientSocketHandle(std::auto_ptr body); private: - unsigned available(); - - friend class senf::ServerSocketHandle; + friend class senf::ServerSocketHandle; }; /// @} @@ -442,4 +453,6 @@ namespace senf { // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: