Utils: Implement more flexible SystemException
[senf.git] / Socket / CommunicationPolicy.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 "../Utils/Exception.hh"
35 #include "ServerSocketHandle.hh"
36
37 //#include "CommunicationPolicy.mpp"
38 #define prefix_
39 ///////////////////////////////cc.p////////////////////////////////////////
40
41 prefix_ void senf::ConnectedCommunicationPolicy::do_listen(FileHandle handle,
42                                                            unsigned backlog)
43 {
44     ::listen(handle.fd(),backlog);
45 }
46
47 prefix_ int senf::ConnectedCommunicationPolicy::do_accept(FileHandle handle,
48                                                           struct sockaddr * addr,
49                                                           unsigned len)
50 {
51     int rv = -1;
52     do {
53         rv = ::accept(handle.fd(),addr,&len);
54         if (rv < 0)
55             switch (errno) {
56             case EWOULDBLOCK:
57                 return -1;
58             case EINTR:
59                 break;
60             default:
61                 throwErrno();
62             }
63     } while (rv<0);
64     return rv;
65 }
66
67 ///////////////////////////////cc.e////////////////////////////////////////
68 #undef prefix_
69 //#include "CommunicationPolicy.mpp"
70
71 \f
72 // Local Variables:
73 // mode: c++
74 // fill-column: 100
75 // c-file-style: "senf"
76 // indent-tabs-mode: nil
77 // ispell-local-dictionary: "american"
78 // compile-command: "scons -u test"
79 // comment-column: 40
80 // End: