delete socket;
return;
}
- emit (emit this->pending(*socket))?this->newConnection():socket->disconnectFromHost();
+ emit (emit this->pending(*socket))?this->newConnection():socket->abort();
}
tcpSocket::tcpSocket(quint64 buffersize, QObject *parent):QTcpSocket(parent){
}
void tcpSocket::read_data(){
while(this->bytesAvailable()>0){
+#ifdef DEBUG
qDebug()<<"Server Event Mode:"<<this->event<<"Server Available bytes:"<<this->bytesAvailable();
+#endif
switch(this->event){
case tcpSocket::headsize: this->size_event(); break;
case tcpSocket::header_receive: this->header_event(); break;
this->event=tcpSocket::data;
}
void tcpSocket::data_event(){
- if(this->bytesAvailable()<this->header_data().datasize()) return;
+ if((quint64)this->bytesAvailable()<this->header_data().datasize()) return;
quint64 final_readsize=this->head_data.datasize()%this->buffer_size,
read_count=(this->head_data.datasize()-final_readsize)/this->buffer_size;
tmp_buffer=msg.toUtf8();
QBuffer memoryStream(&tmp_buffer,this);
if(!memoryStream.open(QIODevice::ReadOnly)){
- this->setErrorString("Memory Stream couldn't open.");
+ this->setErrorString(tr("Memory Stream couldn't open."));
emit this->error(QAbstractSocket::UnknownSocketError);
return (*this);
}
emit this->sentData();
return (*this);
}
-tcpSocket &tcpSocket::operator<<(QFile &file){
+tcpSocket &tcpSocket::operator<<(QFile &src_file){
+ QFile file(src_file.fileName(),this);
if(!this->state()!=QAbstractSocket::ConnectedState)return (*this);
this->head_data=header(this->senderName,QFileInfo(file));
QByteArray tmp_buffer;
this->write(tmp_buffer);
if(!this->flush())return (*this);
tmp_buffer.clear();
- while(this->write(file.read(this->buffer_size))>0)
+ emit this->file_header_sent();
+ if(!file.open(QIODevice::ReadOnly)){
+ this->setErrorString(tr("The file stream couldn't open."));
+ emit this->error(QAbstractSocket::UnknownSocketError);
+ return (*this);
+ }
+ while(this->write(file.read(this->buffer_size))>0&&!this->check_canceled_then_abort()){
if(!this->flush())return (*this);
+ emit this->sending_file_progress(file.pos());
+ }
emit this->sentData();
return (*this);
}