channel.h

Go to the documentation of this file.
00001 // Copyright (C) 2001-2005 Federico Montesino Pouzols <fedemp@altern.org>
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 //
00017 // As a special exception, you may use this file as part of a free software
00018 // library without restriction.  Specifically, if other files instantiate
00019 // templates or use macros or inline functions from this file, or you compile
00020 // this file and link it with other files to produce an executable, this
00021 // file does not by itself cause the resulting executable to be covered by
00022 // the GNU General Public License.  This exception does not however
00023 // invalidate any other reasons why the executable file might be covered by
00024 // the GNU General Public License.
00025 //
00026 // This exception applies only to the code released under the name GNU
00027 // ccRTP.  If you copy code from other releases into a copy of GNU
00028 // ccRTP, as the General Public License permits, the exception does
00029 // not apply to the code that you add in this way.  To avoid misleading
00030 // anyone as to the status of such modified files, you must delete
00031 // this exception notice from them.
00032 //
00033 // If you write modifications of your own for GNU ccRTP, it is your choice
00034 // whether to permit this exception to apply to your modifications.
00035 // If you do not wish that, delete this exception notice.
00036 //
00037 
00038 #ifndef CCRTP_CHANNEL_H_
00039 #define CCRTP_CHANNEL_H_
00040 
00041 #include <ccrtp/base.h>
00042 #include <commoncpp/socket.h>
00043 
00044 #ifndef _MSWINDOWS_
00045 #include <sys/ioctl.h>
00046 inline size_t ccioctl(int so, int request, size_t& len)
00047     { return ioctl(so,request,&len); }
00048 #else
00049 inline size_t ccioctl(SOCKET so, int request, size_t& len )
00050 {
00051     unsigned long l;
00052     size_t result = 0;
00053     ::ioctlsocket(so,request,&l);
00054     len = l;
00055     return result;
00056 }
00057 #endif
00058 
00059 NAMESPACE_COMMONCPP
00060 
00095 class RTPBaseUDPIPv4Socket : private UDPSocket
00096 {
00097 public:
00101     RTPBaseUDPIPv4Socket(const InetAddress& ia, tpport_t port) :
00102         UDPSocket(ia,port)
00103     { }
00104 
00105     inline ~RTPBaseUDPIPv4Socket()
00106     { endSocket(); }
00107 
00108     inline bool
00109     isPendingRecv(microtimeout_t timeout)
00110     { return UDPSocket::isPending(UDPSocket::pendingInput, timeout); }
00111 
00112     inline InetHostAddress
00113     getSender(tpport_t& port) const
00114     { return UDPSocket::getSender(&port); }
00115 
00116     inline size_t
00117     recv(unsigned char* buffer, size_t len)
00118     { return UDPSocket::receive(buffer, len); }
00119 
00123     inline size_t
00124     getNextPacketSize() const
00125     { size_t len; ccioctl(UDPSocket::so,FIONREAD,len); return len; }
00126 
00127     Socket::Error
00128     setMulticast(bool enable)
00129     { return UDPSocket::setMulticast(enable); }
00130 
00131     inline Socket::Error
00132     join(const InetMcastAddress& ia, uint32 iface)
00133     { return UDPSocket::join(ia,iface); }
00134 
00135     inline Socket::Error
00136     drop(const InetMcastAddress& ia)
00137     { return UDPSocket::drop(ia); }
00138 
00139         inline Socket::Error
00140     setTimeToLive(unsigned char ttl)
00141     { return UDPSocket::setTimeToLive(ttl); }
00142 
00146     RTPBaseUDPIPv4Socket() :
00147         UDPSocket()
00148     { }
00149 
00150     inline void
00151     setPeer(const InetAddress &ia, tpport_t port)
00152         {UDPSocket::setPeer((InetHostAddress&)ia, port);}
00153 
00154     inline size_t
00155     send(const unsigned char* const buffer, size_t len)
00156     { return UDPSocket::send(buffer, len); }
00157 
00158     inline SOCKET getRecvSocket() const
00159     { return UDPSocket::so; }
00160 
00161     // common
00162     inline void
00163     endSocket()
00164     { UDPSocket::endSocket(); }
00165 };
00166 
00187 template<class BaseSocket>
00188 class DualRTPChannel
00189 {
00190 public:
00191     DualRTPChannel(const InetAddress& ia, tpport_t port)
00192     {
00193         recvSocket = new BaseSocket(ia,port);
00194         sendSocket = new BaseSocket;
00195     }
00196 
00197     inline ~DualRTPChannel()
00198     { delete sendSocket; delete recvSocket; }
00199 
00200     inline bool
00201     isPendingRecv(microtimeout_t timeout) const
00202     { return recvSocket->isPendingRecv(timeout); }
00203 
00204     inline InetHostAddress
00205     getSender(tpport_t& port) const
00206     { return recvSocket->getSender(port); }
00207 
00208     inline size_t
00209     recv(unsigned char* buffer, size_t len)
00210     { return recvSocket->recv(buffer, len); }
00211 
00212     inline size_t
00213     getNextPacketSize() const
00214     { return recvSocket->getNextPacketSize(); }
00215 
00216     inline Socket::Error
00217     setMulticast(bool enable)
00218     { Socket::Error error = recvSocket->setMulticast(enable);
00219       if (error) return error;
00220       return sendSocket->setMulticast(enable); }
00221 
00222     inline Socket::Error
00223     join(const InetMcastAddress& ia, uint32 iface)
00224     { return recvSocket->join(ia,iface); }
00225 
00226     inline Socket::Error
00227     drop(const InetMcastAddress& ia)
00228     { return recvSocket->drop(ia); }
00229 
00230         inline Socket::Error
00231     setTimeToLive(unsigned char ttl)
00232     { return sendSocket->setTimeToLive(ttl); }
00233 
00234     inline void
00235     setPeer(const InetAddress& host, tpport_t port)
00236     { sendSocket->setPeer(host,port); }
00237 
00238     inline size_t
00239     send(const unsigned char* const buffer, size_t len)
00240     { return sendSocket->send(buffer, len); }
00241 
00242     inline SOCKET getRecvSocket() const
00243     { return recvSocket->getRecvSocket(); }
00244 
00245     // common.
00246     inline void
00247     endSocket()
00248     { sendSocket->endSocket(); recvSocket->endSocket(); }
00249 
00250 private:
00251     BaseSocket* sendSocket;
00252     BaseSocket* recvSocket;
00253 };
00254 
00255 #ifdef  CCXX_IPV6
00256 
00278 class RTPBaseUDPIPv6Socket : private UDPSocket
00279 {
00280 public:
00284     RTPBaseUDPIPv6Socket(const IPV6Address& ia, tpport_t port) :
00285         UDPSocket(ia,port)
00286     { }
00287 
00288     inline ~RTPBaseUDPIPv6Socket()
00289     { endSocket(); }
00290 
00291     inline bool
00292     isPendingRecv(microtimeout_t timeout)
00293     { return UDPSocket::isPending(UDPSocket::pendingInput, timeout); }
00294 
00295     inline IPV6Host
00296     getSender(tpport_t& port) const
00297     { return UDPSocket::getIPV6Sender(&port); }
00298 
00299     inline size_t
00300     recv(unsigned char* buffer, size_t len)
00301     { return UDPSocket::receive(buffer, len); }
00302 
00306     inline size_t
00307     getNextPacketSize() const
00308     { size_t len; ccioctl(UDPSocket::so,FIONREAD,len); return len; }
00309 
00310     Socket::Error
00311     setMulticast(bool enable)
00312     { return UDPSocket::setMulticast(enable); }
00313 
00314     inline Socket::Error
00315     join(const IPV6Multicast& ia, uint32 iface)
00316     { return Socket::join(ia); }
00317 
00318     inline Socket::Error
00319     drop(const IPV6Multicast& ia)
00320     { return UDPSocket::drop(ia); }
00321 
00322         inline Socket::Error
00323     setTimeToLive(unsigned char ttl)
00324     { return UDPSocket::setTimeToLive(ttl); }
00325 
00329     RTPBaseUDPIPv6Socket() :
00330         UDPSocket()
00331     { }
00332 
00333     inline void
00334     setPeer(const IPV6Host &ia, tpport_t port)
00335         {UDPSocket::setPeer(ia, port);}
00336 
00337     inline size_t
00338     send(const unsigned char* const buffer, size_t len)
00339     { return UDPSocket::send(buffer, len); }
00340 
00341     inline SOCKET getRecvSocket() const
00342     { return UDPSocket::so; }
00343 
00344     // common
00345     inline void
00346     endSocket()
00347     { UDPSocket::endSocket(); }
00348 };
00349 
00370 template<class BaseSocket>
00371 class DualRTPChannelIPV6
00372 {
00373 public:
00374     DualRTPChannelIPV6(const IPV6Host& ia, tpport_t port)
00375     {
00376         recvSocket = new BaseSocket(ia,port);
00377         sendSocket = new BaseSocket;
00378     }
00379 
00380     inline ~DualRTPChannelIPV6()
00381     { delete sendSocket; delete recvSocket; }
00382 
00383     inline bool
00384     isPendingRecv(microtimeout_t timeout) const
00385     { return recvSocket->isPendingRecv(timeout); }
00386 
00387     inline IPV6Host
00388     getSender(tpport_t& port) const
00389     { return recvSocket->getIPV6Sender(port); }
00390 
00391     inline size_t
00392     recv(unsigned char* buffer, size_t len)
00393     { return recvSocket->recv(buffer, len); }
00394 
00395     inline size_t
00396     getNextPacketSize() const
00397     { return recvSocket->getNextPacketSize(); }
00398 
00399     inline Socket::Error
00400     setMulticast(bool enable)
00401     { Socket::Error error = recvSocket->setMulticast(enable);
00402       if (error) return error;
00403       return sendSocket->setMulticast(enable); }
00404 
00405     inline Socket::Error
00406     join(const IPV6Multicast& ia, uint32 iface)
00407     { return recvSocket->join(ia,iface); }
00408 
00409     inline Socket::Error
00410     drop(const IPV6Multicast& ia)
00411     { return recvSocket->drop(ia); }
00412 
00413         inline Socket::Error
00414     setTimeToLive(unsigned char ttl)
00415     { return sendSocket->setTimeToLive(ttl); }
00416 
00417     inline void
00418     setPeer(const IPV6Host& host, tpport_t port)
00419     { sendSocket->setPeer(host,port); }
00420 
00421     inline size_t
00422     send(const unsigned char* const buffer, size_t len)
00423     { return sendSocket->send(buffer, len); }
00424 
00425     inline SOCKET getRecvSocket() const
00426     { return recvSocket->getRecvSocket(); }
00427 
00428     // common.
00429     inline void
00430     endSocket()
00431     { sendSocket->endSocket(); recvSocket->endSocket(); }
00432 
00433 private:
00434     BaseSocket* sendSocket;
00435     BaseSocket* recvSocket;
00436 };
00437 
00438 
00439 typedef DualRTPChannelIPV6<RTPBaseUDPIPv6Socket> DualRTPUDPIPv6Channel;
00440 typedef RTPBaseUDPIPv6Socket SingleRTPChannelIPV6;
00441 typedef SingleRTPChannelIPV6 SymmetricRTPChannelIPV6;
00442 
00443 #endif
00444 
00445 typedef DualRTPChannel<RTPBaseUDPIPv4Socket> DualRTPUDPIPv4Channel;
00446 
00451 typedef RTPBaseUDPIPv4Socket SingleRTPChannel;
00452 
00456 typedef SingleRTPChannel SymmetricRTPChannel;
00457  // sockets
00459 
00460 END_NAMESPACE
00461 
00462 #endif  //CCRTP_CHANNEL_H_
00463 

Generated on 14 Aug 2013 for ccRTP by  doxygen 1.4.7