00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #include "BSDSocketProtocol.hh"
00027
00028
00029
00030 #include <sys/types.h>
00031 #include <sys/socket.h>
00032 #include <sys/ioctl.h>
00033
00034
00035 #define prefix_
00036
00037
00038 prefix_ std::pair<bool,unsigned> senf::BSDSocketProtocol::linger()
00039 const
00040 {
00041 struct linger ling;
00042 socklen_t len = sizeof(ling);
00043 ::memset(&ling, 0, sizeof(ling));
00044 if (::getsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,&len) < 0)
00045 SENF_THROW_SYSTEM_EXCEPTION("");
00046 return std::make_pair(ling.l_onoff, ling.l_linger);
00047 }
00048
00049 prefix_ void senf::BSDSocketProtocol::linger(bool enable, unsigned timeout)
00050 const
00051 {
00052 struct linger ling;
00053 ling.l_onoff = enable;
00054 ling.l_linger = timeout;
00055 if (::setsockopt(fd(),SOL_SOCKET,SO_LINGER,&ling,sizeof(ling)) < 0)
00056 SENF_THROW_SYSTEM_EXCEPTION("");
00057 }
00058
00059 prefix_ boost::uint8_t senf::BSDSocketProtocol::priority()
00060 const
00061 {
00062 int value;
00063 socklen_t len (sizeof(value));
00064 if (::getsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&value,&len) < 0)
00065 SENF_THROW_SYSTEM_EXCEPTION("");
00066 return value;
00067 }
00068
00069 prefix_ void senf::BSDSocketProtocol::priority(boost::uint8_t value)
00070 const
00071 {
00072 int ivalue (value);
00073 if (::setsockopt(fd(),SOL_SOCKET,SO_PRIORITY,&ivalue,sizeof(ivalue)) < 0)
00074 SENF_THROW_SYSTEM_EXCEPTION("");
00075 }
00076
00077 prefix_ int senf::BSDSocketProtocol::error()
00078 const
00079 {
00080 int err;
00081 socklen_t len (sizeof(err));
00082 if (::getsockopt(fd(),SOL_SOCKET,SO_ERROR,&err,&len) < 0)
00083 SENF_THROW_SYSTEM_EXCEPTION("");
00084 return err;
00085 }
00086
00087 prefix_ unsigned senf::BSDSocketProtocol::rcvbuf()
00088 const
00089 {
00090 unsigned size;
00091 socklen_t len (sizeof(size));
00092 if (::getsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,&len) < 0)
00093 SENF_THROW_SYSTEM_EXCEPTION("");
00094
00095
00096 return size/2;
00097 }
00098
00099 prefix_ void senf::BSDSocketProtocol::rcvbuf(unsigned size)
00100 const
00101 {
00102 if (::setsockopt(fd(),SOL_SOCKET,SO_RCVBUF,&size,sizeof(size)) < 0)
00103 SENF_THROW_SYSTEM_EXCEPTION("");
00104 }
00105
00106 prefix_ unsigned senf::BSDSocketProtocol::sndbuf()
00107 const
00108 {
00109 unsigned size;
00110 socklen_t len (sizeof(size));
00111 if (::getsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,&len) < 0)
00112 SENF_THROW_SYSTEM_EXCEPTION("");
00113
00114
00115 return size/2;
00116 }
00117
00118 prefix_ void senf::BSDSocketProtocol::sndbuf(unsigned size)
00119 const
00120 {
00121 if (::setsockopt(fd(),SOL_SOCKET,SO_SNDBUF,&size,sizeof(size)) < 0)
00122 SENF_THROW_SYSTEM_EXCEPTION("");
00123 }
00124
00125
00126
00127 prefix_ bool senf::AddressableBSDSocketProtocol::reuseaddr()
00128 const
00129 {
00130 int value;
00131 socklen_t len (sizeof(value));
00132 if (::getsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&value,&len) < 0)
00133 SENF_THROW_SYSTEM_EXCEPTION("");
00134 return value;
00135 }
00136
00137 prefix_ void senf::AddressableBSDSocketProtocol::reuseaddr(bool value)
00138 const
00139 {
00140 int ivalue (value);
00141 if (::setsockopt(fd(),SOL_SOCKET,SO_REUSEADDR,&ivalue,sizeof(ivalue)) < 0)
00142 SENF_THROW_SYSTEM_EXCEPTION("");
00143 }
00144
00145
00146 #undef prefix_
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158