Changeset 142


Ignore:
Timestamp:
10/26/10 12:50:10 (19 months ago)
Author:
shiretu
Message:

-- re-factored netio
-- properly implemented BaseProtocol::SetApplication?

Location:
trunk
Files:
1 added
60 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/thelib/include/netio/epoll/inboundnamedpipecarrier.h

    r56 r142  
    2424#include "netio/epoll/iohandler.h" 
    2525 
    26 class BaseProtocol; 
    27  
    2826class InboundNamedPipeCarrier 
    2927: public IOHandler { 
    3028private: 
    31         BaseProtocol *_pProtocol; 
    3229        string _path; 
    3330public: 
     
    3633 
    3734        static InboundNamedPipeCarrier *Create(string path, uint16_t mode); 
    38  
    39         void SetProtocol(BaseProtocol *pPotocol); 
    4035 
    4136        virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/netio/epoll/iohandler.h

    r58 r142  
    3535} IOHandlerType; 
    3636 
     37class BaseProtocol; 
     38 
    3739class IOHandler { 
    3840protected: 
     
    4143        int32_t _inboundFd; 
    4244        int32_t _outboundFd; 
     45        BaseProtocol *_pProtocol; 
    4346private: 
    4447        IOHandlerType _type; 
     
    5356        int32_t GetOutboundFd(); 
    5457        IOHandlerType GetType(); 
     58        void SetProtocol(BaseProtocol *pPotocol); 
    5559        virtual bool SignalOutputData() = 0; 
    5660        virtual bool OnEvent(struct epoll_event &event) = 0; 
  • trunk/sources/thelib/include/netio/epoll/iotimer.h

    r56 r142  
    2424#include "netio/epoll/iohandler.h" 
    2525 
    26 class BaseProtocol; 
    27  
    2826class IOTimer 
    2927: public IOHandler { 
    3028private: 
    3129        static int32_t _idGenerator; 
    32         BaseProtocol *_pProtocol; 
    3330public: 
    34         IOTimer(BaseProtocol *pProtocol); 
     31        IOTimer(); 
    3532        virtual ~IOTimer(); 
    3633 
    37         void ResetProtocol(); 
    3834        virtual bool SignalOutputData(); 
    3935        virtual bool OnEvent(struct epoll_event &eventWrapper); 
  • trunk/sources/thelib/include/netio/epoll/stdiocarrier.h

    r56 r142  
    2525#include "netio/epoll/iohandler.h" 
    2626 
    27 class BaseProtocol; 
    28  
    2927class StdioCarrier 
    3028: public IOHandler { 
    3129private: 
    3230        static StdioCarrier *_pInstance; 
    33         BaseProtocol *_pProtocol; 
    3431        bool _writeDataEnabled; 
    3532private: 
    36         StdioCarrier(BaseProtocol *pProtocol); 
     33        StdioCarrier(); 
    3734public: 
    3835        static StdioCarrier *GetInstance(BaseProtocol *pProtocol); 
    3936        virtual ~StdioCarrier(); 
    40         void ResetProtocol(); 
    4137        virtual bool OnEvent(struct epoll_event &event); 
    4238        virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/netio/epoll/tcpacceptor.h

    r56 r142  
    2121#ifndef _TCPACCEPTOR_H 
    2222#define _TCPACCEPTOR_H 
    23  
     23  
    2424 
    2525#include "netio/epoll/iohandler.h" 
  • trunk/sources/thelib/include/netio/epoll/tcpcarrier.h

    r56 r142  
    2222#define _TCPCARRIER_H 
    2323 
    24  
    2524#include "netio/epoll/iohandler.h" 
    26  
    27 class BaseProtocol; 
    2825 
    2926class TCPCarrier 
    3027: public IOHandler { 
    3128private: 
    32         BaseProtocol *_pProtocol; 
    3329        bool _writeDataEnabled; 
    3430        sockaddr_in _farAddress; 
     
    4137        int32_t _recvBufferSize; 
    4238public: 
    43         TCPCarrier(int32_t fd, BaseProtocol *pProtocol); 
     39        TCPCarrier(int32_t fd); 
    4440        virtual ~TCPCarrier(); 
    45         void ResetProtocol(); 
    4641        virtual bool OnEvent(struct epoll_event &event); 
    4742        virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/netio/epoll/tcpconnector.h

    r131 r142  
    6767                if ((event.events & EPOLLERR) != 0) { 
    6868                        DEBUG("***CONNECT ERROR: Unable to connect to: %s:%d", 
    69                                 STR(_ip), 
    70                                 _port); 
     69                                        STR(_ip), 
     70                                        _port); 
    7171                        _closeSocket = true; 
    7272                        return false; 
     
    8282                } 
    8383 
    84                 TCPCarrier *pTCPCarrier = new TCPCarrier(_inboundFd, pProtocol->GetFarEndpoint()); 
     84                TCPCarrier *pTCPCarrier = new TCPCarrier(_inboundFd); 
     85                pTCPCarrier->SetProtocol(pProtocol->GetFarEndpoint()); 
    8586                pProtocol->GetFarEndpoint()->SetIOHandler(pTCPCarrier); 
    8687 
  • trunk/sources/thelib/include/netio/epoll/udpcarrier.h

    r56 r142  
    3636        uint16_t _nearPort; 
    3737public: 
    38         UDPCarrier(int32_t fd, BaseProtocol *pProtocol); 
     38        UDPCarrier(int32_t fd); 
    3939        virtual ~UDPCarrier(); 
    4040 
    41         void ResetProtocol(); 
    42         void SetProtocol(BaseProtocol *pProtocol); 
    4341        virtual bool OnEvent(struct epoll_event &event); 
    4442        virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/netio/kqueue/inboundnamedpipecarrier.h

    r2 r142  
    2424#include "netio/kqueue/iohandler.h" 
    2525 
    26 class BaseProtocol; 
    27  
    2826class InboundNamedPipeCarrier 
    2927: public IOHandler { 
    3028private: 
    31     BaseProtocol *_pProtocol; 
    3229    string _path; 
    3330public: 
     
    3633 
    3734    static InboundNamedPipeCarrier *Create(string path, uint16_t mode); 
    38  
    39     void SetProtocol(BaseProtocol *pPotocol); 
    4035 
    4136    virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/netio/kqueue/iohandler.h

    r58 r142  
    11/*  
    2 *  Copyright (c) 2010, 
    3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
    4  
    5 *  This file is part of crtmpserver. 
    6 *  crtmpserver is free software: you can redistribute it and/or modify 
    7 *  it under the terms of the GNU General Public License as published by 
    8 *  the Free Software Foundation, either version 3 of the License, or 
    9 *  (at your option) any later version. 
    10  
    11 *  crtmpserver is distributed in the hope that it will be useful, 
    12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    14 *  GNU General Public License for more details. 
    15  
    16 *  You should have received a copy of the GNU General Public License 
    17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
    18 */ 
     2 *  Copyright (c) 2010, 
     3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
     4 * 
     5 *  This file is part of crtmpserver. 
     6 *  crtmpserver is free software: you can redistribute it and/or modify 
     7 *  it under the terms of the GNU General Public License as published by 
     8 *  the Free Software Foundation, either version 3 of the License, or 
     9 *  (at your option) any later version. 
     10 * 
     11 *  crtmpserver is distributed in the hope that it will be useful, 
     12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 *  GNU General Public License for more details. 
     15 * 
     16 *  You should have received a copy of the GNU General Public License 
     17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
     18 */ 
    1919 
    2020#ifdef NET_KQUEUE 
     
    2626 
    2727typedef enum _IOHandlerType { 
    28     IOHT_ACCEPTOR, 
    29     IOHT_TCP_CONNECTOR, 
    30     IOHT_TCP_CARRIER, 
    31     IOHT_UDP_CARRIER, 
    32     IOHT_INBOUNDNAMEDPIPE_CARRIER, 
    33     IOHT_TIMER, 
    34     IOHT_STDIO 
     28        IOHT_ACCEPTOR, 
     29        IOHT_TCP_CONNECTOR, 
     30        IOHT_TCP_CARRIER, 
     31        IOHT_UDP_CARRIER, 
     32        IOHT_INBOUNDNAMEDPIPE_CARRIER, 
     33        IOHT_TIMER, 
     34        IOHT_STDIO 
    3535} IOHandlerType; 
     36 
     37class BaseProtocol; 
    3638 
    3739class IOHandler { 
    3840protected: 
    39     static uint32_t _idGenerator; 
    40     uint32_t _id; 
    41 protected: 
    42     int32_t _inboundFd; 
    43     int32_t _outboundFd; 
     41        static uint32_t _idGenerator; 
     42        uint32_t _id; 
     43        int32_t _inboundFd; 
     44        int32_t _outboundFd; 
     45        BaseProtocol *_pProtocol; 
    4446private: 
    45     IOHandlerType _type; 
    46     IOHandlerManagerToken *_pToken; 
     47        IOHandlerType _type; 
     48        IOHandlerManagerToken *_pToken; 
    4749public: 
    48     IOHandler(int32_t inboundFd, int32_t outboundFd, IOHandlerType type); 
    49     virtual ~IOHandler(); 
    50     void SetIOHandlerManagerToken(IOHandlerManagerToken *pToken); 
    51     IOHandlerManagerToken * GetIOHandlerManagerToken(); 
    52     uint32_t GetId(); 
    53     int32_t GetInboundFd(); 
    54     int32_t GetOutboundFd(); 
    55     IOHandlerType GetType(); 
    56     virtual bool SignalOutputData() = 0; 
    57     virtual bool OnEvent(struct kevent &event) = 0; 
    58     static string IOHTToString(IOHandlerType type); 
    59     virtual operator string() = 0; 
     50        IOHandler(int32_t inboundFd, int32_t outboundFd, IOHandlerType type); 
     51        virtual ~IOHandler(); 
     52        void SetIOHandlerManagerToken(IOHandlerManagerToken *pToken); 
     53        IOHandlerManagerToken * GetIOHandlerManagerToken(); 
     54        uint32_t GetId(); 
     55        int32_t GetInboundFd(); 
     56        int32_t GetOutboundFd(); 
     57        IOHandlerType GetType(); 
     58        void SetProtocol(BaseProtocol *pPotocol); 
     59        virtual bool SignalOutputData() = 0; 
     60        virtual bool OnEvent(struct kevent &event) = 0; 
     61        static string IOHTToString(IOHandlerType type); 
     62        virtual operator string() = 0; 
    6063}; 
    6164 
  • trunk/sources/thelib/include/netio/kqueue/iotimer.h

    r2 r142  
    2424#include "netio/kqueue/iohandler.h" 
    2525 
    26 class BaseProtocol; 
    27  
    2826class IOTimer 
    2927: public IOHandler { 
    3028private: 
    3129    static int32_t _idGenerator; 
    32     BaseProtocol *_pProtocol; 
    3330public: 
    34     IOTimer(BaseProtocol *pProtocol); 
     31    IOTimer(); 
    3532    virtual ~IOTimer(); 
    3633 
    37     void ResetProtocol(); 
    3834    virtual bool SignalOutputData(); 
    3935    virtual bool OnEvent(struct kevent &event); 
  • trunk/sources/thelib/include/netio/kqueue/stdiocarrier.h

    r2 r142  
    11/*  
    2 *  Copyright (c) 2010, 
    3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
    4  
    5 *  This file is part of crtmpserver. 
    6 *  crtmpserver is free software: you can redistribute it and/or modify 
    7 *  it under the terms of the GNU General Public License as published by 
    8 *  the Free Software Foundation, either version 3 of the License, or 
    9 *  (at your option) any later version. 
    10  
    11 *  crtmpserver is distributed in the hope that it will be useful, 
    12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    14 *  GNU General Public License for more details. 
    15  
    16 *  You should have received a copy of the GNU General Public License 
    17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
    18 */ 
     2 *  Copyright (c) 2010, 
     3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
     4 * 
     5 *  This file is part of crtmpserver. 
     6 *  crtmpserver is free software: you can redistribute it and/or modify 
     7 *  it under the terms of the GNU General Public License as published by 
     8 *  the Free Software Foundation, either version 3 of the License, or 
     9 *  (at your option) any later version. 
     10 * 
     11 *  crtmpserver is distributed in the hope that it will be useful, 
     12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 *  GNU General Public License for more details. 
     15 * 
     16 *  You should have received a copy of the GNU General Public License 
     17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
     18 */ 
    1919 
    2020 
     
    2525#include "netio/kqueue/iohandler.h" 
    2626 
    27 class BaseProtocol; 
    28  
    2927class StdioCarrier 
    3028: public IOHandler { 
    3129private: 
    32     static StdioCarrier *_pInstance; 
    33     BaseProtocol *_pProtocol; 
    34     bool _writeDataEnabled; 
     30        static StdioCarrier *_pInstance; 
     31        bool _writeDataEnabled; 
    3532private: 
    36     StdioCarrier(BaseProtocol *pProtocol); 
     33        StdioCarrier(); 
    3734public: 
    38     static StdioCarrier *GetInstance(BaseProtocol *pProtocol); 
    39     virtual ~StdioCarrier(); 
    40     void ResetProtocol(); 
    41     virtual bool OnEvent(struct kevent &event); 
    42     virtual bool SignalOutputData(); 
    43     virtual operator string(); 
     35        static StdioCarrier *GetInstance(BaseProtocol *pProtocol); 
     36        virtual ~StdioCarrier(); 
     37        virtual bool OnEvent(struct kevent &event); 
     38        virtual bool SignalOutputData(); 
     39        virtual operator string(); 
    4440}; 
    4541 
  • trunk/sources/thelib/include/netio/kqueue/tcpacceptor.h

    r2 r142  
    2424 
    2525#include "netio/kqueue/iohandler.h" 
    26 #include "protocols/baseprotocol.h" 
    2726 
    2827class BaseClientApplication; 
  • trunk/sources/thelib/include/netio/kqueue/tcpcarrier.h

    r2 r142  
    11/*  
    2 *  Copyright (c) 2010, 
    3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
    4  
    5 *  This file is part of crtmpserver. 
    6 *  crtmpserver is free software: you can redistribute it and/or modify 
    7 *  it under the terms of the GNU General Public License as published by 
    8 *  the Free Software Foundation, either version 3 of the License, or 
    9 *  (at your option) any later version. 
    10  
    11 *  crtmpserver is distributed in the hope that it will be useful, 
    12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    14 *  GNU General Public License for more details. 
    15  
    16 *  You should have received a copy of the GNU General Public License 
    17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
    18 */ 
     2 *  Copyright (c) 2010, 
     3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
     4 * 
     5 *  This file is part of crtmpserver. 
     6 *  crtmpserver is free software: you can redistribute it and/or modify 
     7 *  it under the terms of the GNU General Public License as published by 
     8 *  the Free Software Foundation, either version 3 of the License, or 
     9 *  (at your option) any later version. 
     10 * 
     11 *  crtmpserver is distributed in the hope that it will be useful, 
     12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 *  GNU General Public License for more details. 
     15 * 
     16 *  You should have received a copy of the GNU General Public License 
     17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
     18 */ 
    1919 
    2020#ifdef NET_KQUEUE 
     
    2222#define _TCPCARRIER_H 
    2323 
    24  
    2524#include "netio/kqueue/iohandler.h" 
    26  
    27 class BaseProtocol; 
    2825 
    2926class TCPCarrier 
    3027: public IOHandler { 
    3128private: 
    32     BaseProtocol *_pProtocol; 
    33     bool _writeDataEnabled; 
    34     sockaddr_in _farAddress; 
    35     string _farIp; 
    36     uint16_t _farPort; 
    37     sockaddr_in _nearAddress; 
    38     string _nearIp; 
    39     uint16_t _nearPort; 
     29        bool _writeDataEnabled; 
     30        sockaddr_in _farAddress; 
     31        string _farIp; 
     32        uint16_t _farPort; 
     33        sockaddr_in _nearAddress; 
     34        string _nearIp; 
     35        uint16_t _nearPort; 
    4036public: 
    41     TCPCarrier(int32_t fd, BaseProtocol *pProtocol); 
    42     virtual ~TCPCarrier(); 
    43     void ResetProtocol(); 
    44     virtual bool OnEvent(struct kevent &event); 
    45     virtual bool SignalOutputData(); 
    46     virtual operator string(); 
     37        TCPCarrier(int32_t fd); 
     38        virtual ~TCPCarrier(); 
     39        virtual bool OnEvent(struct kevent &event); 
     40        virtual bool SignalOutputData(); 
     41        virtual operator string(); 
    4742 
    48     sockaddr_in &GetFarEndpointAddress(); 
    49     string GetFarEndpointAddressIp(); 
    50     uint16_t GetFarEndpointPort(); 
    51     sockaddr_in &GetNearEndpointAddress(); 
    52     string GetNearEndpointAddressIp(); 
    53     uint16_t GetNearEndpointPort(); 
     43        sockaddr_in &GetFarEndpointAddress(); 
     44        string GetFarEndpointAddressIp(); 
     45        uint16_t GetFarEndpointPort(); 
     46        sockaddr_in &GetNearEndpointAddress(); 
     47        string GetNearEndpointAddressIp(); 
     48        uint16_t GetNearEndpointPort(); 
    5449private: 
    55     bool GetEndpointsInfo(); 
     50        bool GetEndpointsInfo(); 
    5651}; 
    5752 
  • trunk/sources/thelib/include/netio/kqueue/tcpconnector.h

    r131 r142  
    8484                } 
    8585 
    86                 TCPCarrier *pTCPCarrier = new TCPCarrier(_inboundFd, pProtocol->GetFarEndpoint()); 
     86                TCPCarrier *pTCPCarrier = new TCPCarrier(_inboundFd); 
     87                pTCPCarrier->SetProtocol(pProtocol->GetFarEndpoint()); 
    8788                pProtocol->GetFarEndpoint()->SetIOHandler(pTCPCarrier); 
    8889 
  • trunk/sources/thelib/include/netio/kqueue/udpcarrier.h

    r2 r142  
    11/*  
    2 *  Copyright (c) 2010, 
    3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
    4  
    5 *  This file is part of crtmpserver. 
    6 *  crtmpserver is free software: you can redistribute it and/or modify 
    7 *  it under the terms of the GNU General Public License as published by 
    8 *  the Free Software Foundation, either version 3 of the License, or 
    9 *  (at your option) any later version. 
    10  
    11 *  crtmpserver is distributed in the hope that it will be useful, 
    12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    14 *  GNU General Public License for more details. 
    15  
    16 *  You should have received a copy of the GNU General Public License 
    17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
    18 */ 
     2 *  Copyright (c) 2010, 
     3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
     4 * 
     5 *  This file is part of crtmpserver. 
     6 *  crtmpserver is free software: you can redistribute it and/or modify 
     7 *  it under the terms of the GNU General Public License as published by 
     8 *  the Free Software Foundation, either version 3 of the License, or 
     9 *  (at your option) any later version. 
     10 * 
     11 *  crtmpserver is distributed in the hope that it will be useful, 
     12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 *  GNU General Public License for more details. 
     15 * 
     16 *  You should have received a copy of the GNU General Public License 
     17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
     18 */ 
    1919 
    2020 
     
    2525#include "netio/kqueue/iohandler.h" 
    2626 
    27 class BaseProtocol; 
    28  
    2927class UDPCarrier 
    3028: public IOHandler { 
    3129private: 
    32         BaseProtocol *_pProtocol; 
    3330        sockaddr_in _peerAddress; 
    3431        sockaddr_in _nearAddress; 
     
    3633        uint16_t _nearPort; 
    3734public: 
    38         UDPCarrier(int32_t fd, BaseProtocol *pProtocol); 
     35        UDPCarrier(int32_t fd); 
    3936        virtual ~UDPCarrier(); 
    4037 
    41         void ResetProtocol(); 
    42         void SetProtocol(BaseProtocol *pProtocol); 
    4338        virtual bool OnEvent(struct kevent &event); 
    4439        virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/netio/netio.h

    r56 r142  
    6565#include "netio/select/stdiocarrier.h" 
    6666#define NETWORK_REACTOR "select" 
     67#error "Select system is not working now" 
    6768#endif 
    6869 
  • trunk/sources/thelib/include/netio/select/inboundnamedpipecarrier.h

    r56 r142  
    2424#include "netio/select/iohandler.h" 
    2525 
    26 class BaseProtocol; 
    27  
    2826class InboundNamedPipeCarrier 
    2927: public IOHandler { 
    3028private: 
    31         BaseProtocol *_pProtocol; 
    3229        string _path; 
    3330public: 
     
    3633 
    3734        static InboundNamedPipeCarrier *Create(string path, uint16_t mode); 
    38  
    39         void SetProtocol(BaseProtocol *pPotocol); 
    4035 
    4136        virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/netio/select/iohandler.h

    r58 r142  
    2424#include "common.h" 
    2525 
     26 
    2627typedef enum _IOHandlerType { 
    2728        IOHT_ACCEPTOR, 
     
    3435} IOHandlerType; 
    3536 
     37class BaseProtocol; 
     38 
    3639class DLLEXP IOHandler { 
    3740protected: 
    3841        static uint32_t _idGenerator; 
    3942        uint32_t _id; 
    40 protected: 
    4143        int32_t _inboundFd; 
    4244        int32_t _outboundFd; 
     45        BaseProtocol *_pProtocol; 
    4346private: 
    4447        IOHandlerType _type; 
     
    5053        int32_t GetOutboundFd(); 
    5154        IOHandlerType GetType(); 
     55        void SetProtocol(BaseProtocol *pPotocol); 
    5256        virtual bool SignalOutputData() = 0; 
    5357        virtual bool OnEvent(select_event &event) = 0; 
  • trunk/sources/thelib/include/netio/select/iotimer.h

    r56 r142  
    2424#include "netio/select/iohandler.h" 
    2525 
    26 class BaseProtocol; 
    27  
    2826class DLLEXP IOTimer 
    2927: public IOHandler { 
     
    3230        BaseProtocol *_pProtocol; 
    3331public: 
    34         IOTimer(BaseProtocol *pProtocol); 
     32        IOTimer(); 
    3533        virtual ~IOTimer(); 
    3634 
    37         void ResetProtocol(); 
    3835        virtual bool SignalOutputData(); 
    3936        virtual bool OnEvent(select_event &event); 
  • trunk/sources/thelib/include/netio/select/stdiocarrier.h

    r56 r142  
    2525#include "netio/select/iohandler.h" 
    2626 
    27 class BaseProtocol; 
    28  
    2927class DLLEXP StdioCarrier 
    3028: public IOHandler { 
    3129private: 
    3230        static StdioCarrier *_pInstance; 
    33         BaseProtocol *_pProtocol; 
    3431        bool _writeDataEnabled; 
    3532private: 
    36         StdioCarrier(BaseProtocol *pProtocol); 
     33        StdioCarrier(); 
    3734public: 
    3835        static StdioCarrier *GetInstance(BaseProtocol *pProtocol); 
    3936        virtual ~StdioCarrier(); 
    40         void ResetProtocol(); 
    4137        virtual bool OnEvent(select_event &event); 
    4238        virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/netio/select/tcpcarrier.h

    r56 r142  
    2222#define _TCPCARRIER_H 
    2323 
    24  
    2524#include "netio/select/iohandler.h" 
    2625 
     
    3029: public IOHandler { 
    3130private: 
    32         BaseProtocol *_pProtocol; 
    3331        bool _writeDataEnabled; 
    3432        sockaddr_in _farAddress; 
     
    4139        int32_t _recvBufferSize; 
    4240public: 
    43         TCPCarrier(int32_t fd, BaseProtocol *pProtocol); 
     41        TCPCarrier(int32_t fd); 
    4442        virtual ~TCPCarrier(); 
    45         void ResetProtocol(); 
    4643        virtual bool OnEvent(select_event &event); 
    4744        virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/netio/select/tcpconnector.h

    r49 r142  
    8282                } 
    8383 
    84                 TCPCarrier *pTCPCarrier = new TCPCarrier(_inboundFd, pProtocol->GetFarEndpoint()); 
     84                TCPCarrier *pTCPCarrier = new TCPCarrier(_inboundFd); 
     85                pTCPCarrier->SetProtocol(pProtocol->GetFarEndpoint()); 
    8586                pProtocol->GetFarEndpoint()->SetIOHandler(pTCPCarrier); 
    8687 
  • trunk/sources/thelib/include/netio/select/udpcarrier.h

    r56 r142  
    2525#include "netio/select/iohandler.h" 
    2626 
    27 class BaseProtocol; 
    28  
    2927class DLLEXP UDPCarrier 
    3028: public IOHandler { 
     
    3634        uint16_t _nearPort; 
    3735public: 
    38         UDPCarrier(int32_t fd, BaseProtocol *pProtocol); 
     36        UDPCarrier(int32_t fd); 
    3937        virtual ~UDPCarrier(); 
    4038 
    41         void ResetProtocol(); 
    42         void SetProtocol(BaseProtocol *pProtocol); 
    4339        virtual bool OnEvent(select_event &event); 
    4440        virtual bool SignalOutputData(); 
  • trunk/sources/thelib/include/protocols/baseprotocol.h

    r58 r142  
    3535        static uint32_t _idGenerator; 
    3636        uint32_t _id; 
     37        BaseClientApplication *_pApplication; 
    3738protected: 
    3839        uint64_t _type; 
     
    4344        bool _enqueueForDelete; 
    4445        bool _gracefullyEnqueueForDelete; 
    45         BaseClientApplication *_pApplication; 
    4646        Variant _customParameters; 
    4747public: 
     
    160160        virtual void SetApplication(BaseClientApplication *pApplication); 
    161161 
    162         //Resets the protocol's application 
    163         virtual void ResetApplication(); 
    164  
    165162        //This is called by the framework when data is available for processing, 
    166163        //when making use of connection-less protocols 
  • trunk/sources/thelib/include/protocols/rtmp/basertmpprotocol.h

    r131 r142  
    8989        virtual void ReadyForSend(); 
    9090        virtual void SetApplication(BaseClientApplication *pApplication); 
    91         virtual void ResetApplication(); 
    9291 
    9392        bool SendMessage(Variant &message); 
  • trunk/sources/thelib/include/protocols/ts/inboundtsprotocol.h

    r56 r142  
    7070 
    7171        virtual void SetApplication(BaseClientApplication *pApplication); 
    72         virtual void ResetApplication(); 
    7372        BaseTSAppProtocolHandler *GetProtocolHandler(); 
    7473        uint32_t GetChunkSize(); 
  • trunk/sources/thelib/src/application/baseclientapplication.cpp

    r131 r142  
    2929BaseClientApplication::BaseClientApplication(Variant &configuration) 
    3030: _streamsManager(this) { 
    31         _id = _idGenerator++; 
     31        _id = ++_idGenerator; 
    3232        _configuration = configuration; 
    3333        _name = (string) configuration[CONF_APPLICATION_NAME]; 
  • trunk/sources/thelib/src/netio/epoll/inboundnamedpipecarrier.cpp

    r56 r142  
    2626InboundNamedPipeCarrier::InboundNamedPipeCarrier(int32_t fd, string path) 
    2727: IOHandler(fd, fd, IOHT_INBOUNDNAMEDPIPE_CARRIER) { 
    28         _pProtocol = NULL; 
    2928        _path = path; 
    3029} 
     
    6160 
    6261        return pResult; 
    63 } 
    64  
    65 void InboundNamedPipeCarrier::SetProtocol(BaseProtocol *pPotocol) { 
    66         if (_pProtocol != NULL) { 
    67                 ASSERT("protocol already set up"); 
    68         } 
    69         _pProtocol = pPotocol; 
    7062} 
    7163 
  • trunk/sources/thelib/src/netio/epoll/iohandler.cpp

    r56 r142  
    2121#include "netio/epoll/iohandler.h" 
    2222#include "netio/epoll/iohandlermanager.h" 
     23#include "protocols/baseprotocol.h" 
    2324 
    2425uint32_t IOHandler::_idGenerator = 0; 
    2526 
    2627IOHandler::IOHandler(int32_t inboundFd, int32_t outboundFd, IOHandlerType type) { 
     28        _pProtocol = NULL; 
    2729        _type = type; 
    28         _id = _idGenerator++; 
     30        _id = ++_idGenerator; 
    2931        _inboundFd = inboundFd; 
    3032        _outboundFd = outboundFd; 
     
    3436 
    3537IOHandler::~IOHandler() { 
     38        if (_pProtocol != NULL) { 
     39                _pProtocol->SetIOHandler(NULL); 
     40                _pProtocol->EnqueueForDelete(); 
     41                _pProtocol = NULL; 
     42        } 
    3643        IOHandlerManager::UnRegisterIOHandler(this); 
    3744} 
     
    6168} 
    6269 
     70void IOHandler::SetProtocol(BaseProtocol *pPotocol) { 
     71        _pProtocol = pPotocol; 
     72} 
     73 
    6374string IOHandler::IOHTToString(IOHandlerType type) { 
    6475        switch (type) { 
  • trunk/sources/thelib/src/netio/epoll/iotimer.cpp

    r56 r142  
    2525int32_t IOTimer::_idGenerator; 
    2626 
    27 IOTimer::IOTimer(BaseProtocol *pProtocol) 
     27IOTimer::IOTimer() 
    2828: IOHandler(0, 0, IOHT_TIMER) { 
    29         _pProtocol = pProtocol; 
    3029        _inboundFd = _outboundFd = ++_idGenerator; 
    3130} 
     
    3433        //FINEST("Disable timer"); 
    3534        IOHandlerManager::DisableTimer(this, true); 
    36         if (_pProtocol != NULL) { 
    37                 _pProtocol->SetIOHandler(NULL); 
    38                 delete _pProtocol; 
    39         } 
    40 } 
    41  
    42 void IOTimer::ResetProtocol() { 
    43         _pProtocol = NULL; 
    4435} 
    4536 
  • trunk/sources/thelib/src/netio/epoll/stdiocarrier.cpp

    r56 r142  
    4040StdioCarrier *StdioCarrier::_pInstance = NULL; 
    4141 
    42 StdioCarrier::StdioCarrier(BaseProtocol *pProtocol) 
     42StdioCarrier::StdioCarrier() 
    4343: IOHandler(fileno(stdin), fileno(stdout), IOHT_TCP_CARRIER) { 
    44         _pProtocol = pProtocol; 
    4544        IOHandlerManager::EnableReadData(this); 
    4645        _writeDataEnabled = false; 
     
    4948StdioCarrier *StdioCarrier::GetInstance(BaseProtocol *pProtocol) { 
    5049        if (_pInstance == NULL) { 
    51                 _pInstance = new StdioCarrier(pProtocol); 
     50                _pInstance = new StdioCarrier(); 
     51                _pInstance->SetProtocol(pProtocol); 
     52                pProtocol->GetFarEndpoint()->SetIOHandler(_pInstance); 
    5253                return _pInstance; 
    5354        } 
     
    6263 
    6364StdioCarrier::~StdioCarrier() { 
    64         if (_pProtocol != NULL) { 
    65                 _pProtocol->SetIOHandler(NULL); 
    66                 delete _pProtocol; 
    67         } 
    6865        _pInstance = NULL; 
    69 } 
    70  
    71 void StdioCarrier::ResetProtocol() { 
    72         _pProtocol = NULL; 
    7366} 
    7467 
  • trunk/sources/thelib/src/netio/epoll/tcpacceptor.cpp

    r20 r142  
    160160 
    161161        //5. Create the carrier and bind it 
    162         TCPCarrier *pTCPCarrier = new TCPCarrier(fd, pProtocol->GetFarEndpoint()); 
     162        TCPCarrier *pTCPCarrier = new TCPCarrier(fd); 
     163        pTCPCarrier->SetProtocol(pProtocol->GetFarEndpoint()); 
    163164        pProtocol->GetFarEndpoint()->SetIOHandler(pTCPCarrier); 
    164165 
  • trunk/sources/thelib/src/netio/epoll/tcpcarrier.cpp

    r56 r142  
    3838} 
    3939 
    40 TCPCarrier::TCPCarrier(int32_t fd, BaseProtocol *pProtocol) 
     40TCPCarrier::TCPCarrier(int32_t fd) 
    4141: IOHandler(fd, fd, IOHT_TCP_CARRIER) { 
    42         _pProtocol = pProtocol; 
    4342        IOHandlerManager::EnableReadData(this); 
    4443        _writeDataEnabled = false; 
     
    6362TCPCarrier::~TCPCarrier() { 
    6463        close(_inboundFd); 
    65         if (_pProtocol != NULL) { 
    66                 _pProtocol->SetIOHandler(NULL); 
    67                 delete _pProtocol; 
    68         } 
    69 } 
    70  
    71 void TCPCarrier::ResetProtocol() { 
    72         _pProtocol = NULL; 
    7364} 
    7465 
  • trunk/sources/thelib/src/netio/epoll/udpcarrier.cpp

    r56 r142  
    2727#define SOCKET_WRITE_CHUNK SOCKET_READ_CHUNK 
    2828 
    29 UDPCarrier::UDPCarrier(int32_t fd, BaseProtocol *pProtocol) 
     29UDPCarrier::UDPCarrier(int32_t fd) 
    3030: IOHandler(fd, fd, IOHT_UDP_CARRIER) { 
    31         _pProtocol = pProtocol; 
    3231        IOHandlerManager::EnableReadData(this); 
    3332        memset(&_peerAddress, 0, sizeof (sockaddr_in)); 
     
    3938UDPCarrier::~UDPCarrier() { 
    4039        close(_inboundFd); 
    41         if (_pProtocol != NULL) { 
    42                 _pProtocol->SetIOHandler(NULL); 
    43                 delete _pProtocol; 
    44         } 
    45 } 
    46  
    47 void UDPCarrier::ResetProtocol() { 
    48         _pProtocol = NULL; 
    49 } 
    50  
    51 void UDPCarrier::SetProtocol(BaseProtocol *pProtocol) { 
    52         if (_pProtocol != NULL) { 
    53                 ASSERT("This carrier is already bound"); 
    54         } 
    55         _pProtocol = pProtocol; 
    5640} 
    5741 
     
    159143 
    160144        //4. Create the carrier 
    161         UDPCarrier *pResult = new UDPCarrier(sock, NULL); 
     145        UDPCarrier *pResult = new UDPCarrier(sock); 
    162146        pResult->_nearAddress = bindAddress; 
    163147 
  • trunk/sources/thelib/src/netio/kqueue/inboundnamedpipecarrier.cpp

    r56 r142  
    2020 
    2121#ifdef NET_KQUEUE 
    22  
    2322#include "netio/kqueue/iohandlermanager.h" 
    2423#include "netio/kqueue/inboundnamedpipecarrier.h" 
     
    2726InboundNamedPipeCarrier::InboundNamedPipeCarrier(int32_t fd, string path) 
    2827: IOHandler(fd, fd, IOHT_INBOUNDNAMEDPIPE_CARRIER) { 
    29         _pProtocol = NULL; 
    3028        _path = path; 
    3129} 
     
    6260 
    6361        return pResult; 
    64 } 
    65  
    66 void InboundNamedPipeCarrier::SetProtocol(BaseProtocol *pPotocol) { 
    67         if (_pProtocol != NULL) { 
    68                 ASSERT("protocol already set up"); 
    69         } 
    70         _pProtocol = pPotocol; 
    7162} 
    7263 
  • trunk/sources/thelib/src/netio/kqueue/iohandler.cpp

    r2 r142  
    11/*  
    2 *  Copyright (c) 2010, 
    3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
    4  
    5 *  This file is part of crtmpserver. 
    6 *  crtmpserver is free software: you can redistribute it and/or modify 
    7 *  it under the terms of the GNU General Public License as published by 
    8 *  the Free Software Foundation, either version 3 of the License, or 
    9 *  (at your option) any later version. 
    10  
    11 *  crtmpserver is distributed in the hope that it will be useful, 
    12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    14 *  GNU General Public License for more details. 
    15  
    16 *  You should have received a copy of the GNU General Public License 
    17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
    18 */ 
     2 *  Copyright (c) 2010, 
     3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
     4 * 
     5 *  This file is part of crtmpserver. 
     6 *  crtmpserver is free software: you can redistribute it and/or modify 
     7 *  it under the terms of the GNU General Public License as published by 
     8 *  the Free Software Foundation, either version 3 of the License, or 
     9 *  (at your option) any later version. 
     10 * 
     11 *  crtmpserver is distributed in the hope that it will be useful, 
     12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 *  GNU General Public License for more details. 
     15 * 
     16 *  You should have received a copy of the GNU General Public License 
     17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
     18 */ 
    1919 
    2020#ifdef NET_KQUEUE 
    2121#include "netio/kqueue/iohandler.h" 
    2222#include "netio/kqueue/iohandlermanager.h" 
    23  
    24  
    25  
     23#include "protocols/baseprotocol.h" 
    2624 
    2725uint32_t IOHandler::_idGenerator = 0; 
    2826 
    2927IOHandler::IOHandler(int32_t inboundFd, int32_t outboundFd, IOHandlerType type) { 
    30     _type = type; 
    31     _id = _idGenerator++; 
    32     _inboundFd = inboundFd; 
    33     _outboundFd = outboundFd; 
    34     _pToken = NULL; 
    35     IOHandlerManager::RegisterIOHandler(this); 
     28        _pProtocol = NULL; 
     29        _type = type; 
     30        _id = ++_idGenerator; 
     31        _inboundFd = inboundFd; 
     32        _outboundFd = outboundFd; 
     33        _pToken = NULL; 
     34        IOHandlerManager::RegisterIOHandler(this); 
    3635} 
    3736 
    3837IOHandler::~IOHandler() { 
    39     //FINEST("IOHandler %p is in destructor", this); 
    40     IOHandlerManager::UnRegisterIOHandler(this); 
     38        //FINEST("IOHandler %p is in destructor", this); 
     39        if (_pProtocol != NULL) { 
     40                _pProtocol->SetIOHandler(NULL); 
     41                _pProtocol->EnqueueForDelete(); 
     42                _pProtocol = NULL; 
     43        } 
     44        IOHandlerManager::UnRegisterIOHandler(this); 
    4145} 
    4246 
    4347void IOHandler::SetIOHandlerManagerToken(IOHandlerManagerToken *pToken) { 
    44     _pToken = pToken; 
     48        _pToken = pToken; 
    4549} 
    4650 
    4751IOHandlerManagerToken * IOHandler::GetIOHandlerManagerToken() { 
    48     return _pToken; 
     52        return _pToken; 
    4953} 
    5054 
    5155uint32_t IOHandler::GetId() { 
    52     return _id; 
     56        return _id; 
    5357} 
    5458 
    5559int32_t IOHandler::GetInboundFd() { 
    56     return _inboundFd; 
     60        return _inboundFd; 
    5761} 
    5862 
    5963int32_t IOHandler::GetOutboundFd() { 
    60     return _outboundFd; 
     64        return _outboundFd; 
    6165} 
    6266 
    6367IOHandlerType IOHandler::GetType() { 
    64     return _type; 
     68        return _type; 
     69} 
     70 
     71void IOHandler::SetProtocol(BaseProtocol *pPotocol) { 
     72        _pProtocol = pPotocol; 
    6573} 
    6674 
    6775string IOHandler::IOHTToString(IOHandlerType type) { 
    68     switch (type) { 
    69         case IOHT_ACCEPTOR: 
    70             return "IOHT_ACCEPTOR"; 
    71         case IOHT_TCP_CARRIER: 
    72             return "IOHT_TCP_CARRIER"; 
    73         case IOHT_UDP_CARRIER: 
    74             return "IOHT_UDP_CARRIER"; 
    75         case IOHT_TCP_CONNECTOR: 
    76             return "IOHT_TCP_CONNECTOR"; 
    77         case IOHT_TIMER: 
    78             return "IOHT_TIMER"; 
    79         case IOHT_INBOUNDNAMEDPIPE_CARRIER: 
    80             return "IOHT_INBOUNDNAMEDPIPE_CARRIER"; 
    81         case IOHT_STDIO: 
    82             return "IOHT_STDIO"; 
    83         default: 
    84             return format("#unknown: %d#", type); 
    85     } 
     76        switch (type) { 
     77                case IOHT_ACCEPTOR: 
     78                        return "IOHT_ACCEPTOR"; 
     79                case IOHT_TCP_CARRIER: 
     80                        return "IOHT_TCP_CARRIER"; 
     81                case IOHT_UDP_CARRIER: 
     82                        return "IOHT_UDP_CARRIER"; 
     83                case IOHT_TCP_CONNECTOR: 
     84                        return "IOHT_TCP_CONNECTOR"; 
     85                case IOHT_TIMER: 
     86                        return "IOHT_TIMER"; 
     87                case IOHT_INBOUNDNAMEDPIPE_CARRIER: 
     88                        return "IOHT_INBOUNDNAMEDPIPE_CARRIER"; 
     89                case IOHT_STDIO: 
     90                        return "IOHT_STDIO"; 
     91                default: 
     92                        return format("#unknown: %d#", type); 
     93        } 
    8694} 
    8795#endif /* NET_KQUEUE */ 
  • trunk/sources/thelib/src/netio/kqueue/iotimer.cpp

    r2 r142  
    2525int32_t IOTimer::_idGenerator; 
    2626 
    27 IOTimer::IOTimer(BaseProtocol *pProtocol) 
     27IOTimer::IOTimer() 
    2828: IOHandler(0, 0, IOHT_TIMER) { 
    29     _pProtocol = pProtocol; 
    3029    _outboundFd = _inboundFd = ++_idGenerator; 
    3130} 
     
    3433    //FINEST("Disable timer"); 
    3534    IOHandlerManager::DisableTimer(this, true); 
    36     if (_pProtocol != NULL) { 
    37         _pProtocol->SetIOHandler(NULL); 
    38         delete _pProtocol; 
    39     } 
    40 } 
    41  
    42 void IOTimer::ResetProtocol() { 
    43     _pProtocol = NULL; 
    4435} 
    4536 
  • trunk/sources/thelib/src/netio/kqueue/stdiocarrier.cpp

    r58 r142  
    4646StdioCarrier *StdioCarrier::_pInstance = NULL; 
    4747 
    48 StdioCarrier::StdioCarrier(BaseProtocol *pProtocol) 
     48StdioCarrier::StdioCarrier() 
    4949: IOHandler(fileno(stdin), fileno(stdout), IOHT_STDIO) { 
    50         _pProtocol = pProtocol; 
    5150        IOHandlerManager::EnableReadData(this); 
    5251        _writeDataEnabled = false; 
     
    5554StdioCarrier *StdioCarrier::GetInstance(BaseProtocol *pProtocol) { 
    5655        if (_pInstance == NULL) { 
    57                 _pInstance = new StdioCarrier(pProtocol); 
     56                _pInstance = new StdioCarrier(); 
     57                _pInstance->SetProtocol(pProtocol); 
     58                pProtocol->GetFarEndpoint()->SetIOHandler(_pInstance); 
    5859                return _pInstance; 
    5960        } 
     
    6869 
    6970StdioCarrier::~StdioCarrier() { 
    70         if (_pProtocol != NULL) { 
    71                 _pProtocol->SetIOHandler(NULL); 
    72                 delete _pProtocol; 
    73         } 
    7471        _pInstance = NULL; 
    75 } 
    76  
    77 void StdioCarrier::ResetProtocol() { 
    78         _pProtocol = NULL; 
    7972} 
    8073 
  • trunk/sources/thelib/src/netio/kqueue/tcpacceptor.cpp

    r56 r142  
    158158 
    159159        //5. Create the carrier and bind it 
    160         TCPCarrier *pTCPCarrier = new TCPCarrier(fd, pProtocol->GetFarEndpoint()); 
     160        TCPCarrier *pTCPCarrier = new TCPCarrier(fd); 
     161        pTCPCarrier->SetProtocol(pProtocol->GetFarEndpoint()); 
    161162        pProtocol->GetFarEndpoint()->SetIOHandler(pTCPCarrier); 
    162163 
  • trunk/sources/thelib/src/netio/kqueue/tcpcarrier.cpp

    r56 r142  
    4343}*/ 
    4444 
    45 TCPCarrier::TCPCarrier(int32_t fd, BaseProtocol *pProtocol) 
     45TCPCarrier::TCPCarrier(int32_t fd) 
    4646: IOHandler(fd, fd, IOHT_TCP_CARRIER) { 
    47         _pProtocol = pProtocol; 
    4847        IOHandlerManager::EnableReadData(this); 
    4948        _writeDataEnabled = false; 
     
    6059        //FINEST("Delete tcp carrier %p", this); 
    6160        close(_inboundFd); 
    62         if (_pProtocol != NULL) { 
    63                 _pProtocol->SetIOHandler(NULL); 
    64                 delete _pProtocol; 
    65         } 
    6661        //FINEST("Done delete tcp carrier %p", this); 
    67 } 
    68  
    69 void TCPCarrier::ResetProtocol() { 
    70         _pProtocol = NULL; 
    7162} 
    7263 
  • trunk/sources/thelib/src/netio/kqueue/udpcarrier.cpp

    r56 r142  
    2525#include "protocols/baseprotocol.h" 
    2626 
    27 UDPCarrier::UDPCarrier(int32_t fd, BaseProtocol *pProtocol) 
     27UDPCarrier::UDPCarrier(int32_t fd) 
    2828: IOHandler(fd, fd, IOHT_UDP_CARRIER) { 
    29         _pProtocol = pProtocol; 
    3029        IOHandlerManager::EnableReadData(this); 
    3130        memset(&_peerAddress, 0, sizeof (sockaddr_in)); 
     
    3736UDPCarrier::~UDPCarrier() { 
    3837        close(_inboundFd); 
    39         if (_pProtocol != NULL) { 
    40                 _pProtocol->SetIOHandler(NULL); 
    41                 delete _pProtocol; 
    42         } 
    43 } 
    44  
    45 void UDPCarrier::ResetProtocol() { 
    46         _pProtocol = NULL; 
    47 } 
    48  
    49 void UDPCarrier::SetProtocol(BaseProtocol *pProtocol) { 
    50         if (_pProtocol != NULL) { 
    51                 ASSERT("This carrier is already bound"); 
    52         } 
    53         _pProtocol = pProtocol; 
    5438} 
    5539 
     
    153137 
    154138        //4. Create the carrier 
    155         UDPCarrier *pResult = new UDPCarrier(sock, NULL); 
     139        UDPCarrier *pResult = new UDPCarrier(sock); 
    156140        pResult->_nearAddress = bindAddress; 
    157141 
  • trunk/sources/thelib/src/netio/select/inboundnamedpipecarrier.cpp

    r56 r142  
    2727InboundNamedPipeCarrier::InboundNamedPipeCarrier(int32_t fd, string path) 
    2828: IOHandler(fd, fd, IOHT_INBOUNDNAMEDPIPE_CARRIER) { 
    29         _pProtocol = NULL; 
    3029        _path = path; 
    3130} 
     
    6261 
    6362        return pResult; 
    64 } 
    65  
    66 void InboundNamedPipeCarrier::SetProtocol(BaseProtocol *pPotocol) { 
    67         if (_pProtocol != NULL) { 
    68                 ASSERT("protocol already set up"); 
    69         } 
    70         _pProtocol = pPotocol; 
    7163} 
    7264 
  • trunk/sources/thelib/src/netio/select/iohandler.cpp

    r56 r142  
    2121#include "netio/select/iohandler.h" 
    2222#include "netio/select/iohandlermanager.h" 
     23#include "protocols/baseprotocol.h" 
    2324 
    2425uint32_t IOHandler::_idGenerator = 0; 
    2526 
    2627IOHandler::IOHandler(int32_t inboundFd, int32_t outboundFd, IOHandlerType type) { 
     28        _pProtocol = NULL; 
    2729        _type = type; 
    28         _id = _idGenerator++; 
     30        _id = ++_idGenerator; 
    2931        _inboundFd = inboundFd; 
    3032        _outboundFd = outboundFd; 
     
    3436IOHandler::~IOHandler() { 
    3537        //FINEST("IOHandler %p is in destructor", this); 
     38        if (_pProtocol != NULL) { 
     39                _pProtocol->SetIOHandler(NULL); 
     40                _pProtocol->EnqueueForDelete(); 
     41                _pProtocol = NULL; 
     42        } 
    3643        IOHandlerManager::UnRegisterIOHandler(this); 
    3744} 
     
    5158IOHandlerType IOHandler::GetType() { 
    5259        return _type; 
     60} 
     61 
     62void IOHandler::SetProtocol(BaseProtocol *pPotocol) { 
     63        _pProtocol = pPotocol; 
    5364} 
    5465 
  • trunk/sources/thelib/src/netio/select/iohandlermanager.cpp

    r56 r142  
    206206 
    207207bool IOHandlerManager::UpdateFdSets(int32_t fd) { 
    208         uint8_t state; 
     208        uint8_t state = 0; 
    209209 
    210210        //    string str = ""; 
  • trunk/sources/thelib/src/netio/select/iotimer.cpp

    r56 r142  
    2525int32_t IOTimer::_idGenerator; 
    2626 
    27 IOTimer::IOTimer(BaseProtocol *pProtocol) 
     27IOTimer::IOTimer() 
    2828: IOHandler(0, 0, IOHT_TIMER) { 
    29         _pProtocol = pProtocol; 
    3029        _outboundFd = _inboundFd = ++_idGenerator; 
    3130} 
     
    3433        //FINEST("Disable timer"); 
    3534        IOHandlerManager::DisableTimer(this); 
    36         if (_pProtocol != NULL) { 
    37                 _pProtocol->SetIOHandler(NULL); 
    38                 delete _pProtocol; 
    39         } 
    40 } 
    41  
    42 void IOTimer::ResetProtocol() { 
    43         _pProtocol = NULL; 
    4435} 
    4536 
  • trunk/sources/thelib/src/netio/select/stdiocarrier.cpp

    r56 r142  
    4545StdioCarrier *StdioCarrier::_pInstance = NULL; 
    4646 
    47 StdioCarrier::StdioCarrier(BaseProtocol *pProtocol) 
     47StdioCarrier::StdioCarrier() 
    4848: IOHandler(fileno(stdin), fileno(stdout), IOHT_STDIO) { 
    49         _pProtocol = pProtocol; 
    5049        IOHandlerManager::EnableReadData(this); 
    5150        _writeDataEnabled = false; 
     
    5453StdioCarrier *StdioCarrier::GetInstance(BaseProtocol *pProtocol) { 
    5554        if (_pInstance == NULL) { 
    56                 _pInstance = new StdioCarrier(pProtocol); 
     55                _pInstance = new StdioCarrier(); 
     56                _pInstance->SetProtocol(pProtocol); 
     57                pProtocol->GetFarEndpoint()->SetIOHandler(_pInstance); 
    5758                return _pInstance; 
    5859        } 
     
    6768 
    6869StdioCarrier::~StdioCarrier() { 
    69         if (_pProtocol != NULL) { 
    70                 _pProtocol->SetIOHandler(NULL); 
    71                 delete _pProtocol; 
    72         } 
    7370        _pInstance = NULL; 
    74 } 
    75  
    76 void StdioCarrier::ResetProtocol() { 
    77         _pProtocol = NULL; 
    7871} 
    7972 
  • trunk/sources/thelib/src/netio/select/tcpacceptor.cpp

    r56 r142  
    154154 
    155155        //5. Create the carrier and bind it 
    156         TCPCarrier *pTCPCarrier = new TCPCarrier(fd, pProtocol->GetFarEndpoint()); 
     156        TCPCarrier *pTCPCarrier = new TCPCarrier(fd); 
     157        pTCPCarrier->SetProtocol(pProtocol->GetFarEndpoint()); 
    157158        pProtocol->GetFarEndpoint()->SetIOHandler(pTCPCarrier); 
    158159 
  • trunk/sources/thelib/src/netio/select/tcpcarrier.cpp

    r56 r142  
    4343}*/ 
    4444 
    45 TCPCarrier::TCPCarrier(int32_t fd, BaseProtocol *pProtocol) 
     45TCPCarrier::TCPCarrier(int32_t fd) 
    4646: IOHandler(fd, fd, IOHT_TCP_CARRIER) { 
    47         _pProtocol = pProtocol; 
    4847        IOHandlerManager::EnableReadData(this); 
    4948        _writeDataEnabled = false; 
     
    6968        //FINEST("Delete tcp carrier %p", this); 
    7069        CLOSE_SOCKET(_inboundFd); 
    71         if (_pProtocol != NULL) { 
    72                 _pProtocol->SetIOHandler(NULL); 
    73                 delete _pProtocol; 
    74         } 
    7570        //FINEST("Done delete tcp carrier %p", this); 
    76 } 
    77  
    78 void TCPCarrier::ResetProtocol() { 
    79         _pProtocol = NULL; 
    8071} 
    8172 
  • trunk/sources/thelib/src/netio/select/udpcarrier.cpp

    r56 r142  
    2525#include "protocols/baseprotocol.h" 
    2626 
    27 UDPCarrier::UDPCarrier(int32_t fd, BaseProtocol *pProtocol) 
     27UDPCarrier::UDPCarrier(int32_t fd) 
    2828: IOHandler(fd, fd, IOHT_UDP_CARRIER) { 
    29         _pProtocol = pProtocol; 
    3029        IOHandlerManager::EnableReadData(this); 
    3130        memset(&_peerAddress, 0, sizeof (sockaddr_in)); 
     
    3736UDPCarrier::~UDPCarrier() { 
    3837        CLOSE_SOCKET(_inboundFd); 
    39         if (_pProtocol != NULL) { 
    40                 _pProtocol->SetIOHandler(NULL); 
    41                 delete _pProtocol; 
    42         } 
    43 } 
    44  
    45 void UDPCarrier::ResetProtocol() { 
    46         _pProtocol = NULL; 
    47 } 
    48  
    49 void UDPCarrier::SetProtocol(BaseProtocol *pProtocol) { 
    50         if (_pProtocol != NULL) { 
    51                 ASSERT("This carrier is already bound"); 
    52         } 
    53         _pProtocol = pProtocol; 
    5438} 
    5539 
     
    154138 
    155139        //4. Create the carrier 
    156         UDPCarrier *pResult = new UDPCarrier(sock, NULL); 
     140        UDPCarrier *pResult = new UDPCarrier(sock); 
    157141        pResult->_nearAddress = bindAddress; 
    158142 
  • trunk/sources/thelib/src/protocols/baseprotocol.cpp

    r56 r142  
    5252                        _pFarProtocol, _pNearProtocol, _deleteFar, _deleteNear); 
    5353#endif 
    54         if (_pFarProtocol != NULL) { 
    55                 _pFarProtocol->_pNearProtocol = NULL; 
    56                 if (_deleteFar) { 
    57                         delete _pFarProtocol; 
    58                 } 
    59         } 
    60         if (_pNearProtocol != NULL) { 
    61                 _pNearProtocol->_pFarProtocol = NULL; 
    62                 if (_deleteNear) { 
    63                         delete _pNearProtocol; 
    64  
    65                 } 
    66         } 
     54        BaseProtocol *pFar = _pFarProtocol; 
     55        BaseProtocol *pNear = _pNearProtocol; 
     56 
    6757        _pFarProtocol = NULL; 
    6858        _pNearProtocol = NULL; 
     59        if (pFar != NULL) { 
     60                pFar->_pNearProtocol = NULL; 
     61                if (_deleteFar) { 
     62                        pFar->EnqueueForDelete(); 
     63                } 
     64        } 
     65        if (pNear != NULL) { 
     66                pNear->_pFarProtocol = NULL; 
     67                if (_deleteNear) { 
     68                        pNear->EnqueueForDelete(); 
     69                } 
     70        } 
    6971#ifdef LOG_CONSTRUCTOR_DESTRUCTOR 
    7072        FINEST("Protocol with id %d of type %s deleted; F: %p,N: %p, DF: %d, DN: %d", 
     
    7274                        _pFarProtocol, _pNearProtocol, _deleteFar, _deleteNear); 
    7375#endif 
    74         if (_pApplication != NULL) { 
    75                 _pApplication->UnRegisterProtocol(this); 
    76                 _pApplication = NULL; 
    77         } 
    7876        ProtocolManager::UnRegisterProtocol(this); 
    7977} 
     
    330328 
    331329void BaseProtocol::SetApplication(BaseClientApplication *pApplication) { 
     330        //1. Get the old and the new application name and id 
     331        string oldAppName = "(none)"; 
     332        uint32_t oldAppId = 0; 
     333        string newAppName = "(none)"; 
     334        uint32_t newAppId = 0; 
     335        if (_pApplication != NULL) { 
     336                oldAppName = _pApplication->GetName(); 
     337                oldAppId = _pApplication->GetId(); 
     338        } 
     339        if (pApplication != NULL) { 
     340                newAppName = pApplication->GetName(); 
     341                newAppId = pApplication->GetId(); 
     342        } 
     343 
     344        //2. Are we landing on the same application? 
     345        if (oldAppId == newAppId) { 
     346                return; 
     347        } 
     348 
     349        //3. If the application is the same, return. Otherwise, unregister 
    332350        if (_pApplication != NULL) { 
    333351                _pApplication->UnRegisterProtocol(this); 
    334352                _pApplication = NULL; 
    335353        } 
     354 
     355        //4. Setup the new application 
    336356        _pApplication = pApplication; 
    337         _pApplication->RegisterProtocol(this); 
    338 } 
    339  
    340 void BaseProtocol::ResetApplication() { 
    341         _pApplication = NULL; 
     357 
     358        //5. Register to it 
     359        if (_pApplication != NULL) { 
     360                _pApplication->RegisterProtocol(this); 
     361        } 
     362 
     363        //6. Trigger log to production 
     364        //      FINEST("********** %s -> %s ********** %s", STR(oldAppName), STR(newAppName), 
     365        //                      STR(*this)); 
    342366} 
    343367 
  • trunk/sources/thelib/src/protocols/protocolmanager.cpp

    r2 r142  
    11/*  
    2 *  Copyright (c) 2010, 
    3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
    4  
    5 *  This file is part of crtmpserver. 
    6 *  crtmpserver is free software: you can redistribute it and/or modify 
    7 *  it under the terms of the GNU General Public License as published by 
    8 *  the Free Software Foundation, either version 3 of the License, or 
    9 *  (at your option) any later version. 
    10  
    11 *  crtmpserver is distributed in the hope that it will be useful, 
    12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    14 *  GNU General Public License for more details. 
    15  
    16 *  You should have received a copy of the GNU General Public License 
    17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
    18 */ 
     2 *  Copyright (c) 2010, 
     3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
     4 * 
     5 *  This file is part of crtmpserver. 
     6 *  crtmpserver is free software: you can redistribute it and/or modify 
     7 *  it under the terms of the GNU General Public License as published by 
     8 *  the Free Software Foundation, either version 3 of the License, or 
     9 *  (at your option) any later version. 
     10 * 
     11 *  crtmpserver is distributed in the hope that it will be useful, 
     12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 *  GNU General Public License for more details. 
     15 * 
     16 *  You should have received a copy of the GNU General Public License 
     17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
     18 */ 
    1919 
    2020 
     
    2626 
    2727void ProtocolManager::RegisterProtocol(BaseProtocol *pProtocol) { 
    28     if (MAP_HAS1(_activeProtocols, pProtocol->GetId())) 
    29         return; 
    30     if (MAP_HAS1(_deadProtocols, pProtocol->GetId())) 
    31         return; 
    32     _activeProtocols[pProtocol->GetId()] = pProtocol; 
     28        if (MAP_HAS1(_activeProtocols, pProtocol->GetId())) 
     29                return; 
     30        if (MAP_HAS1(_deadProtocols, pProtocol->GetId())) 
     31                return; 
     32        _activeProtocols[pProtocol->GetId()] = pProtocol; 
    3333} 
    3434 
    3535void ProtocolManager::UnRegisterProtocol(BaseProtocol *pProtocol) { 
    36     if (MAP_HAS1(_activeProtocols, pProtocol->GetId())) 
    37         _activeProtocols.erase(pProtocol->GetId()); 
    38     if (MAP_HAS1(_deadProtocols, pProtocol->GetId())) 
    39         _deadProtocols.erase(pProtocol->GetId()); 
     36        if (MAP_HAS1(_activeProtocols, pProtocol->GetId())) 
     37                _activeProtocols.erase(pProtocol->GetId()); 
     38        if (MAP_HAS1(_deadProtocols, pProtocol->GetId())) 
     39                _deadProtocols.erase(pProtocol->GetId()); 
    4040} 
    4141 
    4242void ProtocolManager::EnqueueForDelete(BaseProtocol *pProtocol) { 
    43     FINEST("Enqueue for delete for protool %s", STR(*pProtocol)); 
    44     if (MAP_HAS1(_activeProtocols, pProtocol->GetId())) 
    45         _activeProtocols.erase(pProtocol->GetId()); 
    46     if (!MAP_HAS1(_deadProtocols, pProtocol->GetId())) 
    47         _deadProtocols[pProtocol->GetId()] = pProtocol; 
     43        FINEST("Enqueue for delete for protool %s", STR(*pProtocol)); 
     44        pProtocol->SetApplication(NULL); 
     45        if (MAP_HAS1(_activeProtocols, pProtocol->GetId())) 
     46                _activeProtocols.erase(pProtocol->GetId()); 
     47        if (!MAP_HAS1(_deadProtocols, pProtocol->GetId())) 
     48                _deadProtocols[pProtocol->GetId()] = pProtocol; 
    4849} 
    4950 
    5051void ProtocolManager::CleanupDeadProtocols() { 
    51     while (_deadProtocols.size() > 0) { 
    52         BaseProtocol *pBaseProtocol = MAP_VAL(_deadProtocols.begin()); 
    53         delete pBaseProtocol; 
    54     } 
     52        while (_deadProtocols.size() > 0) { 
     53                BaseProtocol *pBaseProtocol = MAP_VAL(_deadProtocols.begin()); 
     54                delete pBaseProtocol; 
     55        } 
    5556} 
    5657 
    5758void ProtocolManager::Shutdown() { 
    58     while (_activeProtocols.size() > 0) { 
    59         EnqueueForDelete(MAP_VAL(_activeProtocols.begin())); 
    60     } 
     59        while (_activeProtocols.size() > 0) { 
     60                EnqueueForDelete(MAP_VAL(_activeProtocols.begin())); 
     61        } 
    6162} 
    6263 
    6364BaseProtocol * ProtocolManager::GetProtocol(uint32_t id, 
    64         bool includeDeadProtocols) { 
    65     if (!includeDeadProtocols && MAP_HAS1(_deadProtocols, id)) 
    66         return NULL; 
    67     if (MAP_HAS1(_activeProtocols, id)) 
    68         return _activeProtocols[id]; 
    69     if (MAP_HAS1(_deadProtocols, id)) 
    70         return _deadProtocols[id]; 
    71     return NULL; 
     65                bool includeDeadProtocols) { 
     66        if (!includeDeadProtocols && MAP_HAS1(_deadProtocols, id)) 
     67                return NULL; 
     68        if (MAP_HAS1(_activeProtocols, id)) 
     69                return _activeProtocols[id]; 
     70        if (MAP_HAS1(_deadProtocols, id)) 
     71                return _deadProtocols[id]; 
     72        return NULL; 
    7273} 
    7374 
  • trunk/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp

    r140 r142  
    5454 
    5555        FOR_MAP(_connections, uint32_t, BaseRTMPProtocol *, i) { 
    56                 MAP_VAL(i)->ResetApplication(); 
     56                MAP_VAL(i)->SetApplication(NULL); 
    5757                MAP_VAL(i)->EnqueueForDelete(); 
    5858        } 
  • trunk/sources/thelib/src/protocols/rtmp/basertmpprotocol.cpp

    r131 r142  
    7474        _inboundChunkSize = 128; 
    7575        _outboundChunkSize = 128; 
    76         _pApplication = ClientApplicationManager::GetDefaultApplication(); 
    7776 
    7877        for (uint32_t i = 0; i < MAX_STREAMS_COUNT; i++) { 
     
    8887 
    8988BaseRTMPProtocol::~BaseRTMPProtocol() { 
    90         if (_pApplication != NULL) { 
    91                 _pApplication->UnRegisterProtocol(this); 
    92                 _pProtocolHandler = NULL; 
    93                 _pApplication = NULL; 
    94         } 
    9589        for (uint32_t i = 0; i < MAX_STREAMS_COUNT; i++) { 
    9690                if (_streams[i] != NULL) { 
     
    190184 
    191185void BaseRTMPProtocol::SetApplication(BaseClientApplication *pApplication) { 
    192         assert(pApplication != NULL); 
    193186        BaseProtocol::SetApplication(pApplication); 
    194         _pProtocolHandler = (BaseRTMPAppProtocolHandler *) 
    195                         _pApplication->GetProtocolHandler(this); 
    196 } 
    197  
    198 void BaseRTMPProtocol::ResetApplication() { 
    199         BaseProtocol::ResetApplication(); 
    200         _pProtocolHandler = NULL; 
     187        if (pApplication != NULL) { 
     188                _pProtocolHandler = (BaseRTMPAppProtocolHandler *) 
     189                                pApplication->GetProtocolHandler(this); 
     190        } else { 
     191                _pProtocolHandler = NULL; 
     192        } 
    201193} 
    202194 
     
    780772                                                if (H_ML(header) == channel.lastInProcBytes) { 
    781773                                                        channel.lastInProcBytes = 0; 
    782                                                         if (_pApplication == NULL || _pProtocolHandler == NULL) { 
     774                                                        if (_pProtocolHandler == NULL) { 
    783775                                                                FATAL("RTMP connection no longer associated with an application"); 
    784776                                                                return false; 
  • trunk/sources/thelib/src/protocols/rtp/rtspprotocol.cpp

    r131 r142  
    7171void RTSPProtocol::SetApplication(BaseClientApplication *pApplication) { 
    7272        BaseProtocol::SetApplication(pApplication); 
    73         _pProtocolHandler = (BaseRTSPAppProtocolHandler *) 
    74                         _pApplication->GetProtocolHandler(GetType()); 
    75         if (_pProtocolHandler == NULL) { 
    76                 FATAL("Protocol handler not found"); 
    77                 EnqueueForDelete(); 
     73        if (pApplication != NULL) { 
     74                _pProtocolHandler = (BaseRTSPAppProtocolHandler *) 
     75                                pApplication->GetProtocolHandler(GetType()); 
     76                if (_pProtocolHandler == NULL) { 
     77                        FATAL("Protocol handler not found"); 
     78                        EnqueueForDelete(); 
     79                } 
     80        } else { 
     81                _pProtocolHandler = NULL; 
    7882        } 
    7983} 
  • trunk/sources/thelib/src/protocols/tcpprotocol.cpp

    r2 r142  
    11/*  
    2 *  Copyright (c) 2010, 
    3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
    4  
    5 *  This file is part of crtmpserver. 
    6 *  crtmpserver is free software: you can redistribute it and/or modify 
    7 *  it under the terms of the GNU General Public License as published by 
    8 *  the Free Software Foundation, either version 3 of the License, or 
    9 *  (at your option) any later version. 
    10  
    11 *  crtmpserver is distributed in the hope that it will be useful, 
    12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    14 *  GNU General Public License for more details. 
    15  
    16 *  You should have received a copy of the GNU General Public License 
    17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
    18 */ 
     2 *  Copyright (c) 2010, 
     3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
     4 * 
     5 *  This file is part of crtmpserver. 
     6 *  crtmpserver is free software: you can redistribute it and/or modify 
     7 *  it under the terms of the GNU General Public License as published by 
     8 *  the Free Software Foundation, either version 3 of the License, or 
     9 *  (at your option) any later version. 
     10 * 
     11 *  crtmpserver is distributed in the hope that it will be useful, 
     12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 *  GNU General Public License for more details. 
     15 * 
     16 *  You should have received a copy of the GNU General Public License 
     17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
     18 */ 
    1919 
    2020 
     
    2424TCPProtocol::TCPProtocol() 
    2525: BaseProtocol(PT_TCP) { 
    26     _decodedBytesCount = 0; 
    27     _pCarrier = NULL; 
     26        _decodedBytesCount = 0; 
     27        _pCarrier = NULL; 
    2828} 
    2929 
    3030TCPProtocol::~TCPProtocol() { 
    31     if (_pCarrier != NULL) { 
    32         IOHandler *pCarrier = _pCarrier; 
    33         _pCarrier = NULL; 
    34         if (pCarrier->GetType() == IOHT_TCP_CARRIER) 
    35             ((TCPCarrier *) pCarrier)->ResetProtocol(); 
    36         if (pCarrier->GetType() == IOHT_STDIO) 
    37             ((StdioCarrier *) pCarrier)->ResetProtocol(); 
    38         delete pCarrier; 
    39     } 
     31        if (_pCarrier != NULL) { 
     32                IOHandler *pCarrier = _pCarrier; 
     33                _pCarrier = NULL; 
     34                pCarrier->SetProtocol(NULL); 
     35                delete pCarrier; 
     36        } 
    4037} 
    4138 
    4239bool TCPProtocol::Initialize(Variant &parameters) { 
    43     return true; 
     40        return true; 
    4441} 
    4542 
    4643IOHandler *TCPProtocol::GetIOHandler() { 
    47     return _pCarrier; 
     44        return _pCarrier; 
    4845} 
    4946 
    5047void TCPProtocol::SetIOHandler(IOHandler *pIOHandler) { 
    51     if (pIOHandler != NULL) { 
    52         if ((pIOHandler->GetType() != IOHT_TCP_CARRIER) 
    53                 && (pIOHandler->GetType() != IOHT_STDIO)) { 
    54             ASSERT("This protocol accepts only TCP carriers"); 
    55         } 
    56     } 
    57     _pCarrier = pIOHandler; 
     48        if (pIOHandler != NULL) { 
     49                if ((pIOHandler->GetType() != IOHT_TCP_CARRIER) 
     50                                && (pIOHandler->GetType() != IOHT_STDIO)) { 
     51                        ASSERT("This protocol accepts only TCP carriers"); 
     52                } 
     53        } 
     54        _pCarrier = pIOHandler; 
    5855} 
    5956 
    6057bool TCPProtocol::AllowFarProtocol(uint64_t type) { 
    61     WARN("This protocol doesn't accept any far protocol"); 
    62     return false; 
     58        WARN("This protocol doesn't accept any far protocol"); 
     59        return false; 
    6360} 
    6461 
    6562bool TCPProtocol::AllowNearProtocol(uint64_t type) { 
    66     //    if ( 
    67     //            type == PT_INBOUNDRTMP || 
    68     //            type == PT_OUTBOUNDRTMP || 
    69     //            type == PT_RTMPE || 
    70     //            type == PT_SSL || 
    71     //            type == PT_INBOUNDDNS || 
    72     //            type == PT_OUTBOUNDDNS || 
    73     //            type == PT_INBOUNDTS || 
    74     //            type == PT_INBOUNDHTTP || 
    75     //            type == PT_OUTBOUNDHTTP || 
    76     //            false 
    77     //            ) 
    78     //        return true; 
    79     //    WARN("Near protocol %s not accepted by %s", 
    80     //            STR(tagToString(type)), 
    81     //            STR(tagToString(_type))); 
    82     //    return false; 
    83     return true; 
     63        //    if ( 
     64        //            type == PT_INBOUNDRTMP || 
     65        //            type == PT_OUTBOUNDRTMP || 
     66        //            type == PT_RTMPE || 
     67        //            type == PT_SSL || 
     68        //            type == PT_INBOUNDDNS || 
     69        //            type == PT_OUTBOUNDDNS || 
     70        //            type == PT_INBOUNDTS || 
     71        //            type == PT_INBOUNDHTTP || 
     72        //            type == PT_OUTBOUNDHTTP || 
     73        //            false 
     74        //            ) 
     75        //        return true; 
     76        //    WARN("Near protocol %s not accepted by %s", 
     77        //            STR(tagToString(type)), 
     78        //            STR(tagToString(_type))); 
     79        //    return false; 
     80        return true; 
    8481} 
    8582 
    8683IOBuffer * TCPProtocol::GetInputBuffer() { 
    87     return &_inputBuffer; 
     84        return &_inputBuffer; 
    8885} 
    8986 
    9087bool TCPProtocol::SignalInputData(int32_t recvAmount) { 
    91     _decodedBytesCount += recvAmount; 
    92     //FINEST("_decodedBytesCount: %d", _decodedBytesCount); 
    93     return _pNearProtocol->SignalInputData(_inputBuffer); 
     88        _decodedBytesCount += recvAmount; 
     89        //FINEST("_decodedBytesCount: %d", _decodedBytesCount); 
     90        return _pNearProtocol->SignalInputData(_inputBuffer); 
    9491} 
    9592 
    9693bool TCPProtocol::SignalInputData(IOBuffer & /* ignored */) { 
    97     ASSERT("OPERATION NOT SUPPORTED"); 
     94        ASSERT("OPERATION NOT SUPPORTED"); 
    9895        return false; 
    9996} 
    10097 
    10198bool TCPProtocol::EnqueueForOutbound() { 
    102     if (_pCarrier == NULL) { 
    103         ASSERT("TCPProtocol has no carrier"); 
    104         return false; 
    105     } 
    106     return _pCarrier->SignalOutputData(); 
     99        if (_pCarrier == NULL) { 
     100                ASSERT("TCPProtocol has no carrier"); 
     101                return false; 
     102        } 
     103        return _pCarrier->SignalOutputData(); 
    107104} 
    108105 
    109106uint32_t TCPProtocol::GetDecodedBytesCount() { 
    110     return _decodedBytesCount; 
     107        return _decodedBytesCount; 
    111108} 
    112109 
  • trunk/sources/thelib/src/protocols/timer/basetimerprotocol.cpp

    r56 r142  
    2424BaseTimerProtocol::BaseTimerProtocol() 
    2525: BaseProtocol(PT_TIMER) { 
    26         _pTimer = new IOTimer(this); 
     26        _pTimer = new IOTimer(); 
     27        _pTimer->SetProtocol(this); 
    2728} 
    2829 
     
    3132                IOTimer *pTimer = _pTimer; 
    3233                _pTimer = NULL; 
    33                 pTimer->ResetProtocol(); 
     34                pTimer->SetProtocol(NULL); 
    3435                delete pTimer; 
    3536        } 
  • trunk/sources/thelib/src/protocols/ts/inboundtsprotocol.cpp

    r56 r142  
    143143 
    144144void InboundTSProtocol::SetApplication(BaseClientApplication *pApplication) { 
    145         assert(pApplication != NULL); 
    146145        BaseProtocol::SetApplication(pApplication); 
    147         _pProtocolHandler = (BaseTSAppProtocolHandler *) 
    148                         _pApplication->GetProtocolHandler(this); 
    149 } 
    150  
    151 void InboundTSProtocol::ResetApplication() { 
    152         BaseProtocol::ResetApplication(); 
    153         _pProtocolHandler = NULL; 
     146        if (pApplication != NULL) { 
     147                _pProtocolHandler = (BaseTSAppProtocolHandler *) 
     148                                pApplication->GetProtocolHandler(this); 
     149        } else { 
     150                _pProtocolHandler = NULL; 
     151        } 
    154152} 
    155153 
  • trunk/sources/thelib/src/protocols/udpprotocol.cpp

    r2 r142  
    3232                IOHandler *pCarrier = _pCarrier; 
    3333                _pCarrier = NULL; 
    34                 ((UDPCarrier *) pCarrier)->ResetProtocol(); 
     34                pCarrier->SetProtocol(NULL); 
    3535                delete pCarrier; 
    3636        } 
  • trunk/sources/thelib/src/protocols/variant/basevariantprotocol.cpp

    r17 r142  
    3939 
    4040void BaseVariantProtocol::SetApplication(BaseClientApplication *pApplication) { 
    41         if (pApplication == NULL) 
    42                 return; 
    4341        BaseProtocol::SetApplication(pApplication); 
    44         _pProtocolHandler = (BaseVariantAppProtocolHandler *) 
    45                         _pApplication->GetProtocolHandler(this); 
     42        if (pApplication != NULL) { 
     43                _pProtocolHandler = (BaseVariantAppProtocolHandler *) 
     44                                pApplication->GetProtocolHandler(this); 
     45        } else { 
     46                _pProtocolHandler = NULL; 
     47        } 
    4648} 
    4749 
Note: See TracChangeset for help on using the changeset viewer.