Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

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 
00043 #ifndef WIN32
00044 #include <sys/ioctl.h>
00045 inline size_t ccioctl(SOCKET so, int request, size_t& len) 
00046 { return ::ioctl(so,request,&len); }
00047 #else
00048 inline size_t ccioctl(SOCKET so, int request, size_t& len )
00049 { 
00050         unsigned long l; 
00051         size_t result = 0;
00052         ::ioctlsocket(so,request,&l); 
00053         len = l; 
00054         return result;
00055 }
00056 #endif
00057 
00058 #ifdef  CCXX_NAMESPACES
00059 namespace ost {
00060 #endif
00061 
00096 class RTPBaseUDPIPv4Socket : private UDPSocket
00097 {
00098 public:
00102         RTPBaseUDPIPv4Socket(const InetAddress& ia, tpport_t port) :
00103                 UDPSocket(ia,port)
00104         { }
00105         
00106         inline ~RTPBaseUDPIPv4Socket()
00107         { endSocket(); }
00108         
00109         inline bool
00110         isPendingRecv(microtimeout_t timeout)
00111         { return UDPSocket::isPending(UDPSocket::pendingInput, timeout); }
00112 
00113         InetHostAddress
00114         getSender(tpport_t& port) const
00115         { return UDPSocket::getSender(&port); }
00116 
00117         inline size_t
00118         recv(unsigned char* buffer, size_t len)
00119         { return UDPSocket::receive(buffer, len); }
00120 
00124         inline size_t
00125         getNextPacketSize() const
00126         { size_t len; ccioctl(UDPSocket::so,FIONREAD,len); return len; }
00127 
00128         Socket::Error
00129         setMulticast(bool enable)
00130         { return UDPSocket::setMulticast(enable); }
00131 
00132         inline Socket::Error
00133         join(const InetMcastAddress& ia, uint32 iface)
00134         { return UDPSocket::join(ia,iface); }
00135 
00136         inline Socket::Error
00137         drop(const InetMcastAddress& ia)
00138         { return UDPSocket::drop(ia); }
00139 
00140         inline Socket::Error 
00141         setTimeToLive(unsigned char ttl)
00142         { return UDPSocket::setTimeToLive(ttl); }
00143  
00147         RTPBaseUDPIPv4Socket() :
00148                 UDPSocket()
00149         { }
00150 
00151         inline void 
00152         setPeer(const InetAddress &ia, tpport_t port)
00153                 {UDPSocket::setPeer((InetHostAddress&)ia, port);}
00154 
00155         inline size_t
00156         send(const unsigned char* const buffer, size_t len)
00157         { return UDPSocket::send(buffer, len); }
00158 
00159         inline SOCKET getRecvSocket() const
00160         { return UDPSocket::so; }
00161 
00162         // common
00163         inline void
00164         endSocket()
00165         { UDPSocket::endSocket(); }
00166 };
00167 
00188 template<class BaseSocket>
00189 class DualRTPChannel
00190 {
00191 public:
00192         DualRTPChannel(const InetAddress& ia, tpport_t port)
00193         { 
00194                 recvSocket = new BaseSocket(ia,port);
00195                 sendSocket = new BaseSocket;
00196         }
00197 
00198         inline ~DualRTPChannel()
00199         { delete sendSocket; delete recvSocket; }
00200         
00201         inline bool
00202         isPendingRecv(microtimeout_t timeout) const
00203         { return recvSocket->isPendingRecv(timeout); }
00204 
00205         InetHostAddress
00206         getSender(tpport_t& port) const
00207         { return recvSocket->getSender(port); }
00208 
00209         inline size_t
00210         recv(unsigned char* buffer, size_t len)
00211         { return recvSocket->recv(buffer, len); }
00212 
00213         inline size_t
00214         getNextPacketSize() const
00215         { return recvSocket->getNextPacketSize(); }
00216 
00217         Socket::Error
00218         setMulticast(bool enable)
00219         { return recvSocket->setMulticast(enable); }
00220 
00221         inline Socket::Error
00222         join(const InetMcastAddress& ia, uint32 iface)
00223         { return recvSocket->join(ia,iface); }
00224 
00225         inline Socket::Error
00226         drop(const InetMcastAddress& ia)
00227         { return recvSocket->drop(ia); }
00228 
00229         inline Socket::Error 
00230         setTimeToLive(unsigned char ttl)
00231         { return recvSocket->setTimeToLive(ttl); }
00232  
00233         inline void 
00234         setPeer(const InetAddress& host, tpport_t port)
00235         { sendSocket->setPeer(host,port); }
00236 
00237         inline size_t
00238         send(const unsigned char* const buffer, size_t len)               
00239         { return sendSocket->send(buffer, len); }
00240 
00241         inline SOCKET getRecvSocket() const
00242         { return recvSocket->getRecvSocket(); }
00243 
00244         // common.
00245         inline void
00246         endSocket()
00247         { sendSocket->endSocket(); recvSocket->endSocket(); }
00248 
00249 private:
00250         BaseSocket* sendSocket;
00251         BaseSocket* recvSocket;
00252 };
00253 
00254 typedef DualRTPChannel<RTPBaseUDPIPv4Socket> DualRTPUDPIPv4Channel;
00255 
00260 typedef RTPBaseUDPIPv4Socket SingleRTPChannel;
00261 
00265 typedef SingleRTPChannel SymmetricRTPChannel;
00266  // sockets
00268 
00269 #ifdef  CCXX_NAMESPACES
00270 }
00271 #endif
00272 
00273 #endif  //CCRTP_CHANNEL_H_
00274 

Generated on Fri Dec 9 23:36:18 2005 for ccRTP by  doxygen 1.4.4