TCPSocketProtocol.cc

Go to the documentation of this file.
00001 // $Id: TCPSocketProtocol.cc 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2006
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00027 #include "TCPSocketProtocol.hh"
00028 //#include "TCPSocketProtocol.ih"
00029 
00030 // Custom includes
00031 #include <sys/socket.h>
00032 #include <netinet/in.h>
00033 #include <netinet/tcp.h>
00034 #include <sys/ioctl.h>
00035 #include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
00036 
00037 //#include "TCPSocketProtocol.mpp"
00038 #define prefix_
00039 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00040 
00041 prefix_ bool senf::TCPSocketProtocol::nodelay()
00042     const
00043 {
00044     int value;
00045     socklen_t len (sizeof(value));
00046     if (::getsockopt(fd(),SOL_TCP,TCP_NODELAY,&value,&len) < 0)
00047         SENF_THROW_SYSTEM_EXCEPTION("");
00048     return value;
00049 }
00050 
00051 prefix_ void senf::TCPSocketProtocol::nodelay(bool value)
00052     const
00053 {
00054     int ivalue (value);
00055     if (::setsockopt(fd(),SOL_TCP,TCP_NODELAY,&ivalue,sizeof(ivalue)) < 0)
00056         SENF_THROW_SYSTEM_EXCEPTION("");
00057 }
00058 
00059 prefix_ unsigned senf::TCPSocketProtocol::siocinq()
00060     const
00061 {
00062     int n;
00063     if (::ioctl(fd(),SIOCINQ,&n) < 0)
00064         SENF_THROW_SYSTEM_EXCEPTION("");
00065     return n;
00066 }
00067 
00068 prefix_ unsigned senf::TCPSocketProtocol::siocoutq()
00069     const
00070 {
00071     int n;
00072     if (::ioctl(fd(),SIOCOUTQ,&n) < 0)
00073         SENF_THROW_SYSTEM_EXCEPTION("");
00074     return n;
00075 }
00076 
00077 prefix_ void senf::TCPSocketProtocol::shutdown(ShutType type)
00078     const
00079 {
00080     if (::shutdown(fd(), type) < 0)
00081         SENF_THROW_SYSTEM_EXCEPTION("::shutdown()");
00082 }
00083 
00084 prefix_ void senf::TCPSocketProtocol::close()
00085 {
00086     shutdown(ShutRDWR);
00087     INetSocketProtocol::close();
00088 }
00089 
00090 prefix_ unsigned senf::TCPSocketProtocol::available()
00091     const
00092 {
00093     return siocinq();
00094 }
00095 
00096 prefix_ bool senf::TCPSocketProtocol::eof()
00097     const
00098 {
00099     return fh().readable() && available()==0;
00100 }
00101 
00102 
00103 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00104 #undef prefix_
00105 //#include "TCPSocketProtocol.mpp"
00106 
00107 
00108 // Local Variables:
00109 // mode: c++
00110 // fill-column: 100
00111 // c-file-style: "senf"
00112 // indent-tabs-mode: nil
00113 // ispell-local-dictionary: "american"
00114 // compile-command: "scons -u test"
00115 // comment-column: 40
00116 // End: