示例#1
0
CompactIndex2::~CompactIndex2() {
	if (fileHandle < 0)
		return;

	if (!readOnly) {
		if (use_O_DIRECT) {
			// if we access the output file directly, we need to close the file handle
			// now and re-acquire a new one, because the write operations in the destructor
			// are not properly mem-aligned
			close(fileHandle);
			fileHandle = open(fileName, O_RDWR | O_LARGEFILE, DEFAULT_FILE_PERMISSIONS);
			if (fileHandle < 0) {
				log(LOG_ERROR, LOG_ID, "Unable to re-open target file.");
				perror("~CompactIndex2");
				exit(1);
			}
		}
		flushWriteCache();

		// write descriptors
		lseek(fileHandle, bytesWrittenToFile, SEEK_SET);
		bytesWrittenToFile +=
			writeRawData(bytesWrittenToFile, compressedDescriptors, usedByDescriptors);

		// write header data
		header.compressedDescriptorSize = usedByDescriptors;
		bytesWrittenToFile +=
			writeRawData(bytesWrittenToFile, &header, sizeof(header));
		forced_ftruncate(fileHandle, lseek(fileHandle, 0, SEEK_CUR));
		realFree(writeCache);
		writeCache = NULL;
		fsync(fileHandle);
	} // end if (!readOnly)

	sprintf(errorMessage, "Freeing memory for on-disk index: %s", fileName);
	long long pc = header.postingCount;
	log(LOG_DEBUG, LOG_ID, errorMessage);
	sprintf(errorMessage,
			"  terms: %lld, segments: %lld, postings: %lld, descriptors: %lld (%d bytes)",
			static_cast<long long>(header.termCount),
			static_cast<long long>(header.listCount),
			static_cast<long long>(header.postingCount),
			static_cast<long long>(header.descriptorCount),
			usedByDescriptors);
	log(LOG_DEBUG, LOG_ID, errorMessage);

	FREE_AND_SET_TO_NULL(inMemoryIndex);
	FREE_AND_SET_TO_NULL(temporaryPLSH);
	FREE_AND_SET_TO_NULL(compressedDescriptors);
	FREE_AND_SET_TO_NULL(groupDescriptors);
	FREE_AND_SET_TO_NULL(fileName);
	if (baseFile != NULL) {
		delete baseFile;
		baseFile = NULL;
	}

	close(fileHandle);
	fileHandle = -1;
} // end of ~CompactIndex2()
示例#2
0
CompactIndex::~CompactIndex() {
	if (fileHandle < 0)
		return;

	if (!readOnly) {
		if (use_O_DIRECT) {
			// if we access the output file directly, we need to close the file handle
			// now and re-acquire a new one, because the write operations in the destructor
			// are not properly mem-aligned
			close(fileHandle);
			fileHandle = open(fileName, O_RDWR | O_LARGEFILE, DEFAULT_FILE_PERMISSIONS);
			if (fileHandle < 0) {
				log(LOG_ERROR, LOG_ID, "Unable to re-open target file.");
				perror("~CompactIndex");
				exit(1);
			}
		}
		flushWriteCache();

		// write descriptors
		long long totalDescriptorSize =
			header.descriptorCount * sizeof(CompactIndex_BlockDescriptor);
		lseek(fileHandle, bytesWrittenToFile, SEEK_SET);
		writeRawData(bytesWrittenToFile, descriptors, totalDescriptorSize);

		// write header data
		writeRawData(bytesWrittenToFile + totalDescriptorSize, &header, sizeof(header));
		forced_ftruncate(fileHandle, lseek(fileHandle, 0, SEEK_CUR));
		realFree(writeCache);
		writeCache = NULL;
		fsync(fileHandle);
	}

	sprintf(errorMessage, "Freeing memory for %s index: %s",
			(inMemoryIndex == NULL ? "on-disk" : "in-memory"), fileName);
	long long pc = header.postingCount;
	log(LOG_DEBUG, LOG_ID, errorMessage);
	sprintf(errorMessage, "  termCount = %d, listCount = %d, descriptorCount = %d, postingCount = %lld",
			header.termCount, header.listCount, header.descriptorCount, pc);
	log(LOG_DEBUG, LOG_ID, errorMessage);

	FREE_AND_SET_TO_NULL(fileName);
	FREE_AND_SET_TO_NULL(descriptors);
	FREE_AND_SET_TO_NULL(inMemoryIndex);
	if (baseFile != NULL) {
		delete baseFile;
		baseFile = NULL;
	}

	close(fileHandle);
	fileHandle = -1;
} // end of ~CompactIndex()
void TAbstractWebSocket::sendPong(const QByteArray &data)
{
    TWebSocketFrame frame;
    frame.setOpCode(TWebSocketFrame::Pong);
    frame.setPayload(data);
    writeRawData(frame.toByteArray());
}
void TAbstractWebSocket::sendBinary(const QByteArray &data)
{
    TWebSocketFrame frame;
    frame.setOpCode(TWebSocketFrame::BinaryFrame);
    frame.setPayload(data);
    writeRawData(frame.toByteArray());

    renewKeepAlive();  // Renew Keep-Alive interval
}
void TAbstractWebSocket::sendText(const QString &message)
{
    TWebSocketFrame frame;
    frame.setOpCode(TWebSocketFrame::TextFrame);
    frame.setPayload(message.toUtf8());
    writeRawData(frame.toByteArray());

    renewKeepAlive();  // Renew Keep-Alive interval
}
void rawForcesAndMoments::evaluate()
{
    List<std::pair<scalar, label> > timeLabel;
    vectorField forces, moments;

    readForceAndMomentData(timeLabel, forces, moments);

    writeRawData(timeLabel, forces, moments);
}
示例#7
0
void saveFull( MultiBlock2D& multiBlock, FileName fName, IndexOrdering::OrderingT ordering )
{
    global::profiler().start("io");
    SparseBlockStructure2D blockStructure(multiBlock.getBoundingBox());
    Box2D bbox = multiBlock.getBoundingBox();
    if (ordering==IndexOrdering::forward) {
        plint nBlocks = std::min(bbox.getNx(), (plint)global::mpi().getSize());
        std::vector<std::pair<plint,plint> > ranges;
        util::linearRepartition(bbox.x0, bbox.x1, nBlocks, ranges);
        for (pluint iRange=0; iRange<ranges.size(); ++iRange) {
            blockStructure.addBlock (
                    Box2D( ranges[iRange].first, ranges[iRange].second,
                           bbox.y0, bbox.y1 ),
                    iRange );
        }
    }
    else if (ordering==IndexOrdering::backward) {
        plint nBlocks = std::min(bbox.getNy(), (plint)global::mpi().getSize());
        std::vector<std::pair<plint,plint> > ranges;
        util::linearRepartition(bbox.y0, bbox.y1, nBlocks, ranges);
        for (pluint iRange=0; iRange<ranges.size(); ++iRange) {
            blockStructure.addBlock (
                    Box2D( bbox.x0, bbox.x1, ranges[iRange].first, ranges[iRange].second ),
                    iRange );
        }
    }
    else {
        // Sparse ordering not defined.
        PLB_ASSERT( false );
    }
    plint envelopeWidth=1;
    MultiBlockManagement2D adjacentMultiBlockManagement (
            blockStructure, new OneToOneThreadAttribution, envelopeWidth );
    MultiBlock2D* multiAdjacentBlock = multiBlock.clone(adjacentMultiBlockManagement);
    
    std::vector<plint> offset;
    std::vector<plint> myBlockIds;
    std::vector<std::vector<char> > data;

    bool dynamicContent = false;
    dumpData(*multiAdjacentBlock, dynamicContent, offset, myBlockIds, data);
    if (ordering==IndexOrdering::backward && myBlockIds.size()==1) {
        PLB_ASSERT( data.size()==1 );
        Box2D domain;
        blockStructure.getBulk(myBlockIds[0], domain);
        plint sizeOfCell = multiAdjacentBlock->sizeOfCell();
        PLB_ASSERT( domain.nCells()*sizeOfCell == (plint)data[0].size() );
        transposeToBackward( sizeOfCell, domain, data[0] );
    }

    plint totalSize = offset[offset.size()-1];
    writeOneBlockXmlSpec(*multiAdjacentBlock, fName, totalSize, ordering);
    writeRawData(fName, myBlockIds, offset, data);
    delete multiAdjacentBlock;
    global::profiler().stop("io");
}
示例#8
0
void save( MultiBlock2D& multiBlock, FileName fName, bool dynamicContent )
{
    global::profiler().start("io");
    std::vector<plint> offset;
    std::vector<plint> myBlockIds;
    std::vector<std::vector<char> > data;

    dumpData(multiBlock, dynamicContent, offset, myBlockIds, data);

    writeXmlSpec(multiBlock, fName, offset, dynamicContent);
    writeRawData(fName, myBlockIds, offset, data);
    global::profiler().stop("io");
}
void TAbstractWebSocket::sendClose(int code)
{
    if (!closeSent.exchange(true)) {
        TWebSocketFrame frame;
        frame.setOpCode(TWebSocketFrame::Close);
        QDataStream ds(&frame.payload(), QIODevice::WriteOnly);
        ds.setByteOrder(QDataStream::BigEndian);
        ds << (qint16)code;
        writeRawData(frame.toByteArray());

        stopKeepAlive();
    }
}
void TAbstractWebSocket::sendHandshakeResponse()
{
    THttpResponseHeader response;
    response.setStatusLine(Tf::SwitchingProtocols, THttpUtility::getResponseReasonPhrase(Tf::SwitchingProtocols));
    response.setRawHeader("Upgrade", "websocket");
    response.setRawHeader("Connection", "Upgrade");

    QByteArray secAccept = QCryptographicHash::hash(reqHeader.rawHeader("Sec-WebSocket-Key").trimmed() + saltToken,
                                                    QCryptographicHash::Sha1).toBase64();
    response.setRawHeader("Sec-WebSocket-Accept", secAccept);

    writeRawData(response.toByteArray());
}
示例#11
0
qint64 THttpSocket::write(const THttpHeader *header, QIODevice *body)
{
    T_TRACEFUNC("");

    if (body && !body->isOpen()) {
        if (!body->open(QIODevice::ReadOnly)) {
            tWarn("open failed");
            return -1;
        }
    }

    // Writes HTTP header
    QByteArray hdata = header->toByteArray();
    qint64 total = writeRawData(hdata.data(), hdata.size());
    if (total < 0) {
        return -1;
    }

    if (body) {
        QBuffer *buffer = qobject_cast<QBuffer *>(body);
        if (buffer) {
            if (writeRawData(buffer->data().data(), buffer->size()) != buffer->size()) {
                return -1;
            }
            total += buffer->size();
        } else {
            QByteArray buf(WRITE_BUFFER_LENGTH, 0);
            qint64 readLen = 0;
            while ((readLen = body->read(buf.data(), buf.size())) > 0) {
                if (writeRawData(buf.data(), readLen) != readLen) {
                    return -1;
                }
                total += readLen;
            }
        }
    }
    return total;
}
示例#12
0
err_t HttpClient::onReceive(pbuf *buf)
{
	if (buf == NULL)
	{
		// Disconnected, close it
		TcpClient::onReceive(buf);
	}
	else
	{
		int startPos = 0;
		if (waitParse)
		{
			String http = NetUtils::pbufStrCopy(buf, 0, 4);
			http.toUpperCase();
			if (http == "HTTP" && code == 0)
			{
				int codeStart = NetUtils::pbufFindChar(buf, ' ', 4);
				int codeEnd = NetUtils::pbufFindChar(buf, ' ', codeStart + 1);
				if (codeStart != -1 && codeEnd != -1 && codeEnd - codeStart < 5)
				{
					String strCode = NetUtils::pbufStrCopy(buf, codeStart, codeEnd);
					code = strCode.toInt();
				}
				else
					code = 0;
			}
			int headerEnd = NetUtils::pbufFindStr(buf, "\r\n\r\n");
			if (headerEnd != -1)
			{
				debugf("Header pos: %d", headerEnd);
				startPos = headerEnd + 4;
				waitParse = false;
				if (headerEnd < NETWORK_MAX_HTTP_PARSING_LEN)
					parseHeaders(buf, headerEnd);
			}
		}

		writeRawData(buf, startPos);

		// Fire ReadyToSend callback
		TcpClient::onReceive(buf);
	}

	return ERR_OK;
}
示例#13
0
qint64 THttpSocket::writeRawData(const QByteArray &data)
{
    return writeRawData(data.data(), data.size());
}
void BinaryWriterAppender::writeFooter() const
{
    if (layout() && mpWriter)
        writeRawData(binaryLayout()->binaryFooter());
}