more usable unix sockets classes
[senf.git] / Socket / Protocols / UN / UNProtocol.cc
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum NETwork research (NET)
4 //     David Wagner <david.wagner@fokus.fraunhofer.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief UNProtocol non-inline non-template implementation */
23
24 #include "UNProtocol.hh"
25 //#include "UNProtocol.ih"
26
27 // Custom includes
28 #include <sys/socket.h>
29 #include <sys/ioctl.h>
30 #include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
31 #include "../../../Utils/Exception.hh"
32
33 //#include "UNProtocol.mpp"
34 #define prefix_
35 ///////////////////////////////cc.p////////////////////////////////////////
36 prefix_ unsigned senf::UNProtocol::available()
37     const
38 {
39     int n;
40     if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
41         throw senf::SystemException(errno);
42     return n;
43 }
44
45 prefix_ bool senf::UNProtocol::eof()
46     const
47 {
48     return false;
49 }
50
51 prefix_ void senf::UNProtocol::connect(UNSocketAddress const & address) 
52     const 
53 {
54     if(::connect(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
55         throw SystemException(errno);
56 }
57
58 prefix_ void senf::UNProtocol::bind(UNSocketAddress const & address) 
59     const 
60 {
61     if(::bind(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
62         throw SystemException(errno);
63 }
64
65
66
67
68
69 ///////////////////////////////cc.e////////////////////////////////////////
70 #undef prefix_
71 //#include "UNProtocol.mpp"
72
73 \f
74 // Local Variables:
75 // mode: c++
76 // fill-column: 100
77 // comment-column: 40
78 // c-file-style: "senf"
79 // indent-tabs-mode: nil
80 // ispell-local-dictionary: "american"
81 // compile-command: "scons -u test"
82 // End: