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 "senf/Utils/hexdump.hh"
34 #include "senf/Utils/String.hh"
35 //#include "ReadWritePolicy.ih"
38 #include <sys/types.h>
39 #include <sys/socket.h>
43 //#include "ReadWritePolicy.mpp"
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 prefix_ unsigned senf::ReadablePolicy::read(FileHandle & handle, char * buffer,
52 rv = ::read(handle.fd(), buffer, size);
58 // This means, the socket is non-blocking an no data was available
62 SENF_THROW_SYSTEM_EXCEPTION(":::read");
68 prefix_ unsigned senf::ReadablePolicy::do_readfrom(FileHandle & handle, char * buffer,
70 struct ::sockaddr * addr, socklen_t * len)
74 rv = ::recvfrom(handle.fd(),buffer, size, 0, addr, len);
83 SENF_THROW_SYSTEM_EXCEPTION("::recvfrom");
89 prefix_ unsigned senf::WriteablePolicy::do_write(FileHandle & handle, char const * buffer,
94 rv = ::write(handle.fd(), buffer, size);
101 // According to the man page this should not happen, since packets are just silently being dropped.
102 // It does happen in NetEmu using small TxQueues on WLAN interfaces
104 // Writing to a UDP socket seems return this error code if a corresponding ICMP
105 // error code has been received before (at least on linux). This is inconsistent
106 // since I cannot rely on getting ECONNREFUSED. I therefore ignore this error. TCP
107 // sockets will return this error on connect() and not on write(). Therefore we can
108 // unconditionally ignore this error here.
112 SENF_THROW_SYSTEM_EXCEPTION("::write");
118 prefix_ unsigned senf::WriteablePolicy::do_writeto(FileHandle & handle,
119 char const * buffer, unsigned size,
120 struct sockaddr const * addr, socklen_t len)
124 rv = ::sendto(handle.fd(), buffer, size, 0, addr, len);
131 // According to the man page this should not happen, since packets are just silently being dropped.
132 // It does happen in NetEmu using small TxQueues on WLAN interfaces
136 std::stringstream a, b;
137 senf::hexdump( (char*) addr , ((char*) addr) + len , a);
138 senf::hexdump( (char*) buffer , ((char*) buffer) + size , b);
139 SENF_THROW_SYSTEM_EXCEPTION("::sendto(" + senf::str(b) + ") to " + senf::str(a));
145 //-/////////////////////////////////////////////////////////////////////////////////////////////////
147 //#include "ReadWritePolicy.mpp"
153 // c-file-style: "senf"
154 // indent-tabs-mode: nil
155 // ispell-local-dictionary: "american"
156 // compile-command: "scons -u test"
157 // comment-column: 40