summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Schneider2014-05-22 11:41:31 +0200
committerManuel Schneider2014-05-22 11:44:19 +0200
commitb2dd6e8b0b86446cb4d3f32403b029ee2496cc11 (patch)
tree7791fd2792b4c3ee4acb1b22c6b8bbeb20b55601
parent[Client] Make setTutor inline and drop the communication stuff since the clie... (diff)
downloadpvs2-b2dd6e8b0b86446cb4d3f32403b029ee2496cc11.tar.gz
pvs2-b2dd6e8b0b86446cb4d3f32403b029ee2496cc11.tar.xz
pvs2-b2dd6e8b0b86446cb4d3f32403b029ee2496cc11.zip
Fix segfault. Drop nullpointer polls since SslSocket is now const. [id == _VNCCLIENT] Logical reduction. Cleanup header.
-rw-r--r--src/client/net/serverconnection.cpp4
-rw-r--r--src/server/net/client.cpp39
-rw-r--r--src/server/net/client.h51
3 files changed, 42 insertions, 52 deletions
diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp
index c590dc5..0849eab 100644
--- a/src/client/net/serverconnection.cpp
+++ b/src/client/net/serverconnection.cpp
@@ -342,9 +342,9 @@ void ServerConnection::onVncViewerStartStop(const bool started, const int client
_toServer.reset();
_toServer.setField(_ID, _VNCCLIENT);
if (started)
- _toServer.setField("ENABLED", QByteArray("1"));
+ _toServer.setField("ENABLED", __TRUE);
else
- _toServer.setField("ENABLED", QByteArray("0"));
+ _toServer.setField("ENABLED", __FALSE);
_toServer.setField("CLIENTID", QString::number(clientId));
sendMessage(_toServer);
}
diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp
index 3859f06..67b25b2 100644
--- a/src/server/net/client.cpp
+++ b/src/server/net/client.cpp
@@ -56,12 +56,8 @@ Client::Client(QSslSocket* socket) : _socket(socket)
/******************************************************************************/
Client::~Client()
{
- if (_socket != NULL)
- {
- qCritical("**** SOCKET DELETE IN DESTRUCTOR");
- _socket->deleteLater();
- }
- qDebug("*** Client %s destroyed.", qPrintable(_socket->peerAddress().toString()));
+ qDebug() << "*** Client" << _host << " destroyed.";
+ _socket->deleteLater();
}
/******************************************************************************/
@@ -90,7 +86,7 @@ void Client::timerEvent(QTimerEvent* event)
/******************************************************************************/
void Client::sendMessage(NetworkMessage& message)
{
- if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState)
+ if (_socket->state() != QAbstractSocket::ConnectedState)
return;
message.writeMessage(_socket);
if (!message.writeComplete())
@@ -102,7 +98,7 @@ void Client::sendMessage(NetworkMessage& message)
/******************************************************************************/
void Client::requestThumb(const int width, const int height)
{
- if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState)
+ if (_socket->state() != QAbstractSocket::ConnectedState)
{
qDebug("requestThumb called in bad state");
return;
@@ -118,13 +114,12 @@ void Client::requestThumb(const int width, const int height)
void Client::onDataArrival()
{
//
- if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState)
+ if (_socket->state() != QAbstractSocket::ConnectedState)
{
qDebug("dataArrival called in bad state");
return;
}
- //qDebug() << _socket->bytesAvailable() << " bytes to read";
bool ret;
while (_socket->bytesAvailable())
{
@@ -138,8 +133,6 @@ void Client::onDataArrival()
{
this->handleMsg();
_fromClient.reset();
- if (_socket == NULL)
- return;
}
}
}
@@ -198,26 +191,25 @@ void Client::handleMsg()
{
// Client tells us that it started or stopped displaying a remote screen via VNC
_activeVncClient = (_fromClient.getFieldString("ENABLED").toInt() != 0);
- const int other = (int)_fromClient.getFieldString("CLIENTID").toInt();
+ const int projectionSource = (int)_fromClient.getFieldString("CLIENTID").toInt();
- const int last = _activeVncClient ? _currentProjectionSource : other;
-
- if (!_activeVncClient)
+ if (_activeVncClient)
{
- if (other == _desiredProjectionSource)
+ qDebug() << "Client " << _name << " started its VNC client (watching " << projectionSource << ")";
+ if (projectionSource == _desiredProjectionSource)
_desiredProjectionSource = 0;
- _currentProjectionSource = 0;
- qDebug() << "Client " << _name << " stopped its VNC client (watched " << last << ")";
+ emit vncClientStateChange(this, _currentProjectionSource);
+ _currentProjectionSource = projectionSource;
}
else
{
- if (other == _desiredProjectionSource)
+ qDebug() << "Client " << _name << " stopped its VNC client (watched " << projectionSource << ")";
+ if (projectionSource == _desiredProjectionSource)
_desiredProjectionSource = 0;
- _currentProjectionSource = other;
- qDebug() << "Client " << _name << " started its VNC client (watching " << other << ")";
+ emit vncClientStateChange(this, _currentProjectionSource);
+ _currentProjectionSource = 0;
}
- emit vncClientStateChange(this, last);
}
return;
}
@@ -339,7 +331,6 @@ void Client::disconnect()
qDebug("*** Client %s disconnected.", qPrintable(_socket->peerAddress().toString()));
_socket->blockSignals(true);
_socket->abort();
- _socket->deleteLater();
this->deleteLater();
emit disconnected();
}
diff --git a/src/server/net/client.h b/src/server/net/client.h
index 389d05c..c148e76 100644
--- a/src/server/net/client.h
+++ b/src/server/net/client.h
@@ -46,16 +46,20 @@ public:
inline const int id() const { return _id; }
inline const int desiredProjectionSource() const { return _desiredProjectionSource; }
inline const int currentProjectionSource() const { return _currentProjectionSource; }
+ // To be replaced by states
+ inline const bool isActiveVncClient() const { return _activeVncClient; }
+ inline const bool isActiveVncServer() const { return _vncPort > 0; }
+ inline const bool isProjectionSource() const { return _isProjectionSource; }
// Setters
inline void setProjectionSource(bool enable) { _isProjectionSource = enable; }
inline void setDesiredProjectionSource(int source) { _desiredProjectionSource = source; }
inline void setTutor(bool enable){ _isTutor = enable; }
- // To be replaced by states
- inline const bool isActiveVncClient() const { return _activeVncClient; }
- inline const bool isActiveVncServer() const { return _vncPort > 0; }
- inline const bool isProjectionSource() const { return _isProjectionSource; }
+
+ //New ones
+//b void startVncServer();
+
//Send message stuff
@@ -69,29 +73,24 @@ public:
private:
QSslSocket * const _socket;
- State _state;
-
- static int _clientIdCounter;
- int _authed; // 0 = challenge sent, awaiting reply 1 = challenge ok, client challenge replied, awaiting login, 2 = ESTABLISHED
- QString _name;
- QString _host;
- QByteArray _challenge;
- qint64 _pingTimeout;
+ State _state;
+ int _authed; // 0 = challenge sent, awaiting reply 1 = challenge ok, client challenge replied, awaiting login, 2 = ESTABLISHED
+ QString _name;
+ QString _host;
+ QByteArray _challenge;
+ qint64 _pingTimeout;
NetworkMessage _fromClient;
- int _timerIdAuthTimeout, _timerPingTimeout;
- int _id; // this client's unique id
- // If this client should be projected to from another client, the other
- // client's id is set here. 0 otherwise. This is not currently used and it is
- // questionable if this makes sense, as it might just be confusing if several
- // groups students watch different other students. Also, visualizing such a
- // situation in the GUI in a meaningful way would be hard.
- int _desiredProjectionSource;
- bool _isProjectionSource; // Tells whether this client is currently the VNC broadcast source.
- int _currentProjectionSource;
- QString _vncRwPass, _vncRoPass;
- int _vncPort; // VNCserver state. Greater 0 -> active on this port. Equals 0 -> no server.
- bool _activeVncClient; // Flag indicating that the client is displaying a remote screen via VNC
- bool _isTutor; // Flag indicating that the client has been set as a tutor
+ int _timerIdAuthTimeout, _timerPingTimeout;
+ int _id; // this client's unique id
+ int _desiredProjectionSource;
+ bool _isProjectionSource; // Tells whether this client is currently the VNC broadcast source.
+ int _currentProjectionSource;
+ QString _vncRwPass, _vncRoPass;
+ int _vncPort; // VNCserver state. Greater 0 -> active on this port. Equals 0 -> no server.
+ bool _activeVncClient; // Flag indicating that the client is displaying a remote screen via VNC
+ bool _isTutor; // Flag indicating that the client has been set as a tutor
+
+ static int _clientIdCounter;
void handleMsg();
void sendMessage(NetworkMessage& message);