git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@129 270642c3-0616-0410...
[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                 break;
57             case EINTR:
58                 break;
59             default:
60                 throw SystemException(errno);
61             }
62     } while (rv<0);
63     return rv;
64 }
65
66 ///////////////////////////////cc.e////////////////////////////////////////
67 #undef prefix_
68 //#include "CommunicationPolicy.mpp"
69
70 \f
71 // Local Variables:
72 // mode: c++
73 // c-file-style: "satcom"
74 // End: