本文整理汇总了C++中AsyncFio::sync方法的典型用法代码示例。如果您正苦于以下问题:C++ AsyncFio::sync方法的具体用法?C++ AsyncFio::sync怎么用?C++ AsyncFio::sync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncFio
的用法示例。
在下文中一共展示了AsyncFio::sync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void Ps2File::cacheReadSync() {
if (_cacheOpRunning) {
int res = fio.sync(_fd);
assert(res >= 0);
_bytesInCache += res;
_physFilePos += res;
_cacheOpRunning = false;
}
}
示例2: fclose
Ps2WriteFile::~Ps2WriteFile(void) {
if ((_fd >= 0) && (_bytesInCache)) {
fio.write(_fd, _cacheBuf, _bytesInCache);
int wrRes = fio.sync(_fd);
if (wrRes != (int)_bytesInCache) // too late to return an error
printf("Cache flush on fclose(): Unable to write %d cached bytes to mc, only %d bytes written\n", _bytesInCache, wrRes);
}
if (_fd >= 0)
fio.close(_fd);
free(_cacheBuf);
}
示例3:
uint32 Ps2ReadFile::read(void *dest, uint32 len) {
WaitSema(_sema);
uint8 *destBuf = (uint8*)dest;
if ((_filePos < _cachePos) || (_filePos + len > _cachePos + _bytesInCache))
cacheReadSync(); // we have to read from CD, sync cache.
while (len && (_filePos != _fileSize)) {
if ((_filePos >= _cachePos) && (_filePos < _cachePos + _bytesInCache)) { // read from cache
uint32 staPos = (_cacheOfs + (_filePos - _cachePos)) % CACHE_SIZE;
uint32 cpyLen = _bytesInCache - (_filePos - _cachePos);
if (cpyLen > len)
cpyLen = len;
if (staPos + cpyLen > CACHE_SIZE)
cpyLen = CACHE_SIZE - staPos;
assert(cpyLen);
memcpy(destBuf, _cacheBuf + staPos, cpyLen);
_filePos += cpyLen;
destBuf += cpyLen;
_readBytesBlock += len;
len -= cpyLen;
} else { // cache miss
assert(!_cacheOpRunning);
if (_physFilePos != _filePos) {
if ((_filePos < _physFilePos) || (_filePos > _physFilePos + (CACHE_SIZE / 2)))
_readBytesBlock = 0; // reset cache hit count
_physFilePos = _filePos & ~READ_ALIGN_MASK;
if (fio.seek(_fd, _physFilePos, SEEK_SET) != (int)_physFilePos)
break; // read beyond EOF
}
int doRead = len + (_filePos - _physFilePos);
doRead = (doRead + READ_ALIGN_MASK) & ~READ_ALIGN_MASK;
if (doRead > MAX_READ_STEP)
doRead = MAX_READ_STEP;
if (doRead < 2048)
doRead = 2048;
fio.read(_fd, _cacheBuf, doRead);
_cachePos = _physFilePos;
_cacheOfs = 0;
_bytesInCache = fio.sync(_fd);
_physFilePos += _bytesInCache;
if (!_bytesInCache)
break; // EOF
}
}
cacheReadAhead();
SignalSema(_sema);
return destBuf - (uint8*)dest;
}
示例4: if
bool Ps2File::open(const char *name, int mode) {
#if 1
_fd = fio.open(name, mode);
dbg_printf("open %s [%d]\n", name, _fd);
if (_fd >= 0) {
_mode = mode;
_filePos = 0;
if (_mode == O_RDONLY) {
_fileSize = fio.seek(_fd, 0, SEEK_END);
fio.seek(_fd, 0, SEEK_SET);
}
else
_fileSize = 0;
dbg_printf(" _mode = %x\n", _mode);
dbg_printf(" _fileSize = %d\n", _fileSize);
// dbg_printf(" _filePos = %d\n", _filePos);
return true;
}
return false;
#else
uint32 r;
// hack: FIO does not reports size for RW (?)
_fd = fio.open(name, O_RDONLY);
if (_fd >= 0) {
_fileSize = fio.seek(_fd, 0, SEEK_END);
fio.seek(_fd, 0, SEEK_SET); /* rewind ! */
if (_fileSize && mode != O_RDONLY) {
fio.read(_fd, _cacheBuf, _fileSize);
r = fio.sync(_fd);
dbg_printf(" sz=%d, read=%d\n", _fileSize, r);
assert(r == _fileSize);
}
fio.close(_fd);
}
else
_fileSize = 0; /* new file */
_fd = fio.open(name, mode);
dbg_printf("open %s [%d]\n", name, _fd);
if (_fd >= 0) {
_mode = mode;
_filePos = 0;
if (_fileSize) { /* existing data */
if (mode == O_RDONLY) {
/* DANGER: for w* modes it will truncate your fine files */
fio.seek(_fd, 0, SEEK_SET);
}
else if (_mode & O_APPEND) {
fio.seek(_fd, 0, _fileSize);
_filePos = _fileSize;
}
#if 0 /* file already trunc'd when opened as w* -> moved up */
if (mode != O_RDONLY) {
fio.read(_fd, _cacheBuf, _fileSize);
r = fio.sync(_fd);
dbg_printf(" sz=%d, read=%d\n", _fileSize, r);
assert(r == _fileSize);
// _fileSize = fio.seek(_fd, 0, SEEK_END);
}
#endif
}
dbg_printf(" _mode = %x\n", _mode);
dbg_printf(" _fileSize = %d\n", _fileSize);
dbg_printf(" _filePos = %d\n", _filePos);
return true;
} else
return false;
#endif
}