本文整理汇总了C++中ProcessId::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ ProcessId::toString方法的具体用法?C++ ProcessId::toString怎么用?C++ ProcessId::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProcessId
的用法示例。
在下文中一共展示了ProcessId::toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writePid
Status StorageEngineLockFile::writePid() {
if (!_lockFileHandle->isValid()) {
return Status(ErrorCodes::FileNotOpen,
str::stream() << "Unable to write process ID to " << _filespec
<< " because file has not been opened.");
}
if (::ftruncate(_lockFileHandle->_fd, 0)) {
int errorcode = errno;
return Status(ErrorCodes::FileStreamFailed,
str::stream() << "Unable to write process id to file (ftruncate failed): "
<< _filespec
<< ' '
<< errnoWithDescription(errorcode));
}
ProcessId pid = ProcessId::getCurrent();
std::stringstream ss;
ss << pid << std::endl;
std::string pidStr = ss.str();
int bytesWritten = ::write(_lockFileHandle->_fd, pidStr.c_str(), pidStr.size());
if (bytesWritten < 0) {
int errorcode = errno;
return Status(ErrorCodes::FileStreamFailed,
str::stream() << "Unable to write process id " << pid.toString()
<< " to file: "
<< _filespec
<< ' '
<< errnoWithDescription(errorcode));
} else if (bytesWritten == 0) {
return Status(ErrorCodes::FileStreamFailed,
str::stream() << "Unable to write process id " << pid.toString()
<< " to file: "
<< _filespec
<< " no data written.");
}
if (::fsync(_lockFileHandle->_fd)) {
int errorcode = errno;
return Status(ErrorCodes::FileStreamFailed,
str::stream() << "Unable to write process id " << pid.toString()
<< " to file (fsync failed): "
<< _filespec
<< ' '
<< errnoWithDescription(errorcode));
}
flushMyDirectory(_filespec);
return Status::OK();
}
示例2: writePid
Status StorageEngineLockFile::writePid() {
if (!_lockFileHandle->isValid()) {
return Status(ErrorCodes::FileNotOpen,
str::stream() << "Unable to write process ID to " << _filespec
<< " because file has not been opened.");
}
Status status = _truncateFile(_lockFileHandle->_handle);
if (!status.isOK()) {
return status;
}
ProcessId pid = ProcessId::getCurrent();
std::stringstream ss;
ss << pid << std::endl;
std::string pidStr = ss.str();
DWORD bytesWritten = 0;
if (::WriteFile(_lockFileHandle->_handle,
static_cast<LPCVOID>(pidStr.c_str()),
static_cast<DWORD>(pidStr.size()),
&bytesWritten,
NULL) == FALSE) {
int errorcode = GetLastError();
return Status(ErrorCodes::FileStreamFailed,
str::stream() << "Unable to write process id " << pid.toString()
<< " to file: "
<< _filespec
<< ' '
<< errnoWithDescription(errorcode));
} else if (bytesWritten == 0) {
return Status(ErrorCodes::FileStreamFailed,
str::stream() << "Unable to write process id " << pid.toString()
<< " to file: "
<< _filespec
<< " no data written.");
}
::FlushFileBuffers(_lockFileHandle->_handle);
return Status::OK();
}