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>
41 //#include "ReadWritePolicy.mpp"
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45 prefix_ unsigned senf::ReadablePolicy::read(FileHandle & handle, char * buffer,
50 rv = ::read(handle.fd(), buffer, size);
56 // This means, the socket is non-blocking an no data was available
60 SENF_THROW_SYSTEM_EXCEPTION(":::read");
66 prefix_ unsigned senf::ReadablePolicy::do_readfrom(FileHandle & handle, char * buffer,
68 struct ::sockaddr * addr, socklen_t * len)
72 rv = ::recvfrom(handle.fd(),buffer, size, 0, addr, len);
81 SENF_THROW_SYSTEM_EXCEPTION("::recvfrom");
87 prefix_ unsigned senf::WriteablePolicy::do_write(FileHandle & handle, char const * buffer,
92 rv = ::write(handle.fd(), buffer, size);
99 // According to the man page this should not happen, since packets are just silently being dropped.
100 // It does happen in NetEmu using small TxQueues on WLAN interfaces
102 // Writing to a UDP socket seems return this error code if a corresponding ICMP
103 // error code has been received before (at least on linux). This is inconsistent
104 // since I cannot rely on getting ECONNREFUSED. I therefore ignore this error. TCP
105 // sockets will return this error on connect() and not on write(). Therefore we can
106 // unconditionally ignore this error here.
110 SENF_THROW_SYSTEM_EXCEPTION("::write");
116 prefix_ unsigned senf::WriteablePolicy::do_writeto(FileHandle & handle,
117 char const * buffer, unsigned size,
118 struct sockaddr const * addr, socklen_t len)
122 rv = ::sendto(handle.fd(), buffer, size, 0, addr, len);
129 // According to the man page this should not happen, since packets are just silently being dropped.
130 // It does happen in NetEmu using small TxQueues on WLAN interfaces
134 SENF_THROW_SYSTEM_EXCEPTION("::sendto");
140 //-/////////////////////////////////////////////////////////////////////////////////////////////////
142 //#include "ReadWritePolicy.mpp"
148 // c-file-style: "senf"
149 // indent-tabs-mode: nil
150 // ispell-local-dictionary: "american"
151 // compile-command: "scons -u test"
152 // comment-column: 40