~ubuntu-branches/ubuntu/trusty/jreen/trusty

« back to all changes in this revision

Viewing changes to 3rdparty/icesupport/servsock.cpp

  • Committer: Package Import Robot
  • Author(s): Prasad Murthy
  • Date: 2013-03-08 00:00:33 UTC
  • Revision ID: package-import@ubuntu.com-20130308000033-x8thp6syo1kkh63s
Tags: upstream-1.1.1
ImportĀ upstreamĀ versionĀ 1.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * servsock.cpp - simple wrapper to QServerSocket
 
3
 * Copyright (C) 2003  Justin Karneges
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2.1 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#include "servsock.h"
 
22
 
 
23
// CS_NAMESPACE_BEGIN
 
24
 
 
25
//----------------------------------------------------------------------------
 
26
// ServSock
 
27
//----------------------------------------------------------------------------
 
28
class ServSock::Private
 
29
{
 
30
public:
 
31
        Private() {}
 
32
 
 
33
        ServSockSignal *serv;
 
34
};
 
35
 
 
36
ServSock::ServSock(QObject *parent)
 
37
:QObject(parent)
 
38
{
 
39
        d = new Private;
 
40
        d->serv = 0;
 
41
}
 
42
 
 
43
ServSock::~ServSock()
 
44
{
 
45
        stop();
 
46
        delete d;
 
47
}
 
48
 
 
49
bool ServSock::isActive() const
 
50
{
 
51
        return (d->serv ? true: false);
 
52
}
 
53
 
 
54
bool ServSock::listen(quint16 port)
 
55
{
 
56
        stop();
 
57
 
 
58
        d->serv = new ServSockSignal(this);
 
59
        if(!d->serv->listen(QHostAddress::Any, port)) {
 
60
                delete d->serv;
 
61
                d->serv = 0;
 
62
                return false;
 
63
        }
 
64
        connect(d->serv, SIGNAL(connectionReady(int)), SLOT(sss_connectionReady(int)));
 
65
 
 
66
        return true;
 
67
}
 
68
 
 
69
void ServSock::stop()
 
70
{
 
71
        delete d->serv;
 
72
        d->serv = 0;
 
73
}
 
74
 
 
75
int ServSock::port() const
 
76
{
 
77
        if(d->serv)
 
78
                return d->serv->serverPort();
 
79
        else
 
80
                return -1;
 
81
}
 
82
 
 
83
QHostAddress ServSock::address() const
 
84
{
 
85
        if(d->serv)
 
86
                return d->serv->serverAddress();
 
87
        else
 
88
                return QHostAddress();
 
89
}
 
90
 
 
91
void ServSock::sss_connectionReady(int s)
 
92
{
 
93
        connectionReady(s);
 
94
}
 
95
 
 
96
 
 
97
//----------------------------------------------------------------------------
 
98
// ServSockSignal
 
99
//----------------------------------------------------------------------------
 
100
ServSockSignal::ServSockSignal(QObject *parent)
 
101
:QTcpServer(parent)
 
102
{
 
103
        setMaxPendingConnections(16);
 
104
}
 
105
 
 
106
void ServSockSignal::incomingConnection(int socketDescriptor)
 
107
{
 
108
        connectionReady(socketDescriptor);
 
109
}
 
110
 
 
111
// CS_NAMESPACE_END