~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to cutestuff/network/servsock.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

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(Q_UINT16 port)
55
 
{
56
 
        stop();
57
 
 
58
 
        d->serv = new ServSockSignal(port);
59
 
        if(!d->serv->ok()) {
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->port();
79
 
        else
80
 
                return -1;
81
 
}
82
 
 
83
 
QHostAddress ServSock::address() const
84
 
{
85
 
        if(d->serv)
86
 
                return d->serv->address();
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(int port)
101
 
:QServerSocket(port, 16)
102
 
{
103
 
}
104
 
 
105
 
void ServSockSignal::newConnection(int x)
106
 
{
107
 
        connectionReady(x);
108
 
}
109
 
 
110
 
// CS_NAMESPACE_END