summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/SelectorThread.h
blob: 149c6f4083dd9cbd5b460cd28f89440b7b1e7720 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// **********************************************************************
//
// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef ICE_SELECTOR_THREAD_H
#define ICE_SELECTOR_THREAD_H

#include <IceUtil/Shared.h>
#include <IceUtil/Handle.h>
#include <IceUtil/Mutex.h>
#include <IceUtil/Thread.h>
#include <IceUtil/Timer.h>

#include <Ice/Config.h>
#include <Ice/SelectorThreadF.h>
#include <Ice/SocketReadyCallback.h>
#include <Ice/InstanceF.h>
#include <Ice/Selector.h>

#include <deque>

namespace IceInternal
{

class SelectorThread : public IceUtil::Shared, IceUtil::Mutex
{
public:

    SelectorThread(const InstancePtr&);
    virtual ~SelectorThread();

    void destroy();

    void incFdsInUse();
    void decFdsInUse();

    void _register(SOCKET, const SocketReadyCallbackPtr&, SocketStatus status, int timeout);
    void unregister(const SocketReadyCallbackPtr&);
    void finish(const SocketReadyCallbackPtr&);

    void joinWithThread();

private:

    void run();

    class HelperThread : public IceUtil::Thread
    {
    public:
        
        HelperThread(const SelectorThreadPtr&);
        virtual void run();

    private:

        SelectorThreadPtr _selectorThread;
    };
    friend class HelperThread;

    InstancePtr _instance;
    bool _destroyed;

    Selector<SocketReadyCallback> _selector;

    std::deque<SocketReadyCallbackPtr> _finished;

    IceUtil::ThreadPtr _thread;
    IceUtil::TimerPtr _timer;
};

}

#endif