channel.h

00001 /*****************************************************************************
00002 Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are
00007 met:
00008 
00009 * Redistributions of source code must retain the above
00010   copyright notice, this list of conditions and the
00011   following disclaimer.
00012 
00013 * Redistributions in binary form must reproduce the
00014   above copyright notice, this list of conditions
00015   and the following disclaimer in the documentation
00016   and/or other materials provided with the distribution.
00017 
00018 * Neither the name of the University of Illinois
00019   nor the names of its contributors may be used to
00020   endorse or promote products derived from this
00021   software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00024 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00025 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00026 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00027 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00028 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00029 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00030 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00031 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00032 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 *****************************************************************************/
00035 
00036 /*****************************************************************************
00037 written by
00038    Yunhong Gu, last updated 01/27/2011
00039 *****************************************************************************/
00040 
00041 #ifndef __UDT_CHANNEL_H__
00042 #define __UDT_CHANNEL_H__
00043 
00044 
00045 #include "udt.h"
00046 #include "packet.h"
00047 
00048 
00049 class CChannel
00050 {
00051 public:
00052    CChannel();
00053    CChannel(int version);
00054    ~CChannel();
00055 
00056       // Functionality:
00057       //    Open a UDP channel.
00058       // Parameters:
00059       //    0) [in] addr: The local address that UDP will use.
00060       // Returned value:
00061       //    None.
00062 
00063    void open(const sockaddr* addr = NULL);
00064 
00065       // Functionality:
00066       //    Open a UDP channel based on an existing UDP socket.
00067       // Parameters:
00068       //    0) [in] udpsock: UDP socket descriptor.
00069       // Returned value:
00070       //    None.
00071 
00072    void open(UDPSOCKET udpsock);
00073 
00074       // Functionality:
00075       //    Disconnect and close the UDP entity.
00076       // Parameters:
00077       //    None.
00078       // Returned value:
00079       //    None.
00080 
00081    void close() const;
00082 
00083       // Functionality:
00084       //    Get the UDP sending buffer size.
00085       // Parameters:
00086       //    None.
00087       // Returned value:
00088       //    Current UDP sending buffer size.
00089 
00090    int getSndBufSize();
00091 
00092       // Functionality:
00093       //    Get the UDP receiving buffer size.
00094       // Parameters:
00095       //    None.
00096       // Returned value:
00097       //    Current UDP receiving buffer size.
00098 
00099    int getRcvBufSize();
00100 
00101       // Functionality:
00102       //    Set the UDP sending buffer size.
00103       // Parameters:
00104       //    0) [in] size: expected UDP sending buffer size.
00105       // Returned value:
00106       //    None.
00107 
00108    void setSndBufSize(int size);
00109 
00110       // Functionality:
00111       //    Set the UDP receiving buffer size.
00112       // Parameters:
00113       //    0) [in] size: expected UDP receiving buffer size.
00114       // Returned value:
00115       //    None.
00116 
00117    void setRcvBufSize(int size);
00118 
00119       // Functionality:
00120       //    Query the socket address that the channel is using.
00121       // Parameters:
00122       //    0) [out] addr: pointer to store the returned socket address.
00123       // Returned value:
00124       //    None.
00125 
00126    void getSockAddr(sockaddr* addr) const;
00127 
00128       // Functionality:
00129       //    Query the peer side socket address that the channel is connect to.
00130       // Parameters:
00131       //    0) [out] addr: pointer to store the returned socket address.
00132       // Returned value:
00133       //    None.
00134 
00135    void getPeerAddr(sockaddr* addr) const;
00136 
00137       // Functionality:
00138       //    Send a packet to the given address.
00139       // Parameters:
00140       //    0) [in] addr: pointer to the destination address.
00141       //    1) [in] packet: reference to a CPacket entity.
00142       // Returned value:
00143       //    Actual size of data sent.
00144 
00145    int sendto(const sockaddr* addr, CPacket& packet) const;
00146 
00147       // Functionality:
00148       //    Receive a packet from the channel and record the source address.
00149       // Parameters:
00150       //    0) [in] addr: pointer to the source address.
00151       //    1) [in] packet: reference to a CPacket entity.
00152       // Returned value:
00153       //    Actual size of data received.
00154 
00155    int recvfrom(sockaddr* addr, CPacket& packet) const;
00156 
00157 private:
00158    void setUDPSockOpt();
00159 
00160 private:
00161    int m_iIPversion;                    // IP version
00162    int m_iSockAddrSize;                 // socket address structure size (pre-defined to avoid run-time test)
00163 
00164    UDPSOCKET m_iSocket;                 // socket descriptor
00165 
00166    int m_iSndBufSize;                   // UDP sending buffer size
00167    int m_iRcvBufSize;                   // UDP receiving buffer size
00168 };
00169 
00170 
00171 #endif

Generated on 9 Feb 2013 for barchart-udt-core-2.2.2 by  doxygen 1.6.1