summaryrefslogtreecommitdiff
path: root/PracticalSocket.cpp
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-02-28 23:18:08 +0000
committerChristian Pointner <equinox@anytun.org>2008-02-28 23:18:08 +0000
commit63a7daa4f27a83bf49ce7ffaf95b68c4a0e15231 (patch)
tree6e3bedbfb872b8cd5638810082e60eff0f6344e4 /PracticalSocket.cpp
parentfixed (diff)
anyrtpproxy finished ??
Diffstat (limited to 'PracticalSocket.cpp')
-rw-r--r--PracticalSocket.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/PracticalSocket.cpp b/PracticalSocket.cpp
index 658bc6e..5d39557 100644
--- a/PracticalSocket.cpp
+++ b/PracticalSocket.cpp
@@ -186,6 +186,14 @@ void Socket::setLocalAddressAndPort(const string &localAddress,
}
}
+void Socket::setSocketOpt(int optionName, const void* optionValue, socklen_t optionLen)
+ throw(SocketException)
+{
+ if (::setsockopt(sockDesc, SOL_SOCKET, optionName, optionValue, optionLen) < 0) {
+ throw SocketException("setSockopt failed", true);
+ }
+}
+
void Socket::cleanUp() throw(SocketException) {
#ifdef WIN32
if (WSACleanup() != 0) {
@@ -282,6 +290,8 @@ TCPSocket::TCPSocket(int newConnSD) : CommunicatingSocket(newConnSD) {
TCPServerSocket::TCPServerSocket(unsigned short localPort, int queueLen)
throw(SocketException) : Socket(SOCK_STREAM, IPPROTO_TCP) {
+ const int opt = 1;
+ setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt));
setLocalPort(localPort);
setListen(queueLen);
}
@@ -289,6 +299,8 @@ TCPServerSocket::TCPServerSocket(unsigned short localPort, int queueLen)
TCPServerSocket::TCPServerSocket(const string &localAddress,
unsigned short localPort, int queueLen)
throw(SocketException) : Socket(SOCK_STREAM, IPPROTO_TCP) {
+ const int opt = 1;
+ setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt));
setLocalAddressAndPort(localAddress, localPort);
setListen(queueLen);
}
@@ -312,17 +324,24 @@ void TCPServerSocket::setListen(int queueLen) throw(SocketException) {
UDPSocket::UDPSocket() throw(SocketException) : CommunicatingSocket(SOCK_DGRAM,
IPPROTO_UDP) {
+
+ const int opt = 1;
+ setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt));
setBroadcast();
}
UDPSocket::UDPSocket(unsigned short localPort) throw(SocketException) :
CommunicatingSocket(SOCK_DGRAM, IPPROTO_UDP) {
+ const int opt = 1;
+ setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt));
setLocalPort(localPort);
setBroadcast();
}
UDPSocket::UDPSocket(const string &localAddress, unsigned short localPort)
throw(SocketException) : CommunicatingSocket(SOCK_DGRAM, IPPROTO_UDP) {
+ const int opt = 1;
+ setSocketOpt(SO_REUSEADDR, &opt, sizeof(opt));
setLocalAddressAndPort(localAddress, localPort);
setBroadcast();
}