本文整理汇总了C++中Disk::read方法的典型用法代码示例。如果您正苦于以下问题:C++ Disk::read方法的具体用法?C++ Disk::read怎么用?C++ Disk::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Disk
的用法示例。
在下文中一共展示了Disk::read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readRecordFromDiskTest
/**
* @brief BTRecordFile::readRecordFromDiskTest
* @param pDisk
* @param pRecordID
* Hace la lectura de un registro en la RAM
*/
void BTRecordFile::readRecordFromDiskTest(Disk pDisk, unsigned short pRecordID)
{
const char *padre = pDisk.read(this->_metadataPtr->getFirstRecordPos(), 7);
const char *hizq = pDisk.read(this->_metadataPtr->getFirstRecordPos() + 8, 7);
const char *hder = pDisk.read(this->_metadataPtr->getFirstRecordPos() + 16, 7);
std::string father(padre); // obtiene el padre
std::string HI(hizq); // obtiene el hijo izq
std::string HD(hder); // obtiene el hijo der
unsigned short _sizeCounter = this->_metadataPtr->getFirstRecordPos() + 24; // inicio de la data
DLL<IRecordDataType*> *tmp1 = _metadataPtr->getRecordStruct();
DLLNode<IRecordDataType*> *tmp = tmp1->getHeadPtr();
const char *data;
cout << "Binario " << father << " " << HI << " " << HD << endl;
std::string P = _conversion->binaryToDecimal(father);
std::string PHI = _conversion->binaryToDecimal(HI);
std::string PHD = _conversion->binaryToDecimal(HD);
cout << P << " " << PHI << " " << PHD << " ";
while (tmp != nullptr) {
data = (dynamic_cast<RecordDataType<char>*>(tmp->getData()))->getDataPtr();
const char *DATO = pDisk.read(_sizeCounter, 7);
std::string DATOSTR(DATO); // obtiene el padre
_sizeCounter += 8;
cout << sortUserDataFromDisk(DATOSTR, *data) << endl;
tmp = tmp->getNextPtr();
}
}
示例2: dispatch
int RPC::dispatch(Disk& disk)
{
char buf[NDISK_BLOCK_SIZE];
char packet[NDISK_BLOCK_SIZE + 8];
size_t len = NDISK_BLOCK_SIZE + 8;
char *msg = packet;
if (disk.block_size() != NDISK_BLOCK_SIZE)
return DISK_ERROR;
// Read the packet (with 8-byte header)
do
{
ssize_t nread = recv(sock, msg, len, 0);
if (nread <= 0)
return DISK_ERROR;
len -= nread;
msg += nread;
}
while (len > 0);
// Get the command from the packet's first four bytes
char command[5];
memcpy(command, packet, 4);
command[4] = '\0';
// Get the block number parameter from the packet
int block_num = ston(packet + 4);
if (!strcmp(command, "NUMB"))
{
// Write num blocks into packet data
ntos(packet + 8, disk.num_blocks());
}
else if (!strcmp(command, "FRMT"))
{
disk.format(block_num);
}
else if (!strcmp(command, "READ"))
{
disk.read(block_num, buf);
memcpy(packet + 8, buf, NDISK_BLOCK_SIZE);
}
else if (!strcmp(command, "WRTE"))
{
memcpy(buf, packet + 8, NDISK_BLOCK_SIZE);
disk.write(block_num, buf);
}
else
{
message1("Unknown RPC command %s\n", command);
}
message2("RPC command %s(%d)\n", command, block_num);
len = NDISK_BLOCK_SIZE + 8;
msg = packet;
// Write the packet (with 8-byte header)
do
{
ssize_t nwritten = send(sock, msg, len, 0);
if (nwritten < 0)
return DISK_ERROR;
len -= nwritten;
msg += nwritten;
}
while (len > 0);
return DISK_OK;
}