bc2fa337bf7a8b521d367874506991e454f527a4
[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 // Definition of non-inline non-template functions
24
25 #include "CommunicationPolicy.hh"
26 //#include "CommunicationPolicy.ih"
27
28 // Custom includes
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <errno.h>
32 #include "Utils/Exception.hh"
33 #include "ServerSocketHandle.hh"
34
35 //#include "CommunicationPolicy.mpp"
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 prefix_ void satcom::lib::ConnectedCommunicationPolicy::listen(FileHandle handle,
40                                                                unsigned backlog)
41 {
42     ::listen(handle.fd(),backlog);
43 }
44
45 prefix_ int satcom::lib::ConnectedCommunicationPolicy::do_accept(FileHandle handle,
46                                                                  struct sockaddr * addr,
47                                                                  unsigned len)
48 {
49     int rv = -1;
50     do {
51         rv = ::accept(handle.fd(),addr,&len);
52         if (rv < 0)
53             switch (errno) {
54             case EWOULDBLOCK:
55                 return -1;
56             case EINTR:
57                 break;
58             default:
59                 throw SystemException(errno);
60             }
61     } while (rv<0);
62     return rv;
63 }
64
65 ///////////////////////////////cc.e////////////////////////////////////////
66 #undef prefix_
67 //#include "CommunicationPolicy.mpp"
68
69 \f
70 // Local Variables:
71 // mode: c++
72 // c-file-style: "satcom"
73 // End: