示例#1
0
inline std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& is, uuid& id)
{
    typedef typename std::basic_istream<CharT,Traits>::sentry sentry_t;
    sentry_t ok(is);
    if (ok)
    {
        CharT c;
        if (!is.get(c))
            return is;

        is.unget();

        if (c == is.widen('{'))
        {
            CharT buf[38+1];
            if (!is.read(buf, 38))
                return is;
            buf[38] = CharT();
            id = uuid(buf);
        }
        else
        {
            CharT buf[36+1];
            if (!is.read(buf, 36))
                return is;
            buf[36] = CharT();
            id = uuid(buf);
        }
    }
    return is;
}
示例#2
0
int ReadHTTPMessage(std::basic_istream<char>& stream, map<string,
                    string>& mapHeadersRet, string& strMessageRet,
                    int nProto)
{
    mapHeadersRet.clear();
    strMessageRet = "";

    // Read header
    int nLen = ReadHTTPHeaders(stream, mapHeadersRet);
    if (nLen < 0 || nLen > (int)MAX_SIZE)
        return HTTP_INTERNAL_SERVER_ERROR;

    // Read message
    if (nLen > 0)
    {
        vector<char> vch(nLen);
        stream.read(&vch[0], nLen);
        strMessageRet = string(vch.begin(), vch.end());
    }

    string sConHdr = mapHeadersRet["connection"];

    if ((sConHdr != "close") && (sConHdr != "keep-alive"))
    {
        if (nProto >= 1)
            mapHeadersRet["connection"] = "keep-alive";
        else
            mapHeadersRet["connection"] = "close";
    }

    return HTTP_OK;
}
示例#3
0
 void read_next()
 {
     parser_.begin_parse();
     while (!eof_ && !parser_.done())
     {
         if (!(index_ < buffer_length_))
         {
             if (!is_->eof())
             {
                 is_->read(buffer_.data(), buffer_capacity_);
                 buffer_length_ = static_cast<size_t>(is_->gcount());
                 if (buffer_length_ == 0)
                 {
                     eof_ = true;
                 }
                 index_ = 0;
             }
             else
             {
                 eof_ = true;
             }
         }
         if (!eof_)
         {
             parser_.parse(buffer_.data(),index_,buffer_length_);
             index_ = parser_.index();
         }
     }
     parser_.end_parse();
 }
示例#4
0
 void check_done()
 {
     while (!eof_)
     {
         if (!(index_ < buffer_length_))
         {
             if (!is_->eof())
             {
                 is_->read(buffer_.data(), buffer_capacity_);
                 buffer_length_ = static_cast<size_t>(is_->gcount());
                 if (buffer_length_ == 0)
                 {
                     eof_ = true;
                 }
                 index_ = 0;
             }
             else
             {
                 eof_ = true;
             }
         }
         if (!eof_)
         {
             parser_.check_done(buffer_.data(),index_,buffer_length_);
             index_ = parser_.index();
         }
     }
 }
示例#5
0
文件: wav.hpp 项目: januswel/avsutil
 inline std::basic_istream<Char>&
 operator >>(std::basic_istream<Char>& in, header_type& header) {
     in.read(
             util::cast::pointer_cast<char*>(&header),
             sizeof(header_type));
     return in;
 }
示例#6
0
int ReadHTTP (std::basic_istream<char>& stream, std::map<std::string, std::string>& mapHeadersRet,
              std::string& strMessageRet)
{
    mapHeadersRet.clear ();
    strMessageRet = "";

    // Read status
    int nStatus = ReadHTTPStatus (stream);

    // Read header
    int nLen = ReadHTTPHeader (stream, mapHeadersRet);

    if (nLen < 0 || nLen > gMaxHTTPHeaderSize)
        return 500;

    // Read message
    if (nLen > 0)
    {
        std::vector<char> vch (nLen);
        stream.read (&vch[0], nLen);
        strMessageRet = std::string (vch.begin (), vch.end ());
    }

    return nStatus;
}
示例#7
0
std::basic_istream<charT,traits> & operator >> (std::basic_istream<charT,traits> & iStream, BE<INT>& benum)
{
  INT val;
  iStream.read(reinterpret_cast<charT*>(&val), sizeof val);
  benum.value = endian::ntoh(val);
  return iStream ;
}
示例#8
0
std::basic_istream<charT,traits> & operator >> (std::basic_istream<charT,traits> & iStream, Bytes & str)
{
  BE<int32_t> sz; 
  iStream >> sz;
  str.bytes.resize(sz.value);
  iStream.read(reinterpret_cast<charT*>(str.bytes.data()), sz.value);
  return iStream ;
}
示例#9
0
文件: main.cpp 项目: CCJY/coliru
std::basic_istream<e,t>& operator>>(std::basic_istream<e,t>& in, const e(&sliteral)[N]) {
        e buffer[N-1] = {}; //get buffer
        in >> buffer[0]; //skips whitespace
        if (N>2)
                in.read(buffer+1, N-2); //read the rest
        if (strncmp(buffer, sliteral, N-1)) //if it failed
                in.setstate(in.rdstate() | std::ios::badbit); //set the state
        return in;
}
示例#10
0
文件: MSXML.hpp 项目: dmit25/nwlibs
inline void ReadBSTRFromStream( std::basic_istream< CharT, CharTraitsT > &Istream, ATL::CComBSTR &Str )
{ 
   Str.Empty();

   CharT Buff[256];

   do 
   {
      Istream.read( Buff, APL_ARRSIZE(Buff) );
      ATL::CComBSTR TmpStr(Istream.gcount(), Buff);
      Str.Append(TmpStr);   

   } while(Istream.gcount() == APL_ARRSIZE(Buff));
}
示例#11
0
std::basic_istream<CharT>& operator>>(std::basic_istream<CharT>& is, RMap<StrType>& param){
	size_t bufferSize = is.rdbuf()->in_avail();
	char* buffer = new CharT[bufferSize+1];
	is.read(buffer, bufferSize);
	buffer[bufferSize] = '\0';

	StrType str(buffer);
	typename StrType::iterator it = str.begin();
	parseMap<StrType>(param, it);

	delete[] buffer;

	return is;
}
示例#12
0
int ReadHTTPMessage(std::basic_istream<char>& stream, map<string,
                    string>& mapHeadersRet, string& strMessageRet,
                    int nProto, size_t max_size)
{
    mapHeadersRet.clear();
    strMessageRet = "";

    // Read header
    int nLen = ReadHTTPHeaders(stream, mapHeadersRet);
    if (nLen < 0 || (size_t)nLen > max_size)
        return HTTP_INTERNAL_SERVER_ERROR;

    // Read message
    if (nLen > 0)
    {
        //vector<char> vch(nLen);
        //stream.read(&vch[0], nLen);

        //RPC Bug Fix:
        //Prevent easy memory exhaustion attack
        //Allocate memory for POST message data only as bytes come in, instead of
        //all at once at the beginning.
        vector<char> vch;
        size_t ptr = 0;
        while (ptr < (size_t)nLen)
        {
            size_t bytes_to_read = std::min((size_t)nLen - ptr, POST_READ_SIZE);
            vch.resize(ptr + bytes_to_read);
            stream.read(&vch[ptr], bytes_to_read);
            if (!stream) // Connection lost while reading
                return HTTP_INTERNAL_SERVER_ERROR;
            ptr += bytes_to_read;
        }
        strMessageRet = string(vch.begin(), vch.end());
    }

    string sConHdr = mapHeadersRet["connection"];

    if ((sConHdr != "close") && (sConHdr != "keep-alive"))
    {
        if (nProto >= 1)
            mapHeadersRet["connection"] = "keep-alive";
        else
            mapHeadersRet["connection"] = "close";
    }

    return HTTP_OK;
}
示例#13
0
文件: MSXML.hpp 项目: dmit25/nwlibs
inline void ReadBSTRFromStream( std::basic_istream< WCHAR, CharTraitsT > &Istream, ATL::CComBSTR &Str )
{ 
   //Оптимизация исключающая временные объекты
   Str.Empty();

   WCHAR Buff[256];

   do 
   {
      Istream.read( Buff, APL_ARRSIZE(Buff) );
      Str.Append(Buff, Istream.gcount());   

   }
   while(Istream.gcount() == APL_ARRSIZE(Buff));

}
示例#14
0
int Buffer::pushBytesFromStream(std::basic_istream<char>& istr, int cnt)
{
    if (writeAvailable() < cnt)
        cnt = writeAvailable();

    istr.read((char*)_tail, cnt);
    if (istr.eof())
    {
        cnt = istr.gcount();
    }
    else if (istr.fail())
    {
        return -1;
    }
    _tail += cnt;
    return cnt;
}
示例#15
0
int ReadHTTPMessage(std::basic_istream<char>& stream, map<string,
                    string>& mapHeadersRet, string& strMessageRet,
                    int nProto, size_t max_size)
{
    mapHeadersRet.clear();
    strMessageRet = "";

    // Read header
    int nLen = ReadHTTPHeaders(stream, mapHeadersRet);
    if (nLen < 0 || (size_t)nLen > max_size)
        return HTTP_INTERNAL_SERVER_ERROR;

    // Read message
    if (nLen > 0)
    {
        vector<char> vch;
        size_t ptr = 0;
        while (ptr < (size_t)nLen)
        {
            size_t bytes_to_read = std::min((size_t)nLen - ptr, POST_READ_SIZE);
            vch.resize(ptr + bytes_to_read);
            stream.read(&vch[ptr], bytes_to_read);
            if (!stream) // Connection lost while reading
                return HTTP_INTERNAL_SERVER_ERROR;
            ptr += bytes_to_read;
        }
        strMessageRet = string(vch.begin(), vch.end());
    }

    string sConHdr = mapHeadersRet["connection"];

    if ((sConHdr != "close") && (sConHdr != "keep-alive"))
    {
        if (nProto >= 1)
            mapHeadersRet["connection"] = "keep-alive";
        else
            mapHeadersRet["connection"] = "close";
    }

    return HTTP_OK;
}
示例#16
0
		friend std::basic_istream<charT, traits> & operator >> (
			std::basic_istream<charT, traits> &stream, const mytype &value)
		{
			return stream.read((char *)&value.value, sizeof(valueT));
		}