X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FSocket%2FReadWritePolicy.hh;fp=senf%2FSocket%2FReadWritePolicy.hh;h=24d5cea6bf246a5e8c1bf9bd37d13ee35c8e9902;hb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;hp=0000000000000000000000000000000000000000;hpb=164fe477094d42463722584e527a02379ab5d985;p=senf.git diff --git a/senf/Socket/ReadWritePolicy.hh b/senf/Socket/ReadWritePolicy.hh new file mode 100644 index 0000000..24d5cea --- /dev/null +++ b/senf/Socket/ReadWritePolicy.hh @@ -0,0 +1,181 @@ +// $Id$ +// +// Copyright (C) 2006 +// 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief ReadPolicy and WritePolicy public header + + \todo ReadWritePolicy.test.cc + */ + +#ifndef HH_SENF_Socket_ReadWritePolicy_ +#define HH_SENF_Socket_ReadWritePolicy_ 1 + +// Custom includes +#include "SocketPolicy.hh" +#include "ClientSocketHandle.hh" +#include "CommunicationPolicy.hh" + +//#include "ReadWritePolicy.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + + +struct sockaddr; + +namespace senf { + + /// \addtogroup policy_impl_group + /// @{ + + /** \brief ReadPolicy for readable sockets + + This policy provides support for readable sockets via the standard UNIX read/recvfrom system + calls. The concrete semantics of the read calls depend on the framing policy of the socket. + */ + struct ReadablePolicy : public ReadPolicyBase + { + static unsigned read(FileHandle handle, char * buffer, unsigned size); + ///< read data from socket + /**< \param[in] handle socket handle to read from + \param[in] buffer address of buffer to write data to + \param[in] size size of buffer + \returns number of bytes read */ +# ifndef DOXYGEN + template + static unsigned readfrom(ClientSocketHandle handle, char * buffer, unsigned size, + typename SPolicy::AddressingPolicy::Address & address, + typename IfCommunicationPolicyIs< + SPolicy,UnconnectedCommunicationPolicy>::type * = 0); +# else + template + static unsigned readfrom(ClientSocketHandle handle, char * buffer, unsigned size, + typename Policy::AddressingPolicy::Address & address); + ///< read data from socket returning peer address + /**< \param[in] handle socket handle to read from + \param[in] buffer address of buffer to write data to + \param[in] size size of buffer + \param[out] address peer address + \returns number of bytes read */ +# endif + + private: + static unsigned do_readfrom(FileHandle handle, char * buffer, unsigned size, + struct ::sockaddr * addr, socklen_t * len); + }; + + /** \brief ReadPolicy for unreadable sockets + + This is different from UndefinedReadPolicy (which is the same as ReadPolicyBase). This + policy class defines the socket readability -- it explicitly states, that the socket does + not support reading. + */ + struct NotReadablePolicy : public ReadPolicyBase + {}; + + /** \brief WritePolicy for writeable sockets + + This policy provides support for writable sockets via the standard UNIX write/sendto system + calls. The concrete semantics of the write calls depend on the framing policy of the socket. + */ + struct WriteablePolicy : public WritePolicyBase + { +# ifndef DOXYGEN + template + static unsigned write(ClientSocketHandle handle, char const * buffer, unsigned size, + typename IfCommunicationPolicyIs< + SPolicy,ConnectedCommunicationPolicy>::type * = 0); +# else + template + static unsigned write(ClientSocketHandle handle, char const * buffer, + unsigned size); + ///< write data to socket + /**< This member is only enabled if the socket uses + connected communication. Otherwise the communication + partner must be specified explicitly using the sendto + call + + \param[in] handle socket handle to write data to + \param[in] buffer address of buffer to send + \param[in] size number of bytes to write + \returns number of bytes written */ +# endif +# ifndef DOXYGEN + template + static unsigned writeto(ClientSocketHandle handle, + typename boost::call_traits< + typename SPolicy::AddressingPolicy::Address>::param_type addr, + char const * buffer, unsigned size, + typename IfCommunicationPolicyIs< + SPolicy,UnconnectedCommunicationPolicy>::type * = 0); +# else + template + static unsigned writeto(ClientSocketHandle handle, + typename Policy::AddressingPolicy::Address const & addr, + char const * buffer, unsigned size); + ///< write data to socket sending to given peer + /**< This member is only enabled if the socket uses + unconnected communication. Otherwise no target may be + specified since it is implied in the connection. + + \param[in] handle socket handle to write data to + \param[in] buffer address of buffer to send + \param[in] size number of bytes to write + \param[in] addr peer to send data to + \returns number of bytes written + */ +# endif + + private: + static unsigned do_write(FileHandle handle, char const * buffer, unsigned size); + static unsigned do_writeto(FileHandle handle, char const * buffer, unsigned size, + struct sockaddr const * addr, socklen_t len); + }; + + /** \brief WritePolicy for unwriteable sockets + + This is different from UndefinedWritePolicy (which is the same as WritePolicyBase). This + policy class defines the socket writeability -- it explicitly states, that the socket does + not support writing. + */ + struct NotWriteablePolicy : public WritePolicyBase + {}; + + /// @} + +} + + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "ReadWritePolicy.cci" +//#include "ReadWritePolicy.ct" +#include "ReadWritePolicy.cti" +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: