epoll.h

00001 /*****************************************************************************
00002 Copyright (c) 2001 - 2010, 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 08/20/2010
00039 *****************************************************************************/
00040 
00041 #ifndef __UDT_EPOLL_H__
00042 #define __UDT_EPOLL_H__
00043 
00044 
00045 #include <map>
00046 #include <set>
00047 #include "udt.h"
00048 
00049 
00050 struct CEPollDesc
00051 {
00052    int m_iID;                                // epoll ID
00053    std::set<UDTSOCKET> m_sUDTSocksOut;       // set of UDT sockets waiting for write events
00054    std::set<UDTSOCKET> m_sUDTSocksIn;        // set of UDT sockets waiting for read events
00055    std::set<UDTSOCKET> m_sUDTSocksEx;        // set of UDT sockets waiting for exceptions
00056 
00057    int m_iLocalID;                           // local system epoll ID
00058    std::set<SYSSOCKET> m_sLocals;            // set of local (non-UDT) descriptors
00059 
00060    std::set<UDTSOCKET> m_sUDTWrites;         // UDT sockets ready for write
00061    std::set<UDTSOCKET> m_sUDTReads;          // UDT sockets ready for read
00062    std::set<UDTSOCKET> m_sUDTExcepts;        // UDT sockets with exceptions (connection broken, etc.)
00063 };
00064 
00065 class CEPoll
00066 {
00067 friend class CUDT;
00068 friend class CRendezvousQueue;
00069 
00070 public:
00071    CEPoll();
00072    ~CEPoll();
00073 
00074 public: // for CUDTUnited API
00075 
00076       // Functionality:
00077       //    create a new EPoll.
00078       // Parameters:
00079       //    None.
00080       // Returned value:
00081       //    new EPoll ID if success, otherwise an error number.
00082 
00083    int create();
00084 
00085       // Functionality:
00086       //    add a UDT socket to an EPoll.
00087       // Parameters:
00088       //    0) [in] eid: EPoll ID.
00089       //    1) [in] u: UDT Socket ID.
00090       //    2) [in] events: events to watch.
00091       // Returned value:
00092       //    0 if success, otherwise an error number.
00093 
00094    int add_usock(const int eid, const UDTSOCKET& u, const int* events = NULL);
00095 
00096    // BARCHART
00097    int update_usock(const int eid, const UDTSOCKET& u, const int* events = NULL);
00098    // BARCHART
00099    int verify_usock(const int eid, const UDTSOCKET& u, int* events);
00100 
00101       // Functionality:
00102       //    add a system socket to an EPoll.
00103       // Parameters:
00104       //    0) [in] eid: EPoll ID.
00105       //    1) [in] s: system Socket ID.
00106       //    2) [in] events: events to watch.
00107       // Returned value:
00108       //    0 if success, otherwise an error number.
00109 
00110    int add_ssock(const int eid, const SYSSOCKET& s, const int* events = NULL);
00111 
00112       // Functionality:
00113       //    remove a UDT socket event from an EPoll; socket will be removed if no events to watch
00114       // Parameters:
00115       //    0) [in] eid: EPoll ID.
00116       //    1) [in] u: UDT socket ID.
00117       // Returned value:
00118       //    0 if success, otherwise an error number.
00119 
00120    int remove_usock(const int eid, const UDTSOCKET& u);
00121 
00122       // Functionality:
00123       //    remove a system socket event from an EPoll; socket will be removed if no events to watch
00124       // Parameters:
00125       //    0) [in] eid: EPoll ID.
00126       //    1) [in] s: system socket ID.
00127       // Returned value:
00128       //    0 if success, otherwise an error number.
00129 
00130    int remove_ssock(const int eid, const SYSSOCKET& s);
00131 
00132       // Functionality:
00133       //    wait for EPoll events or timeout.
00134       // Parameters:
00135       //    0) [in] eid: EPoll ID.
00136       //    1) [out] readfds: UDT sockets available for reading.
00137       //    2) [out] writefds: UDT sockets available for writing.
00138       //    3) [in] msTimeOut: timeout threshold, in milliseconds.
00139       //    4) [out] lrfds: system file descriptors for reading.
00140       //    5) [out] lwfds: system file descriptors for writing.
00141       // Returned value:
00142       //    number of sockets available for IO.
00143 
00144    int wait(const int eid, std::set<UDTSOCKET>* readfds, std::set<UDTSOCKET>* writefds, int64_t msTimeOut, std::set<SYSSOCKET>* lrfds, std::set<SYSSOCKET>* lwfds);
00145 
00146       // Functionality:
00147       //    close and release an EPoll.
00148       // Parameters:
00149       //    0) [in] eid: EPoll ID.
00150       // Returned value:
00151       //    0 if success, otherwise an error number.
00152 
00153    int release(const int eid);
00154 
00155 public: // for CUDT to acknowledge IO status
00156 
00157       // Functionality:
00158       //    Update events available for a UDT socket.
00159       // Parameters:
00160       //    0) [in] uid: UDT socket ID.
00161       //    1) [in] eids: EPoll IDs to be set
00162       //    1) [in] events: Combination of events to update
00163       //    1) [in] enable: true -> enable, otherwise disable
00164       // Returned value:
00165       //    0 if success, otherwise an error number
00166 
00167    int update_events(const UDTSOCKET& uid, std::set<int>& eids, int events, bool enable);
00168 
00169 private:
00170    int m_iIDSeed;                            // seed to generate a new ID
00171    pthread_mutex_t m_SeedLock;
00172 
00173    std::map<int, CEPollDesc> m_mPolls;       // all epolls
00174    pthread_mutex_t m_EPollLock;
00175 };
00176 
00177 
00178 #endif

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