Vidalia
0.2.17
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file net.cpp 00013 ** \brief Common network I/O and utility functions 00014 */ 00015 00016 #include "net.h" 00017 00018 #include <QTcpSocket> 00019 #include <QLocalSocket> 00020 00021 00022 /** Attempts a connection to <b>host</b> on <b>port</b>. Returns true if the 00023 * connection was successful, or false if the connection attempt failed. */ 00024 bool 00025 net_test_connect(QHostAddress host, quint16 port, int timeout) 00026 { 00027 QTcpSocket sock; 00028 sock.connectToHost(host, port); 00029 if (!sock.waitForConnected(timeout)) { 00030 return false; 00031 } 00032 sock.disconnectFromHost(); 00033 return true; 00034 } 00035 00036 bool 00037 socket_test_connect(QString server, int timeout) 00038 { 00039 QLocalSocket sock; 00040 sock.connectToServer(server); 00041 if (!sock.waitForConnected(timeout)) { 00042 return false; 00043 } 00044 sock.disconnectFromServer(); 00045 return true; 00046 } 00047