this->canceled=true;
QTcpSocket::disconnectFromHost();
}
-bool tcpSocket::check_canceled_then_abort(){
+bool tcpSocket::check_canceled(){
if(this->canceled){
this->setErrorString(tr("The process has been canceled by user."));
emit this->error(QAbstractSocket::UnknownSocketError);
- this->abort();
return true;
}
return false;
}
+void tcpSocket::error_occured(const QAbstractSocket::SocketError err){
+ Q_UNUSED(err)
+ qDebug()<<"Error("<<this<<")"<<this->errorString();
+ this->abort();
+
+}
void tcpSocket::cancel(){this->canceled=true;}
QString tcpSocket::path_to_save() const{return this->where_to_save;}
header tcpSocket::header_data() const{return this->head_data;}
#ifdef DEBUG
qDebug()<<"threadedTcpSocket has been created and running.";
#endif
+ qRegisterMetaType<QAbstractSocket::SocketState>("SocketState");
+ qRegisterMetaType<QAbstractSocket::SocketError>("SocketError");
+
this->locks[threadedTcpSocket::BufferSize].lockForRead();
this->locks[threadedTcpSocket::SenderName].lockForRead();
tcpSocket *socket=
this->locks[threadedTcpSocket::BufferSize].unlock();
this->locks[threadedTcpSocket::SenderName].unlock();
/*Common signals*/
- connect(socket,SIGNAL(error(QAbstractSocket::SocketError)),
- SLOT(error_occured(QAbstractSocket::SocketError)),
- Qt::BlockingQueuedConnection);
connect(socket,SIGNAL(connected()),SLOT(host_connected()),Qt::BlockingQueuedConnection);
connect(socket,SIGNAL(connected()),SIGNAL(connected()));
+#ifdef DEBUG
+ connect(socket,SIGNAL(disconnected()),SLOT(host_disconnected()));
+#endif
connect(socket,SIGNAL(disconnected()),SIGNAL(disconnected()));
- connect(socket,SIGNAL(disconnected()),SLOT(host_disconnected()),
- Qt::BlockingQueuedConnection);
+
connect(socket,SIGNAL(hostFound()),SIGNAL(hostFound()));
connect(socket,SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &,QAuthenticator*)),
SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &,QAuthenticator*)));
connect(socket,SIGNAL(file_saved()),SIGNAL(file_saved()));
connect(socket,SIGNAL(file_saved()),SLOT(quit()));
connect(socket,SIGNAL(header_received()),SLOT(header_received()));
- if(!socket->setSocketDescriptor(descriptor)){
- this->_error=socket->errorString();
- emit this->error(socket->error());
- }
+ socket->setSocketDescriptor(descriptor);
this->_addrPort.first=socket->peerAddress();
this->_addrPort.second=socket->peerPort();
+ if(!emit this->pending()) socket->disconnectFromHost();
break;
}
this->locks[threadedTcpSocket::Mode].unlock();
//Cleanup
socket->abort();
}
+
void threadedTcpSocket::host_connected(){
tcpSocket *socket=qobject_cast<tcpSocket *>(this->sender());
#ifdef DEBUG
qDebug()<<"Client:"<<socket->peerAddress().toString()<<"has been connected properly.";
#endif
this->locks[threadedTcpSocket::Msg].lockForRead();
- bool r=this->_msg.isNull();
- this->locks[threadedTcpSocket::Msg].unlock();
- if(r){
+ if(this->_msg.isNull()){
this->locks[threadedTcpSocket::File].lockForRead();
(*socket)<<this->_file;
this->locks[threadedTcpSocket::File].unlock();
(*socket)<<this->_msg;
this->locks[threadedTcpSocket::Msg].unlock();
}
+ this->locks[threadedTcpSocket::Msg].unlock();
}
-void threadedTcpSocket::host_disconnected(){
- tcpSocket *socket=qobject_cast<tcpSocket *>(this->sender());
- socket->close();
+
#ifdef DEBUG
+void threadedTcpSocket::host_disconnected(){
+ this->locks[threadedTcpSocket::Mode].lockForRead();
qDebug()<<"Socket("<<((this->mode==threadedTcpSocket::Session)?"Session":"Client")<<"):Connection closed successful.";
-#endif
- socket->deleteLater();
-}
-
-void threadedTcpSocket::error_occured(const QAbstractSocket::SocketError error){
- tcpSocket *socket=(tcpSocket*)this->sender();
- this->locks[threadedTcpSocket::Error].lockForWrite();
- this->_error=socket->errorString();
- this->locks[threadedTcpSocket::Error].unlock();
- this->exit(1);
- emit this->error(error);
-}
-QString threadedTcpSocket::errorString(){
- this->locks[threadedTcpSocket::Error].lockForRead();
- QString str=this->_error;
- this->locks[threadedTcpSocket::Error].unlock();
- return str;
+ this->locks[threadedTcpSocket::Mode].unlock();
}
+#endif