acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
udp_socket.h
Go to the documentation of this file.
1
5
/*
6
Copyright (C) 2004-2007 Anders Hedstrom
7
8
This library is made available under the terms of the GNU GPL.
9
10
If you would like to use this library in a closed-source application,
11
a separate license agreement is available. For information about
12
the closed-source license agreement for the C++ sockets library,
13
please visit http://www.alhem.net/Sockets/license.html and/or
14
email
[email protected]
.
15
16
This program is free software; you can redistribute it and/or
17
modify it under the terms of the GNU General Public License
18
as published by the Free Software Foundation; either version 2
19
of the License, or (at your option) any later version.
20
21
This program is distributed in the hope that it will be useful,
22
but WITHOUT ANY WARRANTY; without even the implied warranty of
23
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
GNU General Public License for more details.
25
26
You should have received a copy of the GNU General Public License
27
along with this program; if not, write to the Free Software
28
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
*/
30
#pragma once
31
32
33
#include "socket.h"
34
35
36
namespace
sockets
37
{
38
41
class
CLASS_DECL_APEX
udp_socket
:
42
virtual
public
socket
43
{
44
public
:
45
46
47
char_pointer
m_ibuf
;
48
::i32
m_ibufsz
;
49
bool
m_bind_ok
;
50
::networking::port_t
m_port
;
51
memsize m_last_size_written;
52
::i32 m_iConnectionRetryCount;
53
bool
m_b_read_ts;
54
55
56
::i32 m_iWriteFlags;
57
62
udp_socket
(::i32 ibufsz = 16384,
bool
ipv6 =
false
, ::i32 retries = 0);
63
~udp_socket
();
64
66
//\lparam buf Pointer to data
67
//\lparam len Length of data
68
//\lparam sa Pointer to sockaddr struct of sender
69
//\lparam sa_len Length of sockaddr struct */
70
//using socket::OnRawData;
71
//virtual void OnRawData(char_pointer buf, memsize len, struct sockaddr * sa, socklen_t sa_len);
72
74
//\lparam buf Pointer to data
75
//\lparam len Length of data
76
//\lparam sa Pointer to sockaddr struct of sender
77
//\lparam sa_len Length of sockaddr struct
78
//\lparam ts Timestamp from message */
79
//virtual void OnRawData(char_pointer buf, memsize len, struct sockaddr * sa, socklen_t sa_len, struct timeval * ts);
80
82
//\lparam port Incoming port number
83
//\lparam range Port range to try if ports already in use
84
//\return 0 if bind succeeded */
85
//::i32 Bind(::networking::port_t & port, ::i32 range = 1);
87
//\lparam intf Interface ip/hostname
88
//\lparam port Port number
89
//\lparam range Port range
90
//\return 0 if bind succeeded */
91
//::i32 Bind(const ::scoped_string & scopedstrHost, ::networking::port_t & port, ::i32 range = 1);
93
//\lparam a Ip address
94
//\lparam port Port number
95
//\lparam range Port range
96
//\return 0 if bind succeeded */
97
//::i32 Bind(in_addr a, ::networking::port_t & port, ::i32 range = 1);
99
//\lparam a Ipv6 address
100
//\lparam port Port number
101
//\lparam range Port range
102
//\return 0 if bind succeeded */
103
//::i32 Bind(in6_addr a, ::networking::port_t & port, ::i32 range = 1);
105
//\lparam ad socket address
106
//\lparam range Port range
107
//\return 0 if bind succeeded */
108
::i32 Bind(::networking::address & address, ::i32
range
= 1);
109
114
//using ::sockets::socket::open;
115
//bool open(in_addr l, ::networking::port_t port);
117
//\lparam host Hostname
118
//\lparam port Port number
119
//\return true if successful */
120
//bool open(const ::scoped_string & scopedstrHost, ::networking::port_t port);
125
bool
open
(
struct
in6_addr & a, ::networking::port_t port);
129
bool
open
(::networking::address * address);
130
132
void
SendToBuf
(const ::scoped_string & scopedstr, ::networking::port_t, const_char_pointer data, ::i32 len, ::i32
flags
= 0);
134
//void SendToBuf(const in_addr & a, ::networking::port_t, const_char_pointer data, ::i32 len, ::i32 flags = 0);
136
//void SendToBuf(const in6_addr & a, ::networking::port_t, const_char_pointer data, ::i32 len, ::i32 flags = 0);
138
void
SendToBuf
(::networking::address * address, const_char_pointer data, ::i32 len, ::i32
flags
= 0);
139
141
//void SendTo(const ::scoped_string & scopedstr, ::networking::port_t, const ::scoped_string & scopedstr, ::i32 flags = 0);
143
//void SendTo(in_addr, ::networking::port_t, const ::scoped_string & scopedstr, ::i32 flags = 0);
145
//void SendTo(in6_addr, ::networking::port_t, const ::scoped_string & scopedstr, ::i32 flags = 0);
147
void
SendTo
(::networking::address * address, const ::scoped_string & scopedstr, ::i32
flags
= 0);
148
150
//using ::file::file::write;
151
//using ::object::write;
152
void
write
(
const
void
* data, memsize c);
154
//void Send(const string &);
155
157
void
SetBroadcast
(
bool
b =
true
);
160
bool
IsBroadcast
();
161
163
void
SetMulticastTTL
(::i32 ttl = 1);
164
::i32 GetMulticastTTL();
165
bool
SetMulticastLoop(
bool
=
true
);
166
bool
IsMulticastLoop();
167
void
AddMulticastMembership(const ::scoped_string & scopedstrGroup, const ::scoped_string & scopedstrInterface =
"0.0.0.0"
, ::i32 if_index = 0);
168
void
DropMulticastMembership(const ::scoped_string & scopedstrGroup, const ::scoped_string & scopedstrInterface =
"0.0.0.0"
, ::i32 if_index = 0);
170
void
SetMulticastHops
(::i32 = -1);
172
::i32
GetMulticastHops
();
174
bool
IsBound
();
176
//::networking::port_t GetPort();
177
//void OnOptions(::i32, ::i32, ::i32, socket_id) {}
178
memsize
GetLastSizeWritten
();
179
181
void
SetTimestamp
(
bool
=
true
);
182
183
protected
:
184
udp_socket
(
const
udp_socket
& s) : base_socket(s), socket(s) {}
185
void
OnRead();
186
#if defined(LINUX) || defined(MACOSX)
188
::i32 (char_pointer ioBuf, ::i32 inBufSize,
struct
sockaddr * from, ::i32 fromlen,
struct
timeval * ts);
189
#endif
190
192
void
CreateConnection
();
193
194
195
};
196
197
198
}
// namespace sockets
199
200
201
202
203
204
flags
Definition
flags.h:13
range
Definition
range.h:223
sockets::udp_socket::SendTo
void SendTo(::networking::address *address, const ::scoped_string &scopedstr, ::i32 flags=0)
sockets::udp_socket::CreateConnection
void CreateConnection()
sockets::udp_socket::GetMulticastHops
::i32 GetMulticastHops()
sockets::udp_socket::SetMulticastTTL
void SetMulticastTTL(::i32 ttl=1)
sockets::udp_socket::write
void write(const void *data, memsize c)
sockets::udp_socket::udp_socket
udp_socket(::i32 ibufsz=16384, bool ipv6=false, ::i32 retries=0)
sockets::udp_socket::IsBroadcast
bool IsBroadcast()
sockets::udp_socket::SendToBuf
void SendToBuf(const ::scoped_string &scopedstr, ::networking::port_t, const_char_pointer data, ::i32 len, ::i32 flags=0)
sockets::udp_socket::GetLastSizeWritten
memsize GetLastSizeWritten()
sockets::udp_socket::open
bool open(::networking::address *address)
sockets::udp_socket::SetBroadcast
void SetBroadcast(bool b=true)
sockets::udp_socket::SendToBuf
void SendToBuf(::networking::address *address, const_char_pointer data, ::i32 len, ::i32 flags=0)
sockets::udp_socket::m_port
::networking::port_t m_port
Bind port number.
Definition
udp_socket.h:50
sockets::udp_socket::SetTimestamp
void SetTimestamp(bool=true)
sockets::udp_socket::open
bool open(struct in6_addr &a, ::networking::port_t port)
sockets::udp_socket::m_ibuf
char_pointer m_ibuf
Input buffer.
Definition
udp_socket.h:47
sockets::udp_socket::m_ibufsz
::i32 m_ibufsz
i32_size of input buffer
Definition
udp_socket.h:48
sockets::udp_socket::IsBound
bool IsBound()
sockets::udp_socket::SetMulticastHops
void SetMulticastHops(::i32=-1)
sockets::udp_socket::m_bind_ok
bool m_bind_ok
Bind completed successfully.
Definition
udp_socket.h:49
operating_system
linux
udp_socket.h
Generated by
1.17.0