File: ClientMultiplexer.C

package info (click to toggle)
dxpc 3.9.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,140 kB
  • ctags: 1,253
  • sloc: cpp: 12,036; sh: 2,823; makefile: 78
file content (71 lines) | stat: -rw-r--r-- 1,538 bytes parent folder | download | duplicates (3)
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
#include "dxpcconf.h"

#include "ClientMultiplexer.H"
#include "ClientChannel.H"
#include "util.H"

ClientMultiplexer::ClientMultiplexer(int proxyFD,
                                     int
                                     statisticsLevel):
    Multiplexer(proxyFD),
    statisticsLevel_(statisticsLevel)
{
    for (unsigned i = 0; i < MAX_CONNECTIONS; i++)
    {
        _channelMap[i] = -1;
    }
}

void ClientMultiplexer::createNewConnection(int clientFD)
{
    int channelNum = -1;

    for (unsigned i = 0; i < MAX_CONNECTIONS; i++)
    {
        if (_channelMap[i] == -1)
        {
            _channelMap[i] = clientFD;
            channelNum = i;
            break;
        }
    }

    channels_[channelNum] = new ClientChannel(clientFD, statisticsLevel_);
    unsigned char message[3];

    message[0] = 0;
    message[1] = (unsigned char) CTRL_NEW_CONNECTION;
    message[2] = channelNum;
    WriteAll(proxyFD_, message, 3);
}

int ClientMultiplexer::createNewConnectionFromProxy(int)
{
    CERR <<
        "Internal error: in ClientMultiplexer::createNewConnectionFromProxy"
        << ENDL;
    return 0;
}

int ClientMultiplexer::channelIDToFD(int channelID) const
{
    return _channelMap[channelID];
}

int ClientMultiplexer::fdToChannelID(int fd) const
{
    for (unsigned i = 0; i < MAX_CONNECTIONS; i++)
    {
        if (_channelMap[i] == fd)
        {
            return i;
        }
    }

    return -1;
}

void ClientMultiplexer::cleanupChannelFDMapping(int channelNum)
{
    _channelMap[channelNum] = -1;
}