aboutsummaryrefslogtreecommitdiff
path: root/dep/src/sockets/UdpSocket.cpp
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:35:07 -0700
committermaximius <none@none>2009-10-17 15:35:07 -0700
commit26b5e033ffde3d161382fc9addbfa99738379641 (patch)
treea344f369ca32945f787a02dee35c3dbe342bed7e /dep/src/sockets/UdpSocket.cpp
parentf21f47005dcb6b76e1abc9f35fbcd03eed191bff (diff)
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
Diffstat (limited to 'dep/src/sockets/UdpSocket.cpp')
-rw-r--r--dep/src/sockets/UdpSocket.cpp59
1 files changed, 0 insertions, 59 deletions
diff --git a/dep/src/sockets/UdpSocket.cpp b/dep/src/sockets/UdpSocket.cpp
index f4c3d2f9657..f1abe54a1a8 100644
--- a/dep/src/sockets/UdpSocket.cpp
+++ b/dep/src/sockets/UdpSocket.cpp
@@ -4,25 +4,20 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
-
This library is made available under the terms of the GNU GPL.
-
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
-
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
-
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -35,7 +30,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#else
#include <errno.h>
#endif
-
#include "ISocketHandler.h"
#include "UdpSocket.h"
#include "Utility.h"
@@ -47,12 +41,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// include this to see strange sights
//#include <linux/in6.h>
-
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
-
UdpSocket::UdpSocket(ISocketHandler& h, int ibufsz, bool ipv6, int retries) : Socket(h)
, m_ibuf(new char[ibufsz])
, m_ibufsz(ibufsz)
@@ -69,14 +61,12 @@ UdpSocket::UdpSocket(ISocketHandler& h, int ibufsz, bool ipv6, int retries) : So
#endif
}
-
UdpSocket::~UdpSocket()
{
Close();
delete[] m_ibuf;
}
-
int UdpSocket::Bind(port_t &port, int range)
{
#ifdef ENABLE_IPV6
@@ -92,7 +82,6 @@ int UdpSocket::Bind(port_t &port, int range)
return Bind(ad, range);
}
-
int UdpSocket::Bind(const std::string& intf, port_t &port, int range)
{
#ifdef ENABLE_IPV6
@@ -118,14 +107,12 @@ int UdpSocket::Bind(const std::string& intf, port_t &port, int range)
return -1;
}
-
int UdpSocket::Bind(ipaddr_t a, port_t &port, int range)
{
Ipv4Address ad(a, port);
return Bind(ad, range);
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
int UdpSocket::Bind(in6_addr a, port_t &port, int range)
@@ -136,7 +123,6 @@ int UdpSocket::Bind(in6_addr a, port_t &port, int range)
#endif
#endif
-
int UdpSocket::Bind(SocketAddress& ad, int range)
{
if (GetSocket() == INVALID_SOCKET)
@@ -169,7 +155,6 @@ int UdpSocket::Bind(SocketAddress& ad, int range)
return -1;
}
-
/** if you wish to use Send, first Open a connection */
bool UdpSocket::Open(ipaddr_t l, port_t port)
{
@@ -177,7 +162,6 @@ bool UdpSocket::Open(ipaddr_t l, port_t port)
return Open(ad);
}
-
bool UdpSocket::Open(const std::string& host, port_t port)
{
#ifdef ENABLE_IPV6
@@ -201,7 +185,6 @@ bool UdpSocket::Open(const std::string& host, port_t port)
return false;
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
bool UdpSocket::Open(struct in6_addr& a, port_t port)
@@ -212,7 +195,6 @@ bool UdpSocket::Open(struct in6_addr& a, port_t port)
#endif
#endif
-
bool UdpSocket::Open(SocketAddress& ad)
{
if (GetSocket() == INVALID_SOCKET)
@@ -234,7 +216,6 @@ bool UdpSocket::Open(SocketAddress& ad)
return false;
}
-
void UdpSocket::CreateConnection()
{
#ifdef ENABLE_IPV6
@@ -267,7 +248,6 @@ void UdpSocket::CreateConnection()
}
}
-
/** send to specified address */
void UdpSocket::SendToBuf(const std::string& h, port_t p, const char *data, int len, int flags)
{
@@ -291,7 +271,6 @@ void UdpSocket::SendToBuf(const std::string& h, port_t p, const char *data, int
}
}
-
/** send to specified address */
void UdpSocket::SendToBuf(ipaddr_t a, port_t p, const char *data, int len, int flags)
{
@@ -299,7 +278,6 @@ void UdpSocket::SendToBuf(ipaddr_t a, port_t p, const char *data, int len, int f
SendToBuf(ad, data, len, flags);
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
void UdpSocket::SendToBuf(in6_addr a, port_t p, const char *data, int len, int flags)
@@ -310,7 +288,6 @@ void UdpSocket::SendToBuf(in6_addr a, port_t p, const char *data, int len, int f
#endif
#endif
-
void UdpSocket::SendToBuf(SocketAddress& ad, const char *data, int len, int flags)
{
if (GetSocket() == INVALID_SOCKET)
@@ -327,19 +304,16 @@ void UdpSocket::SendToBuf(SocketAddress& ad, const char *data, int len, int flag
}
}
-
void UdpSocket::SendTo(const std::string& a, port_t p, const std::string& str, int flags)
{
SendToBuf(a, p, str.c_str(), (int)str.size(), flags);
}
-
void UdpSocket::SendTo(ipaddr_t a, port_t p, const std::string& str, int flags)
{
SendToBuf(a, p, str.c_str(), (int)str.size(), flags);
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
void UdpSocket::SendTo(in6_addr a, port_t p, const std::string& str, int flags)
@@ -349,13 +323,11 @@ void UdpSocket::SendTo(in6_addr a, port_t p, const std::string& str, int flags)
#endif
#endif
-
void UdpSocket::SendTo(SocketAddress& ad, const std::string& str, int flags)
{
SendToBuf(ad, str.c_str(), (int)str.size(), flags);
}
-
/** send to connected address */
void UdpSocket::SendBuf(const char *data, size_t len, int flags)
{
@@ -370,13 +342,11 @@ void UdpSocket::SendBuf(const char *data, size_t len, int flags)
}
}
-
void UdpSocket::Send(const std::string& str, int flags)
{
SendBuf(str.c_str(), (int)str.size(), flags);
}
-
#if defined(LINUX) || defined(MACOSX)
int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen_t fromlen, struct timeval *ts)
{
@@ -397,15 +367,12 @@ int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen
} cmsg_un;
struct cmsghdr *cmsg;
struct timeval *tv;
-
vec[0].iov_base = ioBuf;
vec[0].iov_len = inBufSize;
-
memset(&msg, 0, sizeof(msg));
memset(from, 0, fromlen);
memset(ioBuf, 0, inBufSize);
memset(&cmsg_un, 0, sizeof(cmsg_un));
-
msg.msg_name = (caddr_t)from;
msg.msg_namelen = fromlen;
msg.msg_iov = vec;
@@ -413,14 +380,10 @@ int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen
msg.msg_control = cmsg_un.data;
msg.msg_controllen = sizeof(cmsg_un.data);
msg.msg_flags = 0;
-
// Original version - for reference only
//int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
-
int n = recvmsg(GetSocket(), &msg, MSG_DONTWAIT);
-
// now ioBuf will contain the data, as if we used recvfrom
-
// Now get the time
if(n != -1 && msg.msg_controllen >= sizeof(struct cmsghdr) && !(msg.msg_flags & MSG_CTRUNC))
{
@@ -442,7 +405,6 @@ int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen
}
#endif
-
void UdpSocket::OnRead()
{
#ifdef ENABLE_IPV6
@@ -555,12 +517,10 @@ void UdpSocket::OnRead()
}
}
-
void UdpSocket::SetBroadcast(bool b)
{
int one = 1;
int zero = 0;
-
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
@@ -581,12 +541,10 @@ void UdpSocket::SetBroadcast(bool b)
}
}
-
bool UdpSocket::IsBroadcast()
{
int is_broadcast = 0;
socklen_t size;
-
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
@@ -598,7 +556,6 @@ bool UdpSocket::IsBroadcast()
return is_broadcast != 0;
}
-
void UdpSocket::SetMulticastTTL(int ttl)
{
if (GetSocket() == INVALID_SOCKET)
@@ -611,12 +568,10 @@ void UdpSocket::SetMulticastTTL(int ttl)
}
}
-
int UdpSocket::GetMulticastTTL()
{
int ttl = 0;
socklen_t size = sizeof(int);
-
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
@@ -628,7 +583,6 @@ int UdpSocket::GetMulticastTTL()
return ttl;
}
-
void UdpSocket::SetMulticastLoop(bool x)
{
if (GetSocket() == INVALID_SOCKET)
@@ -655,7 +609,6 @@ void UdpSocket::SetMulticastLoop(bool x)
}
}
-
bool UdpSocket::IsMulticastLoop()
{
if (GetSocket() == INVALID_SOCKET)
@@ -685,7 +638,6 @@ bool UdpSocket::IsMulticastLoop()
return is_loop ? true : false;
}
-
void UdpSocket::AddMulticastMembership(const std::string& group, const std::string& local_if, int if_index)
{
if (GetSocket() == INVALID_SOCKET)
@@ -726,7 +678,6 @@ void UdpSocket::AddMulticastMembership(const std::string& group, const std::stri
}
}
-
void UdpSocket::DropMulticastMembership(const std::string& group, const std::string& local_if, int if_index)
{
if (GetSocket() == INVALID_SOCKET)
@@ -767,7 +718,6 @@ void UdpSocket::DropMulticastMembership(const std::string& group, const std::str
}
}
-
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
void UdpSocket::SetMulticastHops(int hops)
@@ -787,7 +737,6 @@ void UdpSocket::SetMulticastHops(int hops)
}
}
-
int UdpSocket::GetMulticastHops()
{
if (GetSocket() == INVALID_SOCKET)
@@ -810,44 +759,36 @@ int UdpSocket::GetMulticastHops()
#endif // IPPROTO_IPV6
#endif
-
bool UdpSocket::IsBound()
{
return m_bind_ok;
}
-
void UdpSocket::OnRawData(const char *buf, size_t len, struct sockaddr *sa, socklen_t sa_len)
{
}
-
void UdpSocket::OnRawData(const char *buf, size_t len, struct sockaddr *sa, socklen_t sa_len, struct timeval *ts)
{
}
-
port_t UdpSocket::GetPort()
{
return m_port;
}
-
int UdpSocket::GetLastSizeWritten()
{
return m_last_size_written;
}
-
void UdpSocket::SetTimestamp(bool x)
{
m_b_read_ts = x;
}
-
#ifdef SOCKETS_NAMESPACE
}
#endif
-