aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vncviewer/CConn.cxx72
-rw-r--r--vncviewer/CConn.h4
-rw-r--r--vncviewer/vncviewer.cxx3
3 files changed, 43 insertions, 36 deletions
diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx
index 024d833a..da99c8f1 100644
--- a/vncviewer/CConn.cxx
+++ b/vncviewer/CConn.cxx
@@ -77,12 +77,12 @@ static const rfb::PixelFormat mediumColourPF(8, 8, false, true,
// Time new bandwidth estimates are weighted against (in ms)
static const unsigned bpsEstimateWindow = 1000;
-CConn::CConn(const char* vncServerName, network::Socket* socket=nullptr)
- : serverPort(0), desktop(nullptr), updateCount(0), pixelCount(0),
+CConn::CConn()
+ : serverPort(0), sock(nullptr), desktop(nullptr),
+ updateCount(0), pixelCount(0),
lastServerEncoding((unsigned int)-1), bpsEstimate(20000000)
{
setShared(::shared);
- sock = socket;
supportsLocalCursor = true;
supportsCursorPosition = true;
@@ -95,37 +95,6 @@ CConn::CConn(const char* vncServerName, network::Socket* socket=nullptr)
if (!noJpeg)
setQualityLevel(::qualityLevel);
- if(sock == nullptr) {
- try {
-#ifndef WIN32
- if (strchr(vncServerName, '/') != nullptr) {
- sock = new network::UnixSocket(vncServerName);
- serverHost = sock->getPeerAddress();
- vlog.info(_("Connected to socket %s"), serverHost.c_str());
- } else
-#endif
- {
- network::getHostAndPort(vncServerName, &serverHost, &serverPort);
-
- sock = new network::TcpSocket(serverHost.c_str(), serverPort);
- vlog.info(_("Connected to host %s port %d"),
- serverHost.c_str(), serverPort);
- }
- } catch (std::exception& e) {
- vlog.error("%s", e.what());
- abort_connection(_("Failed to connect to \"%s\":\n\n%s"),
- vncServerName, e.what());
- return;
- }
- }
-
- Fl::add_fd(sock->getFd(), FL_READ | FL_EXCEPT, socketEvent, this);
-
- setServerName(serverHost.c_str());
- setStreams(&sock->inStream(), &sock->outStream());
-
- initialiseProtocol();
-
OptionsDialog::addCallback(handleOptions, this);
}
@@ -178,6 +147,41 @@ CConn::~CConn()
}
}
+void CConn::connect(const char* vncServerName, network::Socket* socket)
+{
+ sock = socket;
+ if(sock == nullptr) {
+ try {
+#ifndef WIN32
+ if (strchr(vncServerName, '/') != nullptr) {
+ sock = new network::UnixSocket(vncServerName);
+ serverHost = sock->getPeerAddress();
+ vlog.info(_("Connected to socket %s"), serverHost.c_str());
+ } else
+#endif
+ {
+ network::getHostAndPort(vncServerName, &serverHost, &serverPort);
+
+ sock = new network::TcpSocket(serverHost.c_str(), serverPort);
+ vlog.info(_("Connected to host %s port %d"),
+ serverHost.c_str(), serverPort);
+ }
+ } catch (std::exception& e) {
+ vlog.error("%s", e.what());
+ abort_connection(_("Failed to connect to \"%s\":\n\n%s"),
+ vncServerName, e.what());
+ return;
+ }
+ }
+
+ Fl::add_fd(sock->getFd(), FL_READ | FL_EXCEPT, socketEvent, this);
+
+ setServerName(serverHost.c_str());
+ setStreams(&sock->inStream(), &sock->outStream());
+
+ initialiseProtocol();
+}
+
std::string CConn::connectionInfo()
{
std::string infoText;
diff --git a/vncviewer/CConn.h b/vncviewer/CConn.h
index b45f58d7..bc30d9b7 100644
--- a/vncviewer/CConn.h
+++ b/vncviewer/CConn.h
@@ -33,9 +33,11 @@ class DesktopWindow;
class CConn : public rfb::CConnection
{
public:
- CConn(const char* vncServerName, network::Socket* sock);
+ CConn();
~CConn();
+ void connect(const char* vncServerName, network::Socket* sock=nullptr);
+
std::string connectionInfo();
unsigned getUpdateCount();
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
index 382119b8..324ec632 100644
--- a/vncviewer/vncviewer.cxx
+++ b/vncviewer/vncviewer.cxx
@@ -181,7 +181,8 @@ static void mainloop(const char* vncserver, network::Socket* sock)
exitMainloop = false;
- cc = new CConn(vncserver, sock);
+ cc = new CConn();
+ cc->connect(vncserver, sock);
while (!exitMainloop) {
int next_timer;