5945590b6151b4898d0873e52c99e885aa25b5ac
[senf.git] / senf / Socket / CommunicationPolicy.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief CommunicationPolicy non-inline non-template implementation
25  */
26
27 #include "CommunicationPolicy.hh"
28 //#include "CommunicationPolicy.ih"
29
30 // Custom includes
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <errno.h>
34 #include <senf/Utils/Exception.hh>
35
36 //#include "CommunicationPolicy.mpp"
37 #define prefix_
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 prefix_ void senf::ConnectedCommunicationPolicy::do_listen(FileHandle const & handle,
41                                                            unsigned backlog)
42 {
43     ::listen(handle.fd(),backlog);
44 }
45
46 prefix_ int senf::ConnectedCommunicationPolicy::do_accept(FileHandle const & handle,
47                                                           struct sockaddr * addr,
48                                                           unsigned len)
49 {
50     int rv = -1;
51     do {
52         rv = ::accept(handle.fd(),addr,&len);
53         if (rv < 0)
54             switch (errno) {
55             case EWOULDBLOCK:
56                 return -1;
57             case EINTR:
58                 break;
59             default:
60                 SENF_THROW_SYSTEM_EXCEPTION("ConnectedCommunicationPolicy::do_accept failed.");
61             }
62     } while (rv<0);
63     return rv;
64 }
65
66 //-/////////////////////////////////////////////////////////////////////////////////////////////////
67 #undef prefix_
68 //#include "CommunicationPolicy.mpp"
69
70 \f
71 // Local Variables:
72 // mode: c++
73 // fill-column: 100
74 // c-file-style: "senf"
75 // indent-tabs-mode: nil
76 // ispell-local-dictionary: "american"
77 // compile-command: "scons -u test"
78 // comment-column: 40
79 // End: