acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
udp_socket.h
Go to the documentation of this file.
1
5/*
6Copyright (C) 2004-2007 Anders Hedstrom
7
8This library is made available under the terms of the GNU GPL.
9
10If you would like to use this library in a closed-source application,
11a separate license agreement is available. For information about
12the closed-source license agreement for the C++ sockets library,
13please visit http://www.alhem.net/Sockets/license.html and/or
15
16This program is free software; you can redistribute it and/or
17modify it under the terms of the GNU General Public License
18as published by the Free Software Foundation; either version 2
19of the License, or (at your option) any later version.
20
21This program is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public License
27along with this program; if not, write to the Free Software
28Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/
30#pragma once
31
32
33#include "socket.h"
34
35
36namespace 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);
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);
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);
174 bool IsBound();
176 //::networking::port_t GetPort();
177 //void OnOptions(::i32, ::i32, ::i32, socket_id) {}
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
193
194
195 };
196
197
198} // namespace sockets
199
200
201
202
203
204
Definition flags.h:13
Definition range.h:223
void SendTo(::networking::address *address, const ::scoped_string &scopedstr, ::i32 flags=0)
void SetMulticastTTL(::i32 ttl=1)
void write(const void *data, memsize c)
udp_socket(::i32 ibufsz=16384, bool ipv6=false, ::i32 retries=0)
void SendToBuf(const ::scoped_string &scopedstr, ::networking::port_t, const_char_pointer data, ::i32 len, ::i32 flags=0)
memsize GetLastSizeWritten()
bool open(::networking::address *address)
void SetBroadcast(bool b=true)
void SendToBuf(::networking::address *address, const_char_pointer data, ::i32 len, ::i32 flags=0)
::networking::port_t m_port
Bind port number.
Definition udp_socket.h:50
void SetTimestamp(bool=true)
bool open(struct in6_addr &a, ::networking::port_t port)
char_pointer m_ibuf
Input buffer.
Definition udp_socket.h:47
::i32 m_ibufsz
i32_size of input buffer
Definition udp_socket.h:48
void SetMulticastHops(::i32=-1)
bool m_bind_ok
Bind completed successfully.
Definition udp_socket.h:49