Esempio n. 1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setFixedSize(467, 304);
    bytesSent = 0;
    ui->lineEdit_localPort->setEnabled(false);
    ui->lineEdit_filePath->setEnabled(false);
    ui->lineEdit_localAddress->setEnabled(false);
    ui->lineEdit_remoteAddress->setEnabled(false);
    ui->progressBar->setValue(0);
    ui->progressBar->setRange(0, 10000);

    connect(&server, SIGNAL(currentStatus(int)), this, SLOT(setCurrentStatus(int)));
    connect(&server, SIGNAL(error(int)), this, SLOT(errorHandler(int)));
    connect(&server, SIGNAL(ipAddress(QString, quint16)),this, SLOT(displayIPAddress(QString, quint16)));
    connect(&server, SIGNAL(bytesSent(qint64)), this, SLOT(updateProgressBar(qint64)));
    connect(&server, SIGNAL(progressRange(qint64)), this, SLOT(setProgressRange(qint64)));

    QFile thePath("C:/imageFilePath_inkPresettingSystem");
    if (thePath.open(QIODevice::ReadOnly)){
        QString dir = thePath.readAll();
        ui->lineEdit_filePath->setText(dir);

        server.setFilePath(dir);
        thePath.close();
    }
}
int SpdyStream::sendData(IOVec *pIov, int total)
{
    char achHeader[8];
    int ret;
    buildDataFrameHeader(achHeader, total);
    m_pSpdyConn->getBuf()->append(achHeader, 8);
    ret = m_pSpdyConn->cacheWritev(*pIov, total);
    LS_DBG_L(this, "SpdyStream::sendData(), total: %d, ret: %d", total, ret);
    if (ret == -1)
    {
        setFlag(HIO_FLAG_ABORT, 1);
        return LS_FAIL;
    }

    setActiveTime(DateTime::s_curTime);
    bytesSent(total);
    m_pSpdyConn->dataFrameSent(total);
    if (isFlowCtrl())
    {
        m_iWindowOut -= total;
        if (m_iWindowOut <= 0)
            setFlag(HIO_FLAG_BUFF_FULL, 1);
    }
    return total;
}
Esempio n. 3
0
void MessageQueue::dataWritten(qint64 bytes)
{
	emit bytesSent(bytes);

	// Write more once the buffer is empty
	if(_socket->bytesToWrite()==0) {
		if(_sendbuflen==0 && _sendqueue.isEmpty() && _snapshot_send.isEmpty())
			emit allSent();
		else
			writeData();
	}
}
Esempio n. 4
0
ClientThread::ClientThread(int h, QObject *parent) :
        QThread(parent),client(parent) /*s(QAbstractSocket::TcpSocket, parent)*//*, file(parent)*/
{
        blockSize = 0;
        blockNumber  = 0;
        client.setSocketDescriptor(h);
        connect(&client, SIGNAL(readyRead()), this, SLOT(getSignalFromClient()));
        connect(&client, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesSent(qint64)));
        isCanceled = false;
        indexOfEntry = 0;
        isFileSelected = false;
        isFolderSelected = false;
}
Esempio n. 5
0
void
BaseShadow::logRequeueEvent( const char* reason )
{
	struct rusage run_remote_rusage;
	memset( &run_remote_rusage, 0, sizeof(struct rusage) );

	run_remote_rusage = getRUsage();

	int exit_reason = getExitReason();

	JobEvictedEvent event;

	event.terminate_and_requeued = true;

	if( exitedBySignal() ) {
		event.normal = false;
		event.signal_number = exitSignal();
	} else {
		event.normal = true;
		event.return_value = exitCode();
	}
			
	if( exit_reason == JOB_COREDUMPED ) {
		event.setCoreFile( core_file_name );
	}

	if( reason ) {
		event.setReason( reason );
	}

		// TODO: fill in local rusage
		// event.run_local_rusage = r;
	event.run_remote_rusage = run_remote_rusage;

		/* we want to log the events from the perspective 
		   of the user job, so if the shadow *sent* the 
		   bytes, then that means the user job *received* 
		   the bytes */
	event.recvd_bytes = bytesSent();
	event.sent_bytes = bytesReceived();
	
	if (!uLog.writeEvent (&event,jobAd)) {
		dprintf( D_ALWAYS, "Unable to log ULOG_JOB_EVICTED "
				 "(and requeued) event\n" );
	}
}
Esempio n. 6
0
void
BaseShadow::logEvictEvent( int exitReason )
{
	struct rusage run_remote_rusage;
	memset( &run_remote_rusage, 0, sizeof(struct rusage) );

	run_remote_rusage = getRUsage();

	switch( exitReason ) {
	case JOB_CKPTED:
	case JOB_NOT_CKPTED:
	case JOB_KILLED:
		break;
	default:
		dprintf( D_ALWAYS, 
				 "logEvictEvent with unknown reason (%d), not logging.\n",
				 exitReason ); 
		return;
	}

	JobEvictedEvent event;
	event.checkpointed = (exitReason == JOB_CKPTED);
	
		// TODO: fill in local rusage
		// event.run_local_rusage = ???
			
		// remote rusage
	event.run_remote_rusage = run_remote_rusage;
	
	set_usageAd(jobAd, &event.pusageAd);

		/*
		  we want to log the events from the perspective of the user
		  job, so if the shadow *sent* the bytes, then that means the
		  user job *received* the bytes
		*/
	event.recvd_bytes = bytesSent();
	event.sent_bytes = bytesReceived();
	
	if (!uLog.writeEvent (&event,jobAd)) {
		dprintf (D_ALWAYS, "Unable to log ULOG_JOB_EVICTED event\n");
	}
}
Esempio n. 7
0
bool
BaseShadow::updateJobInQueue( update_t type )
{
		// insert the bytes sent/recv'ed by this job into our job ad.
		// we want this from the perspective of the job, so it's
		// backwards from the perspective of the shadow.  if this
		// value hasn't changed, it won't show up as dirty and we
		// won't actually connect to the job queue for it.  we do this
		// here since we want it for all kinds of updates...
	MyString buf;
	buf.formatstr( "%s = %f", ATTR_BYTES_SENT, (prev_run_bytes_sent +
											  bytesReceived()) );
	jobAd->Insert( buf.Value() );
	buf.formatstr( "%s = %f", ATTR_BYTES_RECVD, (prev_run_bytes_recvd +
											   bytesSent()) );
	jobAd->Insert( buf.Value() );

	ASSERT( job_updater );

		// Now that the ad is current, just let our QmgrJobUpdater
		// object take care of the rest...
	return job_updater->updateJob( type );
}
Esempio n. 8
0
std::string Server::getStatsDocument() const {
    std::ostringstream doc;
    doc << "clear();" << std::endl;
    for (auto it = _connections.begin(); it != _connections.end(); ++it) {
        doc << "connection({";
        auto connection = it->first;
        jsonKeyPairToStream(doc,
                "since", EpochTimeAsLocal(it->second),
                "fd", connection->getFd(),
                "id", reinterpret_cast<uint64_t>(connection),
                "uri", connection->getRequestUri(),
                "addr", formatAddress(connection->getRemoteAddress()),
                "user", connection->credentials() ?
                        connection->credentials()->username : "******",
                "input", connection->inputBufferSize(),
                "read", connection->bytesReceived(),
                "output", connection->outputBufferSize(),
                "written", connection->bytesSent()
        );
        doc << "});" << std::endl;
    }
    return doc.str();
}
Esempio n. 9
0
// kind defaults to US_NORMAL.
void
BaseShadow::logTerminateEvent( int exitReason, update_style_t kind )
{
	struct rusage run_remote_rusage;
	JobTerminatedEvent event;
	MyString corefile;

	memset( &run_remote_rusage, 0, sizeof(struct rusage) );

	switch( exitReason ) {
	case JOB_EXITED:
	case JOB_COREDUMPED:
		break;
	default:
		dprintf( D_ALWAYS, 
				 "UserLog logTerminateEvent with unknown reason (%d), aborting\n",
				 exitReason ); 
		return;
	}

	if (kind == US_TERMINATE_PENDING) {

		int exited_by_signal = FALSE;
		int exit_signal = 0;
		int exit_code = 0;

		getJobAdExitedBySignal(jobAd, exited_by_signal);
		if (exited_by_signal == TRUE) {
			getJobAdExitSignal(jobAd, exit_signal);
			event.normal = false;
			event.signalNumber = exit_signal;
		} else {
			getJobAdExitCode(jobAd, exit_code);
			event.normal = true;
			event.returnValue = exit_code;
		}

		/* grab usage information out of job ad */
		double real_value;
		if( jobAd->LookupFloat(ATTR_JOB_REMOTE_SYS_CPU, real_value) ) {
			run_remote_rusage.ru_stime.tv_sec = (time_t) real_value;
		}

		if( jobAd->LookupFloat(ATTR_JOB_REMOTE_USER_CPU, real_value) ) {
			run_remote_rusage.ru_utime.tv_sec = (time_t) real_value;
		}

		event.run_remote_rusage = run_remote_rusage;
		event.total_remote_rusage = run_remote_rusage;
	
		/*
		  we want to log the events from the perspective of the user
		  job, so if the shadow *sent* the bytes, then that means the
		  user job *received* the bytes
		*/
		jobAd->LookupFloat(ATTR_BYTES_SENT, event.recvd_bytes);
		jobAd->LookupFloat(ATTR_BYTES_RECVD, event.sent_bytes);

		event.total_recvd_bytes = event.recvd_bytes;
		event.total_sent_bytes = event.sent_bytes;
	
		if( exited_by_signal == TRUE ) {
			jobAd->LookupString(ATTR_JOB_CORE_FILENAME, corefile);
			event.setCoreFile( corefile.Value() );
		}

		if (!uLog.writeEvent (&event,jobAd)) {
			dprintf (D_ALWAYS,"Unable to log "
				 	"ULOG_JOB_TERMINATED event\n");
			EXCEPT("UserLog Unable to log ULOG_JOB_TERMINATED event");
		}

		return;
	}

	// the default kind == US_NORMAL path

	run_remote_rusage = getRUsage();
	
	if( exitedBySignal() ) {
		event.normal = false;
		event.signalNumber = exitSignal();
	} else {
		event.normal = true;
		event.returnValue = exitCode();
	}

		// TODO: fill in local/total rusage
		// event.run_local_rusage = r;
	event.run_remote_rusage = run_remote_rusage;
		// event.total_local_rusage = r;
	event.total_remote_rusage = run_remote_rusage;
	
		/*
		  we want to log the events from the perspective of the user
		  job, so if the shadow *sent* the bytes, then that means the
		  user job *received* the bytes
		*/
	event.recvd_bytes = bytesSent();
	event.sent_bytes = bytesReceived();

	event.total_recvd_bytes = prev_run_bytes_recvd + bytesSent();
	event.total_sent_bytes = prev_run_bytes_sent + bytesReceived();
	
	if( exitReason == JOB_COREDUMPED ) {
		event.setCoreFile( core_file_name );
	}

#if 1
	set_usageAd(jobAd, &event.pusageAd);
#else
	std::string resslist;
	if ( ! jobAd->LookupString("PartitionableResources", resslist))
		resslist = "Cpus, Disk, Memory";

	StringList reslist(resslist.c_str());
	if (reslist.number() > 0) {
		int64_t int64_value = 0;
		ClassAd * puAd = new ClassAd();

		reslist.rewind();
		char * resname = NULL;
		while ((resname = reslist.next()) != NULL) {
			MyString attr;
			int64_value = -1;
			attr.formatstr("%s", resname); // provisioned value
			if (jobAd->LookupInteger(attr.Value(), int64_value)) {
				puAd->Assign(resname, int64_value);
			} 
			// /*for debugging*/ else { puAd->Assign(resname, 42); }
			int64_value = -2;
			attr.formatstr("Request%s", resname);	// requested value
			if (jobAd->LookupInteger(attr.Value(), int64_value)) {
				puAd->Assign(attr.Value(), int64_value);
			}
			// /*for debugging*/ else { puAd->Assign(attr.Value(), 99); }
			int64_value = -3;
			attr.formatstr("%sUsage", resname); // usage value
			if (jobAd->LookupInteger(attr.Value(), int64_value)) {
				puAd->Assign(attr.Value(), int64_value);
			}
		}
		event.pusageAd = puAd;
	}
#endif
	
	if (!uLog.writeEvent (&event,jobAd)) {
		dprintf (D_ALWAYS,"Unable to log "
				 "ULOG_JOB_TERMINATED event\n");
		EXCEPT("UserLog Unable to log ULOG_JOB_TERMINATED event");
	}
}
Esempio n. 10
0
bool
BaseShadow::updateJobInQueue( update_t type )
{
		// insert the bytes sent/recv'ed by this job into our job ad.
		// we want this from the perspective of the job, so it's
		// backwards from the perspective of the shadow.  if this
		// value hasn't changed, it won't show up as dirty and we
		// won't actually connect to the job queue for it.  we do this
		// here since we want it for all kinds of updates...
	ClassAd ftAd;
	ftAd.Assign(ATTR_BYTES_SENT, (prev_run_bytes_sent + bytesReceived()) );

	ftAd.Assign(ATTR_BYTES_RECVD, (prev_run_bytes_recvd + bytesSent()) );

	FileTransferStatus upload_status = XFER_STATUS_UNKNOWN;
	FileTransferStatus download_status = XFER_STATUS_UNKNOWN;
	getFileTransferStatus(upload_status,download_status);
	switch(upload_status) {
	case XFER_STATUS_UNKNOWN:
		break;
	case XFER_STATUS_QUEUED:
		ftAd.Assign(ATTR_TRANSFER_QUEUED,true);
		ftAd.Assign(ATTR_TRANSFERRING_INPUT,true);
		break;
	case XFER_STATUS_ACTIVE:
		ftAd.Assign(ATTR_TRANSFER_QUEUED,false);
		ftAd.Assign(ATTR_TRANSFERRING_INPUT,true);
		break;
	case XFER_STATUS_DONE:
		ftAd.Assign(ATTR_TRANSFER_QUEUED,false);
		ftAd.Assign(ATTR_TRANSFERRING_INPUT,false);
		break;
	}
	switch(download_status) {
	case XFER_STATUS_UNKNOWN:
		break;
	case XFER_STATUS_QUEUED:
		ftAd.Assign(ATTR_TRANSFER_QUEUED,true);
		ftAd.Assign(ATTR_TRANSFERRING_OUTPUT,true);
		break;
	case XFER_STATUS_ACTIVE:
		ftAd.Assign(ATTR_TRANSFER_QUEUED,false);
		ftAd.Assign(ATTR_TRANSFERRING_OUTPUT,true);
		break;
	case XFER_STATUS_DONE:
		ftAd.Assign(ATTR_TRANSFER_QUEUED,false);
		ftAd.Assign(ATTR_TRANSFERRING_OUTPUT,false);
		break;
	}

	MergeClassAdsCleanly(jobAd,&ftAd);

	ASSERT( job_updater );

	if( type == U_PERIODIC ) {
			// Make an update happen soon.
		job_updater->resetUpdateTimer();
		return true;
	}

		// Now that the ad is current, just let our QmgrJobUpdater
		// object take care of the rest...
		//
		// Note that we force a non-durable update for X509 updates; if the
		// schedd crashes, we don't really care when the proxy was updated
		// on the worker node.
	return job_updater->updateJob( type, (type == U_PERIODIC) ? NONDURABLE : 0 );
}
Esempio n. 11
0
void ClientThread::getSignalFromClient()
{
    if (client.bytesAvailable() < 1)
        return;
    QByteArray data = client.read(5);
    qint64 size;
    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);
    char *d = data.data();
    if (d[0] == 'f' || d[0] == 'd'){  //client is asking for all the entry names in image folder
        isCanceled = false;
        QDir imageDir(filePath);
        fileNames = imageDir.entryList(fileFilters, QDir::Files);
        folderNames = imageDir.entryList(folderFilters, QDir::Dirs);
        folderNames.removeAt(folderNames.indexOf("."));
        folderNames.removeAt(folderNames.indexOf(".."));
        for (int i = 0; i < folderNames.length(); i ++){
            block.clear();
            out.device()->seek(0);
            out << qint16(0x0000) << folderNames.at(i).toUtf8();
            size = block.size();
            client.write((char*)&size, sizeof(qint64));
            client.write(block.data(), size);
            if(!client.waitForBytesWritten(-1)){
                emit error(3);
                return;
            }
        }
        for (int i = 0; i < fileNames.length(); i ++){
            block.clear();
            out.device()->seek(0);
            out << qint16(0x0000) << fileNames.at(i).toUtf8();
            size = block.size();
            client.write((char*)&size, sizeof(qint64));
            client.write(block.data(), size);
            if(!client.waitForBytesWritten(-1)){
                emit error(3);
                return;
            }
        }
        //send file name
        block.clear();
        out.device()->seek(0);
        if (d[0] == 'f')
            out << qint16(0x000A);
        else if (d[0] == 'd')
            out << qint16(0x000B);
        size = block.size();
        client.write((char*)&size, sizeof(qint64));
        client.write(block.data(), size);
        if(!client.waitForBytesWritten(-1)){
            emit error(3);
            return;
        }
    }
    else if (d[0] == 't' || d[0] == 'r'){  //client has selected an entry in image folder and asks server to transmit that entry
        numberOfBytesToBeTransmit = 0;
        numberOfFilesSent = 0;
        indexOfEntry = d[1] + (d[2] << 8) + (d[3] << 16) + (d[4] << 24);

        if (d[0] == 't'){
            if (indexOfEntry < folderNames.length()){ //entry selected is a folder
                imageFolderPath = folderNames.at(indexOfEntry);
                imageFolderPath.prepend(filePath);
                imageFolderPath.append("/");
                QDir dir(imageFolderPath);
                QStringList nameFilters;
                nameFilters << "*.tif" << "*.ppf";
                QStringList filesInFolder = dir.entryList(nameFilters, QDir::Files);
                //send file quantity
                block.clear();
                out.device()->seek(0);
                QString fileQuantity;
                fileQuantity.setNum(filesInFolder.length());
                out << qint16(0x0001) << fileQuantity.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);
                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }
                numberOfFilesToBeTransmit = filesInFolder.length();
                isFileSelected = false;
                isFolderSelected = true;
                for (int i = 0; i < filesInFolder.length(); i ++){
                    QString fp = filesInFolder.at(i);
                    fp.prepend(imageFolderPath);
                    QFile f(fp);
                    numberOfBytesToBeTransmit += f.size();
                }
                emit progressRange(numberOfBytesToBeTransmit);
            }
            else if (indexOfEntry < (folderNames.length() + fileNames.length())){       //entry selected is a single file
                imageFilePath = fileNames.at(indexOfEntry - folderNames.length());
                imageFilePath.prepend(filePath);

                //send file quantity
                block.clear();
                out.device()->seek(0);
                QString fileQuantity;
                fileQuantity.setNum(1);
                out << qint16(0x0001) << fileQuantity.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);
                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }
                numberOfFilesToBeTransmit = 1;
                isFileSelected = true;
                isFolderSelected = false;

                QString fp = imageFilePath;
                QFile f(fp);
                numberOfBytesToBeTransmit = f.size();
                emit progressRange(numberOfBytesToBeTransmit);
            }
        }
        else if (d[0] == 'r'){
            if (indexOfEntry < folderNames.length() && (indexOfEntry >= 0)){
                QString pathOfTheFolderToDelete = filePath + folderNames.at(indexOfEntry);
                pathOfTheFolderToDelete = pathOfTheFolderToDelete.replace('/', '\\');
                char str[100];
                QByteArray tempString1 = pathOfTheFolderToDelete.toAscii();
                const char *tempString2 = tempString1.data();
                sprintf(str, "rd/s/q %s", tempString2);
                system(str);
            }
            else if (indexOfEntry < (folderNames.length() + fileNames.length()) && (indexOfEntry >= 0)){
                QString pathOfTheFileToDelete = filePath + fileNames.at(indexOfEntry - folderNames.length());
                QFile fileToDelete(pathOfTheFileToDelete);
                fileToDelete.remove();
            }
            else{   //DELETE ALL FILES!!!
                qDebug() << "DELETING ALL FILES!!!" << d[1] << d[2] << d[3] << d[4];
                for (int i = 0; i < (folderNames.length() + fileNames.length()); i ++){
                    if (i < folderNames.length()){          //delete all the folders
                        QString pathOfTheFolderToDelete = filePath + folderNames.at(i);
                        pathOfTheFolderToDelete = pathOfTheFolderToDelete.replace('/', '\\');
                        char str[100];
                        QByteArray tempString1 = pathOfTheFolderToDelete.toAscii();
                        const char *tempString2 = tempString1.data();
                        sprintf(str, "rd/s/q %s", tempString2);
                        system(str);
                    }
                    else{                                   //delete all the files
                        QString pathOfTheFileToDelete = filePath + fileNames.at(i - folderNames.length());
                        QFile fileToDelete(pathOfTheFileToDelete);
                        fileToDelete.remove();
                    }
                }
            }
        }
    }
    else if (d[0] == 'e'){  //errors,could be more than 6 color files or file size too big
        emit bytesSent(0);
        emit progressRange(10000);
        return;
    }
    else if (d[0] == 'n'){  //send file name and size
        if (isFolderSelected){  //sending folder
            QDir dir(imageFolderPath);
            QStringList nameFilters;
            nameFilters << "*.tif" << "*.ppf";
            QStringList filesInFolder = dir.entryList(nameFilters, QDir::Files);
            if (numberOfFilesSent < numberOfFilesToBeTransmit){
                QString fileName, fileSize;

                //send file name
                block.clear();
                out.device()->seek(0);
                out << qint16(0x0002) << filesInFolder.at(numberOfFilesSent).toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);

                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }

                //send file size
                block.clear();
                out.device()->seek(0);
                fileName = imageFolderPath;
                fileName.append(filesInFolder.at(numberOfFilesSent));
                QFile imageFile(fileName);
                fileSize = fileSize.setNum(imageFile.size());
                out << qint16(0x0003) << fileSize.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);

                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }
            }
        }
        else{       //sending single file
            if (numberOfFilesSent < numberOfFilesToBeTransmit){
                QString fileName, fileSize;
                QFile imageFile(imageFilePath);
                fileName = imageFilePath.right(imageFilePath.length() - imageFilePath.lastIndexOf("/") - 1);
                //send file name
                block.clear();
                out.device()->seek(0);
                out << qint16(0x0002) << fileName.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);

                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }

                //send file size
                block.clear();
                out.device()->seek(0);
                fileSize = fileSize.setNum(imageFile.size());
                out << qint16(0x0003) << fileSize.toUtf8();
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);

                if(!client.waitForBytesWritten(-1)){
                    emit error(3);
                    return;
                }
            }
        }
    }
    else if (d[0] == 'g'){
        if (isFolderSelected){  //sending folder
            QDir dir(imageFolderPath);
            QStringList nameFilters;
            nameFilters << "*.tif" << "*.ppf";
            QStringList filesInFolder = dir.entryList(nameFilters, QDir::Files);
            if (numberOfFilesSent < numberOfFilesToBeTransmit){
                QString fileName = imageFolderPath;
                fileName.append(filesInFolder.at(numberOfFilesSent));
                QFile imageFile(fileName);

                imageFile.open(QIODevice::ReadWrite);
                //send file content
                do{
                    qApp->processEvents();
                    if (!isCanceled){
                        block.clear();
                        out.device()->seek(0);
                        out << qint16(0x0004) << imageFile.read(0xFFF0);
                        size = block.size();

                        client.write((char*)&size, sizeof(qint64));
                        client.write(block.data(), size);
                        if(!client.waitForBytesWritten(-1)){
                            emit error(3);
                        }
                    }
                    else{
                        block.clear();
                        out.device()->seek(0);
                        out << qint16(0x0006);
                        size = block.size();

                        client.write((char*)&size, sizeof(qint64));
                        client.write(block.data(), size);
                        if(!client.waitForBytesWritten(-1)){
                            emit error(3);
                        }
                        emit status(6);
                        return;
                    }
                } while(!imageFile.atEnd() && (!isCanceled));
                //send file EOF
                block.clear();
                out.device()->seek(0);
                out << qint16(0x0005);
                size = block.size();
                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);
                if(!client.waitForBytesWritten(-1))
                    emit error(3);
                emit status(3);
                imageFile.close();

                numberOfFilesSent ++;
            }
        }
        else{
            if (numberOfFilesSent < numberOfFilesToBeTransmit){
                QString fileName;
                QFile imageFile(imageFilePath);
                fileName = imageFilePath.right(imageFilePath.length() - imageFilePath.lastIndexOf("/") - 1);

                imageFile.open(QIODevice::ReadWrite);
                //send file content
                do{
                    if (!isCanceled){
                        block.clear();
                        out.device()->seek(0);
                        out << qint16(0x0004) << imageFile.read(0xFFF0);
                        size = block.size();

                        client.write((char*)&size, sizeof(qint64));
                        client.write(block.data(), size);
                        if(!client.waitForBytesWritten(-1)){
                            emit error(3);
                        }
                    }
                    else{
                        block.clear();
                        out.device()->seek(0);
                        out << qint16(0x0006);
                        size = block.size();

                        client.write((char*)&size, sizeof(qint64));
                        client.write(block.data(), size);
                        if(!client.waitForBytesWritten(-1))
                            emit error(3);
                        emit status(6);
                        return;
                    }
                } while(!imageFile.atEnd() && (!isCanceled));
                //send file EOF
                block.clear();
                out.device()->seek(0);
                out << qint16(0x0005);
                size = block.size();

                client.write((char*)&size, sizeof(qint64));
                client.write(block.data(), size);
                if(!client.waitForBytesWritten(-1))
                    emit error(3);
                emit status(3);
                imageFile.close();
                numberOfFilesSent ++;
            }
        }
    }
}
Esempio n. 12
0
void
MpiResource::resourceExit( int reason, int status ) 
{
	dprintf( D_FULLDEBUG, "Inside MpiResource::resourceExit()\n" );

	RemoteResource::resourceExit( reason, status );

		// Also log a NodeTerminatedEvent to the ULog

	switch( reason ) {
	case JOB_COREDUMPED:
	case JOB_EXITED:
		{
			// Job exited on its own, normally or abnormally
			NodeTerminatedEvent event;
			event.node = node_num;
			if( exited_by_signal ) {
				event.normal = false;
				event.signalNumber = exit_value;
			} else {
				event.normal = true;
				event.returnValue = exit_value;
			}
			
			int had_core = 0;
			jobAd->LookupBool( ATTR_JOB_CORE_DUMPED, had_core );
			if( had_core ) {
				event.setCoreFile( shadow->getCoreName() );
			}

				// TODO: fill in local/total rusage
				// event.run_local_rusage = r;
			event.run_remote_rusage = remote_rusage;
				// event.total_local_rusage = r;
			event.total_remote_rusage = remote_rusage;
			
				/* we want to log the events from the perspective
				   of the user job, so if the shadow *sent* the
				   bytes, then that means the user job *received*
				   the bytes */
			event.recvd_bytes = bytesSent();
			event.sent_bytes = bytesReceived();
				// TODO: total sent and recvd
			event.total_recvd_bytes = bytesSent();
			event.total_sent_bytes = bytesReceived();
			if( !writeULogEvent(&event) ) {
				dprintf( D_ALWAYS,"Unable to log "
						 "ULOG_NODE_TERMINATED event\n" );
			}
		}
		break;	
	case JOB_CKPTED:
	case JOB_NOT_CKPTED:
			// XXX Todo: Do we want a Node evicted event?
		break;
	default:
		dprintf( D_ALWAYS, "Warning: Unknown exit_reason %d in "
				 "MpiResource::resourceExit()\n", reason );  
	}	

}