~ubuntu-branches/ubuntu/wily/psi/wily

« back to all changes in this revision

Viewing changes to cutestuff/legacy/servsock.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

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