1 // Copyright (C) 2001-2005 Federico Montesino Pouzols <fedemp@altern.org>
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccRTP. If you copy code from other releases into a copy of GNU
28 // ccRTP, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccRTP, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37
38 #ifndef CCRTP_CHANNEL_H_
39 #define CCRTP_CHANNEL_H_
40
42
43 #ifndef WIN32
44 #include <sys/ioctl.h>
46 { return ::ioctl(so,request,&len); }
47 #else
49 {
50 unsigned long l;
51 size_t result = 0;
52 ::ioctlsocket(so,request,&l);
53 len = l;
54 return result;
55 }
56 #endif
57
58 #ifdef CCXX_NAMESPACES
59 namespace ost {
60 #endif
61
97 {
98 public:
104 { }
105
107 { endSocket(); }
108
109 inline bool
112
116
117 inline size_t
118 recv(
unsigned char* buffer,
size_t len)
120
124 inline size_t
127
131
135
139
143
149 { }
150
151 inline void
154
155 inline size_t
156 send(
const unsigned char*
const buffer,
size_t len)
158
161
162 // common
163 inline void
166 };
167
188 template<class BaseSocket>
190 {
191 public:
193 {
194 recvSocket = new BaseSocket(ia,port);
195 sendSocket = new BaseSocket;
196 }
197
199 { delete sendSocket; delete recvSocket; }
200
201 inline bool
203 { return recvSocket->isPendingRecv(timeout); }
204
207 { return recvSocket->getSender(port); }
208
209 inline size_t
210 recv(
unsigned char* buffer,
size_t len)
211 { return recvSocket->recv(buffer, len); }
212
213 inline size_t
215 { return recvSocket->getNextPacketSize(); }
216
220 if (error)
return error;
221 return sendSocket->setMulticast(enable); }
222
225 { return recvSocket->join(ia,iface); }
226
229 { return recvSocket->drop(ia); }
230
233 { return sendSocket->setTimeToLive(ttl); }
234
235 inline void
237 { sendSocket->setPeer(host,port); }
238
239 inline size_t
240 send(
const unsigned char*
const buffer,
size_t len)
241 { return sendSocket->send(buffer, len); }
242
244 { return recvSocket->getRecvSocket(); }
245
246 // common.
247 inline void
249 { sendSocket->endSocket(); recvSocket->endSocket(); }
250
251 private:
254 };
255
256 #ifdef CCXX_IPV6
257
279 class RTPBaseUDPIPv6Socket :
private UDPSocket
280 {
281 public:
285 RTPBaseUDPIPv6Socket(
const IPV6Address& ia,
tpport_t port) :
287 { }
288
289 inline ~RTPBaseUDPIPv6Socket()
290 { endSocket(); }
291
292 inline bool
295
296 inline IPV6Host
298 { return UDPSocket::getIPV6Sender(&port); }
299
300 inline size_t
301 recv(unsigned char* buffer, size_t len)
303
307 inline size_t
308 getNextPacketSize() const
310
312 setMulticast(bool enable)
314
316 join(const IPV6Multicast& ia, uint32 iface)
318
320 drop(const IPV6Multicast& ia)
322
324 setTimeToLive(unsigned char ttl)
326
330 RTPBaseUDPIPv6Socket() :
332 { }
333
334 inline void
335 setPeer(
const IPV6Host &ia,
tpport_t port)
337
338 inline size_t
339 send(const unsigned char* const buffer, size_t len)
341
342 inline SOCKET getRecvSocket()
const
344
345 // common
346 inline void
347 endSocket()
349 };
350
371 template<class BaseSocket>
372 class DualRTPChannelIPV6
373 {
374 public:
375 DualRTPChannelIPV6(
const IPV6Host& ia,
tpport_t port)
376 {
377 recvSocket = new BaseSocket(ia,port);
378 sendSocket = new BaseSocket;
379 }
380
381 inline ~DualRTPChannelIPV6()
382 { delete sendSocket; delete recvSocket; }
383
384 inline bool
386 { return recvSocket->isPendingRecv(timeout); }
387
388 inline IPV6Host
390 { return recvSocket->getIPV6Sender(port); }
391
392 inline size_t
393 recv(unsigned char* buffer, size_t len)
394 { return recvSocket->recv(buffer, len); }
395
396 inline size_t
397 getNextPacketSize() const
398 { return recvSocket->getNextPacketSize(); }
399
401 setMulticast(bool enable)
403 if (error)
return error;
404 return sendSocket->setMulticast(enable); }
405
407 join(const IPV6Multicast& ia, uint32 iface)
408 { return recvSocket->join(ia,iface); }
409
411 drop(const IPV6Multicast& ia)
412 { return recvSocket->drop(ia); }
413
415 setTimeToLive(unsigned char ttl)
416 { return sendSocket->setTimeToLive(ttl); }
417
418 inline void
419 setPeer(
const IPV6Host& host,
tpport_t port)
420 { sendSocket->setPeer(host,port); }
421
422 inline size_t
423 send(const unsigned char* const buffer, size_t len)
424 { return sendSocket->send(buffer, len); }
425
426 inline SOCKET getRecvSocket()
const
427 { return recvSocket->getRecvSocket(); }
428
429 // common.
430 inline void
431 endSocket()
432 { sendSocket->endSocket(); recvSocket->endSocket(); }
433
434 private:
435 BaseSocket* sendSocket;
436 BaseSocket* recvSocket;
437 };
438
439
440 typedef DualRTPChannelIPV6<RTPBaseUDPIPv6Socket> DualRTPUDPIPv6Channel;
441 typedef RTPBaseUDPIPv6Socket SingleRTPChannelIPV6;
442 typedef SingleRTPChannelIPV6 SymmetricRTPChannelIPV6;
443
444 #endif
445
447
453
458 // sockets
460
461 #ifdef CCXX_NAMESPACES
462 }
463 #endif
464
465 #endif //CCRTP_CHANNEL_H_
466
virtual bool isPending(Pending pend, timeout_t timeout=TIMEOUT_INF)
Get the status of pending operations.
Socket::Error setTimeToLive(unsigned char ttl)
RTPBaseUDPIPv4Socket()
Constructor for transmitter.
Socket::Error join(const IPV4Multicast &ia, int InterfaceIndex)
join a multicast group on a particular interface
UDP sockets implement the TCP SOCK_DGRAM UDP protocol.
Socket::Error drop(const InetMcastAddress &ia)
Error join(const IPV4Multicast &ia)
Join a multicast group.
DualRTPChannel< RTPBaseUDPIPv4Socket > DualRTPUDPIPv4Channel
__EXPORT AppLog & error(AppLog &sl)
Manipulator for error level.
uint32 microtimeout_t
Time interval expressed in microseconds.
unsigned short tpport_t
Transport Protocol Ports.
Socket::Error drop(const InetMcastAddress &ia)
SOCKET getRecvSocket() const
SOCKET volatile so
the actual socket descriptor, in Windows, unlike posix it cannot be used as an file descriptor that w...
RTPBaseUDPIPv4Socket(const InetAddress &ia, tpport_t port)
Constructor for receiver.
SingleRTPChannel SymmetricRTPChannel
Actually, RTP with a single channel can be called 'Symmetric RTP'.
bool isPendingRecv(microtimeout_t timeout) const
size_t ccioctl(SOCKET so, int request, size_t &len)
ssize_t send(const void *buf, size_t len)
Send a message packet to a peer host.
SOCKET getRecvSocket() const
Error setMulticast(bool enable)
Set the multicast.
Socket::Error join(const InetMcastAddress &ia, uint32 iface)
Socket::Error setTimeToLive(unsigned char ttl)
Error setTimeToLive(char ttl)
Set time to live.
Error drop(const IPV4Multicast &ia)
Drop membership from a multicast group.
Socket::Error setMulticast(bool enable)
A UDP/IPv4 socket class targetted at RTP stacks.
void endSocket(void)
Used as the default destructor for ending a socket.
size_t getNextPacketSize() const
bool isPendingRecv(microtimeout_t timeout)
size_t getNextPacketSize() const
Get size of next datagram waiting to be read.
InetHostAddress getSender(tpport_t &port) const
RTPBaseUDPIPv4Socket SingleRTPChannel
May be used in applications where using the same socket for both sending and receiving is not a limit...
Socket::Error setMulticast(bool enable)
Socket::Error join(const InetMcastAddress &ia, uint32 iface)
IPV4Host getSender(tpport_t *port=NULL) const
size_t recv(unsigned char *buffer, size_t len)
DualRTPChannel(const InetAddress &ia, tpport_t port)
ssize_t receive(void *buf, size_t len, bool reply=false)
Receive a message from any host.
Base elements for RTP stacks: constants, types and global functions.
size_t send(const unsigned char *const buffer, size_t len)
void setPeer(const InetAddress &ia, tpport_t port)
void setPeer(const IPV4Host &host, tpport_t port)
set the peer address to send message packets to.
void setPeer(const InetAddress &host, tpport_t port)
size_t recv(unsigned char *buffer, size_t len)
InetHostAddress getSender(tpport_t &port) const
size_t send(const unsigned char *const buffer, size_t len)