fed45163733787be0256897a1174473262c1c6f3
[senf.git] / Socket / Protocols / INet / TCPProtocol.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY 
6 //     Stefan Bund <g0dil@berlios.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 TCPProtocol non-inline non-template implementation
25  */
26
27 #include "TCPProtocol.hh"
28 //#include "TCPProtocol.ih"
29
30 // Custom includes
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <netinet/tcp.h>
34 #include <sys/ioctl.h>
35 #include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
36 #include "../../../Socket/SocketHandle.hh"
37
38 //#include "TCPProtocol.mpp"
39 #define prefix_
40 ///////////////////////////////cc.p////////////////////////////////////////
41
42 prefix_ bool senf::TCPProtocol::nodelay()
43     const
44 {
45     int value;
46     socklen_t len (sizeof(value));
47     if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
48         throwErrno();
49     return value;
50 }
51
52 prefix_ void senf::TCPProtocol::nodelay(bool value)
53     const
54 {
55     int ivalue (value);
56     if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
57         throwErrno();
58 }
59
60 prefix_ unsigned senf::TCPProtocol::siocinq()
61     const
62 {
63     int n;
64     if (::ioctl(fd(),SIOCINQ,&n) < 0)
65         throwErrno();
66     return n;
67 }
68
69 prefix_ unsigned senf::TCPProtocol::siocoutq()
70     const
71 {
72     int n;
73     if (::ioctl(fd(),SIOCOUTQ,&n) < 0)
74         throwErrno();
75     return n;
76 }
77
78 prefix_ unsigned senf::TCPProtocol::available()
79     const
80 {
81     return siocinq();
82 }
83
84 prefix_ bool senf::TCPProtocol::eof()
85     const
86 {
87     return fh().readable() && available()==0;
88 }
89
90
91 ///////////////////////////////cc.e////////////////////////////////////////
92 #undef prefix_
93 //#include "TCPProtocol.mpp"
94
95 \f
96 // Local Variables:
97 // mode: c++
98 // fill-column: 100
99 // c-file-style: "senf"
100 // indent-tabs-mode: nil
101 // ispell-local-dictionary: "american"
102 // compile-command: "scons -u test"
103 // comment-column: 40
104 // End: