本文整理汇总了C++中IOException函数的典型用法代码示例。如果您正苦于以下问题:C++ IOException函数的具体用法?C++ IOException怎么用?C++ IOException使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IOException函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IOException
void
InflaterIOChannel::go_to_end()
{
if (m_error) {
throw IOException("InflaterIOChannel is in error condition, "
"can't seek to end");
}
// Keep reading until we can't read any more.
unsigned char temp[ZBUF_SIZE];
// Seek forwards.
for (;;) {
const std::streamsize bytes_read = inflate_from_stream(temp, ZBUF_SIZE);
if (!bytes_read) {
// We've seeked as far as we can.
break;
}
}
}
示例2: throw
//
// Constructor
//
SSLSocket::SSLSocket(const InetAddress& address, in_port_t port, SSLContext* context)
throw(IOException, SystemException)
: Socket(address, port), _context(context), _session(NULL)
{
// TODO: check if context is != NULL
/* Connect the SSL socket */
_ssl = SSL_new(_context->_ctx);
_sbio = BIO_new_socket(_impl->_fd, BIO_NOCLOSE);
SSL_set_bio(_ssl, _sbio, _sbio);
//SSL_set_connect_state(_ssl);
// Verify certificate
if (SSL_get_verify_result(_ssl) != X509_V_OK) {
throw IOException("SSLSocket: Certificate doesn't verified");
}
_session_creation = true;
_use_client_mode = true;
}
示例3: vprDEBUG
// Close the file handle.
void FileHandleImplUNIX::close()
{
vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)
<< "[vpr::FileHandleImplUNIX::close()] Closing file descriptor "
<< mFdesc << std::endl << vprDEBUG_FLUSH;
if ( ::close(mFdesc) == -1 )
{
vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
<< "[vpr::FileHandleImplUNIX::close()] Could not close " << mName
<< ": " << strerror(errno) << std::endl << vprDEBUG_FLUSH;
throw IOException("[vpr::FileHandleImplUNIX::close()] Could not close "
+ mName + ": " + std::string(strerror(errno)), VPR_LOCATION);
}
else
{
mFdesc = -1;
mOpen = false;
}
}
示例4: open_flags
// Open the file handle.
void FileHandleImplUNIX::open()
{
int open_flags(mOpenMode);
if ( ! mOpenBlocking )
{
open_flags |= O_NONBLOCK;
}
mFdesc = ::open(mName.c_str(), open_flags);
// If the file handle was not returned successfully, print an error
// message explaining why.
if ( mFdesc == -1 )
{
// If we are opening in non-blocking mode, we do not want to bomb out.
if ( errno == EWOULDBLOCK && ! mOpenBlocking )
{
mOpen = true;
throw WouldBlockException("Would block.", VPR_LOCATION);
}
// Otherwise, report the error.
else
{
mOpen = false;
vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
<< "[vpr::FileHandleImplUNIX::open()] Could not open " << mName
<< ": " << strerror(errno) << std::endl << vprDEBUG_FLUSH;
throw IOException("[vpr::FileHandleImplUNIX::open()] Could not open "
+ mName + ": " + std::string(strerror(errno)), VPR_LOCATION);
}
}
// Otherwise, set mOpen to true.
else
{
mOpen = true;
mBlocking = mOpenBlocking;
}
}
示例5: fill_cache
void
NoSeekFile::fill_cache(std::streamsize size)
{
#ifdef GNASH_NOSEEK_FD_VERBOSE
std::cerr << boost::format(" fill_cache(%d) called") % size << std::endl;
#endif
assert(size >= 0);
// See how big is the cache
while (_cached < static_cast<size_t>(size)) {
#ifdef GNASH_NOSEEK_FD_VERBOSE
size_t bytesNeeded = size - _cached;
bytesNeeded = std::min<size_t>(bytesNeeded, chunkSize);
std::cerr << boost::format(" bytes needed = %d") % bytesNeeded <<
std::endl;
#endif
std::streamsize bytesRead = ::read(_fd, _buf, chunkSize);
if (bytesRead < 0) {
std::cerr << boost::format(_("Error reading %d bytes from "
"input stream")) % chunkSize << std::endl;
_running = false;
// this looks like a CRITICAL error (since we don't handle it..)
throw IOException("Error reading from input stream");
}
if (bytesRead < chunkSize) {
if (bytesRead == 0) {
#ifdef GNASH_NOSEEK_FD_VERBOSE
std::cerr << "EOF reached" << std::endl;
#endif
_running = false;
return;
}
}
cache(_buf, bytesRead);
}
}
示例6: opendir
StringSet SourceHighlightUtils::getFileNames(const std::string path,
const std::string fileExtension) {
StringSet strings;
DIR *dp;
struct dirent *ep;
dp = opendir(path.c_str());
if (dp != NULL) {
while ((ep = readdir(dp))) {
const string name(ep->d_name);
if (get_file_extension(name) == fileExtension) {
strings.insert(name);
}
}
(void) closedir(dp);
} else {
throw IOException("Couldn't open the directory", path);
}
return strings;
}
示例7: switch
void MemoryStream::Seek(sint64 offset, sint32 origin)
{
uint64 newPosition;
switch (origin) {
default:
case STREAM_SEEK_BEGIN:
newPosition = offset;
break;
case STREAM_SEEK_CURRENT:
newPosition = GetPosition() + offset;
break;
case STREAM_SEEK_END:
newPosition = _dataSize + offset;
break;
}
if (newPosition > _dataSize)
{
throw IOException("New position out of bounds.");
}
_position = (void*)((uintptr_t)_data + (uintptr_t)newPosition);
}
示例8: IOException
void BinTreeNodeReader::fillArray(QByteArray& buffer, quint32 len)
{
char data[1025];
buffer.clear();
// bool ready = true;
/*
if (socket->bytesAvailable() < 1)
{
Utilities::logData("fillArray() waiting for bytes");
ready = socket->waitForReadyRead(READ_TIMEOUT);
}
if (!ready)
{
Utilities::logData("fillArray() not ready / timed out");
throw IOException(socket->error());
}
*/
int needToRead = len;
while (needToRead > 0)
{
int bytesRead = socket->read(data,(needToRead > 1024) ? 1024 : needToRead);
if (bytesRead < 0)
throw IOException(socket->error());
if (bytesRead == 0)
// socket->waitForReadyRead(READ_TIMEOUT);
qApp->processEvents();
else
{
needToRead -= bytesRead;
buffer.append(data,bytesRead);
}
}
}
示例9: IOException
std::vector<std::vector<unsigned char> > SerialThrustMasterBase::read() {
std::vector<std::vector<unsigned char> > results;
int availableBytes;
if (ioctl(handle, FIONREAD, &availableBytes) == -1) {
throw IOException("Failed to get number of bytes available for " + name + ": " + std::strerror(errno));
}
// If a full packet is available or a timeout has occurred, process all available data.
if (availableBytes >= 9 || getTime() > timeout) {
int remainingBytes = availableBytes;
std::vector<unsigned char> buffer(remainingBytes);
/**
* While we know how many bytes are avialable, read can still be interrupted by signals,
* so call it in a loop.
*/
while (remainingBytes) {
remainingBytes -= SerialDevice::read(&buffer[0] + (availableBytes - remainingBytes), remainingBytes);
}
/**
* Only return the data to the caller if exactly one full packet arrived. If a timeout
* occurred or extra bytes arrived, discard all of the data.
*/
if (availableBytes == 9) {
results.push_back(buffer);
}
/**
* Request the next state update from the device. Sending requests too quickly can corrupt
* the device's output, so we only send a new request when at least a full packet has
* arrived or a timeout occured.
*/
requestData();
}
return results;
}
示例10: ASSERT
CDEC_NS_BEGIN
// -------------------------------------------------------------------------- //
#if !defined(X_OS_WINDOWS)
#include <unistd.h>
#include <fcntl.h>
void FileWrapper::Open(PCWSTR path, AccessMode access, ShareMode share, bool fCreate)
{
ASSERT(!IsOpen() && path != NULL && *path != 0);
size_t len = wstrlen16(path);
std::string patha = cdec::Encoding::get_Default()->FromUnicode(path, len);
int oflag = 0;
switch (access)
{
case AccessMode::AccessRead:
oflag |= O_RDONLY;
break;
case AccessMode::AccessWrite:
oflag |= O_WRONLY;
break;
case AccessMode::AccessReadWrite:
oflag |= O_RDWR;
break;
default:
cdec_throw(IOException(EC_InvalidArg));
}
if (fCreate)
m_fd = open(patha.c_str(), oflag | O_CREAT, S_IRWXU);
else
m_fd = open(patha.c_str(), oflag);
if (m_fd == -1)
cdec_throw_stdc_lasterr(IOException);
}
示例11: while
qint64 BgzfReader::read(char *buff, qint64 maxSize) {
if(0 == maxSize) {
return 0;
}
stream.next_out = (Bytef *)buff;
stream.avail_out = maxSize;
while(stream.avail_out > 0) {
if(0 == stream.avail_in) {
qint64 returnedValue = ioAdapter.readBlock(buffer, sizeof(buffer));
if(-1 == returnedValue) {
coreLog.error(QString("in BgzfReader::read, failed to read %1 bytes from ioAdapter, after %2 bytes already read. %3")
.arg(sizeof(buffer))
.arg(ioAdapter.bytesRead())
.arg(ioAdapter.errorString()));
throw IOException(BAMDbiPlugin::tr("Can't read input"));
} else if(0 == returnedValue) {
endOfFile = true;
break;
} else {
stream.avail_in = returnedValue;
stream.next_in = (Bytef *)buffer;
}
}
int returnedValue = inflate(&stream, Z_SYNC_FLUSH);
if(Z_STREAM_END == returnedValue) {
nextBlock();
} else if(Z_OK != returnedValue) {
coreLog.error(QString("in BgzfReader::read, failed to decompress %1 bytes, after %2 raw bytes already read")
.arg(sizeof(buffer))
.arg(ioAdapter.bytesRead()));
throw InvalidFormatException(BAMDbiPlugin::tr("Can't decompress data"));
}
}
if(0 == stream.avail_in) {
nextBlock();
}
qint64 bytesRead = maxSize - stream.avail_out;
return bytesRead;
}
示例12: LOG_ERROR
void
Thread::StartNonDetachedWithCleanup()
{
if(! runnable_)
{
LOG_ERROR("Null runnable, Thread already started??");
throw fungi::IOException("Thread already started");
}
ManagedRunnable* wrapper = new ManagedRunnable(*runnable_, true);
runnable_ = 0;
int res = pthread_create(&thread_,
&attr_,
thread_start_util_,
wrapper);
if (res != 0) {
throw IOException("Thread::start", "pthread_create", res);
}
}
示例13: catch
void DownloadOperation::onDownloadReply()
{
if (m_fos != NULL) {
try { m_fos->close(); } catch (...) { }
delete m_fos;
}
if (m_file != NULL) {
delete m_file;
}
m_file = new File(m_pathToTargetFile.getString());
if (m_fileOffset == 0) {
m_file->truncate();
}
try {
m_fos = new FileOutputStream(m_file);
FileSeeker fileSeeker(m_fos->getFD());
if (!fileSeeker.seek((INT64)m_fileOffset)) {
throw IOException(_T("Cannot seek to initial file position"));
}
m_totalBytesCopied += m_fileOffset;
} catch (IOException &ioEx) {
notifyFailedToDownload(ioEx.getMessage());
gotoNext();
return ;
}
UINT32 dataSize = 1024 * 8;
bool compression = m_replyBuffer->isCompressionSupported();
m_sender->sendDownloadDataRequest(dataSize,
compression);
}
示例14: locker
void FileOutputStream::open(const String fileName, bool append)
{
Locker locker(m_mutex);
if (m_fileDescriptor != -1)
{
close();
}
// Write access, create if needed
int flags = O_WRONLY | O_CREAT;
// Support large files if the OS supports it
#ifdef O_LARGEFILE
flags |= O_LARGEFILE;
#endif
// If passed in append, mask on the append option,
// otherwise truncate the file
if (append)
{
flags |= O_APPEND;
}
else
{
flags |= O_TRUNC;
}
m_fileDescriptor = UnixUtil::sys_open(fileName.c_str(), // File name
flags, // Creation flags, see above
0666); // File mask if created
if (m_fileDescriptor == -1)
{
throw IOException(String("Failed to open file: ") +
UnixUtil::getLastErrorMessage());
}
}
示例15: handleError
int SerialChannelImpl::writeImpl(const std::string& data)
{
if (0 == data.length()) return 0;
std::string d = data;
if (_config.getUseEOFImpl())
{
size_t pos = d.find(_config.getEOFCharImpl());
if (pos != d.npos) d = d.substr(0, pos+1);
}
DWORD written = 0;
DWORD length = static_cast<DWORD>(d.length());
if (!WriteFile(_handle, d.data(), length, &written, NULL) ||
((written != length) && (0 != written)))
handleError(_name);
else if (0 == written)
throw IOException("Error writing to " + _name);
return written;
}