4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief ReadPolicy and WritePolicy non-inline non-template implementation
32 #include "ReadWritePolicy.hh"
33 //#include "ReadWritePolicy.ih"
36 #include <sys/types.h>
37 #include <sys/socket.h>
42 //#include "ReadWritePolicy.mpp"
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 prefix_ unsigned senf::ReadablePolicy::read(FileHandle & handle, char * buffer,
51 rv = ::read(handle.fd(), buffer, size);
57 // This means, the socket is non-blocking an no data was available
61 SENF_THROW_SYSTEM_EXCEPTION("");
67 prefix_ unsigned senf::ReadablePolicy::do_readfrom(FileHandle & handle, char * buffer,
69 struct ::sockaddr * addr, socklen_t * len)
73 rv = ::recvfrom(handle.fd(),buffer, size, 0, addr, len);
82 SENF_THROW_SYSTEM_EXCEPTION("");
88 prefix_ unsigned senf::WriteablePolicy::do_write(FileHandle & handle, char const * buffer,
93 rv = ::write(handle.fd(), buffer, size);
100 // According to the man page this should not happen, since packets are just silently being dropped.
101 // It does happen in NetEmu using small TxQueues on WLAN interfaces
103 // Writing to a UDP socket seems return this error code if a corresponding ICMP
104 // error code has been received before (at least on linux). This is inconsistent
105 // since I cannot rely on getting ECONNREFUSED. I therefore ignore this error. TCP
106 // sockets will return this error on connect() and not on write(). Therefore we can
107 // unconditionally ignore this error here.
111 SENF_THROW_SYSTEM_EXCEPTION("");
117 prefix_ unsigned senf::WriteablePolicy::do_writeto(FileHandle & handle,
118 char const * buffer, unsigned size,
119 struct sockaddr const * addr, socklen_t len)
123 rv = ::sendto(handle.fd(), buffer, size, 0, addr, len);
130 // According to the man page this should not happen, since packets are just silently being dropped.
131 // It does happen in NetEmu using small TxQueues on WLAN interfaces
135 SENF_THROW_SYSTEM_EXCEPTION("");
141 //-/////////////////////////////////////////////////////////////////////////////////////////////////
143 //#include "ReadWritePolicy.mpp"
149 // c-file-style: "senf"
150 // indent-tabs-mode: nil
151 // ispell-local-dictionary: "american"
152 // compile-command: "scons -u test"
153 // comment-column: 40