OSDN Git Service

Added a flag for debug.
[greensite/jasmine.git] / network / tcpnetwork.cxx
index c667778..ad946db 100644 (file)
@@ -15,7 +15,7 @@ void tcpServer::incomingConnection(int handle){
                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){
@@ -31,7 +31,9 @@ tcpSocket::tcpSocket(const QString &senderName,quint64 buffersize,QObject *paren
 }
 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;
@@ -76,7 +78,7 @@ void tcpSocket::header_event(){
        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;
@@ -161,7 +163,7 @@ tcpSocket &tcpSocket::operator<<(const QString &msg){
        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);
        }
@@ -172,7 +174,8 @@ tcpSocket &tcpSocket::operator<<(const QString &msg){
        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;
@@ -184,8 +187,16 @@ tcpSocket &tcpSocket::operator<<(QFile &file){
        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);
 }