aboutsummaryrefslogtreecommitdiff
path: root/dep/include/sockets/UdpSocket.h
diff options
context:
space:
mode:
Diffstat (limited to 'dep/include/sockets/UdpSocket.h')
-rw-r--r--dep/include/sockets/UdpSocket.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/dep/include/sockets/UdpSocket.h b/dep/include/sockets/UdpSocket.h
index 010a7b23143..fd9965e96e8 100644
--- a/dep/include/sockets/UdpSocket.h
+++ b/dep/include/sockets/UdpSocket.h
@@ -4,31 +4,39 @@
**/
/*
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.
*/
#ifndef _SOCKETS_UdpSocket_H
#define _SOCKETS_UdpSocket_H
+
#include "sockets-config.h"
#include "Socket.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
+
/** Socket implementation for UDP.
\ingroup basic */
class UdpSocket : public Socket
@@ -40,12 +48,14 @@ public:
\param ipv6 'true' if this is an ipv6 socket */
UdpSocket(ISocketHandler& h,int ibufsz = 16384,bool ipv6 = false, int retries = 0);
~UdpSocket();
+
/** Called when incoming data has been received.
\param buf Pointer to data
\param len Length of data
\param sa Pointer to sockaddr struct of sender
\param sa_len Length of sockaddr struct */
virtual void OnRawData(const char *buf,size_t len,struct sockaddr *sa,socklen_t sa_len);
+
/** Called when incoming data has been received and read timestamp is enabled.
\param buf Pointer to data
\param len Length of data
@@ -53,6 +63,7 @@ public:
\param sa_len Length of sockaddr struct
\param ts Timestamp from message */
virtual void OnRawData(const char *buf,size_t len,struct sockaddr *sa,socklen_t sa_len,struct timeval *ts);
+
/** To receive incoming data, call Bind to setup an incoming port.
\param port Incoming port number
\param range Port range to try if ports already in use
@@ -85,6 +96,7 @@ public:
\param range Port range
\return 0 if bind succeeded */
int Bind(SocketAddress& ad,int range = 1);
+
/** Define remote host.
\param l Address of remote host
\param port Port of remote host
@@ -108,6 +120,7 @@ public:
\param ad Socket address
\return true if successful */
bool Open(SocketAddress& ad);
+
/** Send to specified host */
void SendToBuf(const std::string& ,port_t,const char *data,int len,int flags = 0);
/** Send to specified address */
@@ -120,6 +133,7 @@ public:
#endif
/** Send to specified socket address */
void SendToBuf(SocketAddress& ad,const char *data,int len,int flags = 0);
+
/** Send string to specified host */
void SendTo(const std::string&,port_t,const std::string&,int flags = 0);
/** Send string to specified address */
@@ -132,15 +146,18 @@ public:
#endif
/** Send string to specified socket address */
void SendTo(SocketAddress& ad,const std::string&,int flags = 0);
+
/** Send to connected address */
void SendBuf(const char *data,size_t,int flags = 0);
/** Send string to connected address. */
void Send(const std::string& ,int flags = 0);
+
/** Set broadcast */
void SetBroadcast(bool b = true);
/** Check broadcast flag.
\return true broadcast is enabled. */
bool IsBroadcast();
+
/** multicast */
void SetMulticastTTL(int ttl = 1);
int GetMulticastTTL();
@@ -160,10 +177,14 @@ public:
bool IsBound();
/** Return Bind port number */
port_t GetPort();
+
void OnOptions(int,int,int,SOCKET) {}
+
int GetLastSizeWritten();
+
/** Also read timestamp information from incoming message */
void SetTimestamp(bool = true);
+
protected:
UdpSocket(const UdpSocket& s) : Socket(s) {}
void OnRead();
@@ -171,6 +192,7 @@ protected:
/** This method emulates socket recvfrom, but uses messages so we can get the timestamp */
int ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen_t fromlen, struct timeval *ts);
#endif
+
private:
UdpSocket& operator=(const UdpSocket& ) { return *this; }
/** create before using sendto methods */
@@ -184,8 +206,11 @@ private:
bool m_b_read_ts;
};
+
#ifdef SOCKETS_NAMESPACE
}
#endif
+
#endif // _SOCKETS_UdpSocket_H
+