246eacd17cc6485a6dd277c8445ec6fb3ce3b9ab
[senf.git] / Socket / TCPProtocol.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 "TCPProtocol.hh"
26 //#include "TCPProtocol.ih"
27
28 // Custom includes
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <netinet/tcp.h>
32 #include <sys/ioctl.h>
33 #include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
34 #include "SocketHandle.hh"
35
36 //#include "TCPProtocol.mpp"
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 prefix_ bool senf::TCPProtocol::nodelay()
41     const
42 {
43     int value;
44     socklen_t len (sizeof(value));
45     if (::getsockopt(body().fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
46         throw SystemException(errno);
47     return value;
48 }
49
50 prefix_ void senf::TCPProtocol::nodelay(bool value)
51     const
52 {
53     int ivalue (value);
54     if (::setsockopt(body().fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
55         throw SystemException(errno);
56 }
57
58 prefix_ unsigned senf::TCPProtocol::siocinq()
59     const
60 {
61     int n;
62     if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
63         throw SystemException(errno);
64     return n;
65 }
66
67 prefix_ unsigned senf::TCPProtocol::siocoutq()
68     const
69 {
70     int n;
71     if (::ioctl(body().fd(),SIOCOUTQ,&n) < 0)
72         throw SystemException(errno);
73     return n;
74 }
75
76 prefix_ unsigned senf::TCPProtocol::available()
77     const
78 {
79     return siocinq();
80 }
81
82 prefix_ bool senf::TCPProtocol::eof()
83     const
84 {
85     return body().readable() && available()==0;
86 }
87
88
89 ///////////////////////////////cc.e////////////////////////////////////////
90 #undef prefix_
91 //#include "TCPProtocol.mpp"
92
93 \f
94 // Local Variables:
95 // mode: c++
96 // c-file-style: "senf"
97 // End: