Example #1
0
ConstString::ConstString(std::istream& rStrm,size_t iLen) {
    _pConstantString = NULL;
    _iLen = 0;
    _pAllocString = NULL;

    if (rStrm.eof()) {
        throw EndOfFileException();
    }
    if (iLen <= 0) {
        throw IllegalLengthException();
    }

    _iLen = iLen;
    _pAllocString = new char[iLen+1];
    _pAllocString[iLen] = 0;


    size_t pos,strmLen;
    pos = rStrm.tellg();
    rStrm.seekg(0,std::ios::end);
    strmLen = size_t(rStrm.tellg()) - pos;
    rStrm.seekg(pos);

    rStrm.read(_pAllocString,iLen);

    if (rStrm.eof()) {
        _iLen = strmLen;
        _pAllocString[_iLen] = 0;
    }
}
 std::unique_ptr<typename LocalServerConnection<BufferType>::Channel>
     LocalServerConnection<BufferType>::Accept() {
   PendingChannelEntry* entry;
   try {
     entry = m_pendingChannels->Top();
   } catch(const std::exception&) {
     BOOST_THROW_EXCEPTION(EndOfFileException());
   }
   m_pendingChannels->Pop();
   auto channel = Threading::With(m_clientToServerChannels,
     [&] (ClientToServerChannels& clientToServerChannels) {
       auto channelIterator = clientToServerChannels.find(
         entry->m_clientChannel);
       if(channelIterator == clientToServerChannels.end()) {
         return std::unique_ptr<Channel>{};
       }
       auto channel = std::move(channelIterator->second);
       clientToServerChannels.erase(channelIterator);
       return channel;
     });
   if(channel == nullptr) {
     return Accept();
   }
   channel->m_connection.m_isOpen = true;
   entry->m_result.SetResult();
   return channel;
 }
Example #3
0
void FileStream::ensureRead_slow(void* vbuf, size_t length) {
	assert(m_fp);
	size_t n = ::fread(vbuf, 1, length, m_fp);
	if (n != length) {
		throw EndOfFileException(BOOST_CURRENT_FUNCTION);
	}
}
	char getChar() {
		if (type == TYPE_STRING) {
			if (this->string.size()) {
				int c = (int) this->string[0];
				this->string = this->string.substr(1);
				return c;
			} else {
				throw EndOfFileException("end of file", __FILE__, __LINE__);
			}
		} else {
			int c = fgetc(this->proc_or_file);
			if (c != EOF)
				return c;
			else
				throw EndOfFileException("end of file", __FILE__, __LINE__);
		}
	}
Example #5
0
byte FileStream::readByte_slow() throw(EndOfFileException)
{
	assert(m_fp);
#ifdef __USE_MISC
	int ch = fgetc_unlocked(m_fp);
#else
	int ch = fgetc(m_fp);
#endif
	if (-1 == ch)
		throw EndOfFileException(BOOST_CURRENT_FUNCTION);
	return ch;
}
	void DataIO_loadObject(Input& input, CString& x)
	{
		var_size_t size;
		input >> size;
		LPTSTR buf = x.GetBufferSetLength(size.t);
		buf[size] = 0;
		uint32_t size2 = input.read(buf, size.t);

		if (size2 != size.t)
		{
			throw EndOfFileException("when load CString");
		}
		x.ReleaseBuffer(size.t);
	}