Vidalia 0.3.1
net.cpp
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file net.cpp
13** \brief Common network I/O and utility functions
14*/
15
16#include "net.h"
17
18#include <QTcpSocket>
19#include <QLocalSocket>
20
21
22/** Attempts a connection to <b>host</b> on <b>port</b>. Returns true if the
23 * connection was successful, or false if the connection attempt failed. */
24bool
25net_test_connect(QHostAddress host, quint16 port, int timeout)
26{
27 QTcpSocket sock;
28 sock.connectToHost(host, port);
29 if (!sock.waitForConnected(timeout)) {
30 return false;
31 }
32 sock.disconnectFromHost();
33 return true;
34}
35
36bool
37socket_test_connect(QString server, int timeout)
38{
39 QLocalSocket sock;
40 sock.connectToServer(server);
41 if (!sock.waitForConnected(timeout)) {
42 return false;
43 }
44 sock.disconnectFromServer();
45 return true;
46}
47
bool socket_test_connect(QString server, int timeout)
Definition: net.cpp:37
bool net_test_connect(QHostAddress host, quint16 port, int timeout)
Definition: net.cpp:25