Panda3D

chunkedStreamBuf.h

00001 // Filename: chunkedStreamBuf.h
00002 // Created by:  drose (25Sep02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef CHUNKEDSTREAMBUF_H
00016 #define CHUNKEDSTREAMBUF_H
00017 
00018 #include "pandabase.h"
00019 
00020 // This module is not compiled if OpenSSL is not available.
00021 #ifdef HAVE_OPENSSL
00022 
00023 #include "httpChannel.h"
00024 #include "bioStreamPtr.h"
00025 #include "pointerTo.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : ChunkedStreamBuf
00029 // Description : The streambuf object that implements
00030 //               IChunkedStream.
00031 ////////////////////////////////////////////////////////////////////
00032 // No need to export from DLL.
00033 class ChunkedStreamBuf : public streambuf {
00034 public:
00035   ChunkedStreamBuf();
00036   virtual ~ChunkedStreamBuf();
00037 
00038   void open_read(BioStreamPtr *source, HTTPChannel *doc);
00039   void close_read();
00040 
00041   INLINE bool is_closed() const;
00042   INLINE ISocketStream::ReadState get_read_state() const;
00043 
00044 protected:
00045   virtual int underflow();
00046 
00047 private:
00048   size_t read_chars(char *start, size_t length);
00049   bool http_getline(string &str);
00050 
00051   PT(BioStreamPtr) _source;
00052   size_t _chunk_remaining;
00053   bool _done;
00054   bool _wanted_nonblocking;
00055   string _working_getline;
00056   ISocketStream::ReadState _read_state;
00057 
00058   PT(HTTPChannel) _doc;
00059   int _read_index;
00060   char *_buffer;
00061 
00062   friend class IChunkedStream;
00063 };
00064 
00065 #include "chunkedStreamBuf.I"
00066 
00067 #endif  // HAVE_OPENSSL
00068 
00069 #endif
 All Classes Functions Variables Enumerations