TCPSocketProtocol.cc
Go to the documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027 #include "TCPSocketProtocol.hh"
00028
00029
00030
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>
00036
00037
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
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116