
/*
 * $Log: BinSocketInputStream.hpp,v $
 * Revision 0.1  2003/05/10 02:37:54  gtw
 * Derived from BinHTTPURLInputStream.
 *
 */

#if !defined(BinSocketInputStream_HPP)
#define BinSocketInputStream_HPP


#include <xercesc/util/XMLURL.hpp>
#include <xercesc/util/XMLExceptMsgs.hpp>
#include <xercesc/util/BinInputStream.hpp>
#include <xercesc/util/Mutexes.hpp>


//
// This class implements the BinInputStream interface specified by the XML
// parser.
//
struct hostent;
struct sockaddr;
struct fd_set ;
struct timeval;
XERCES_CPP_NAMESPACE_BEGIN

class XMLUTIL_EXPORT BinSocketInputStream : public BinInputStream
{
public :
    BinSocketInputStream(const XMLURL&  urlSource);
    ~BinSocketInputStream();

    unsigned int curPos() const;
    unsigned int readBytes
    (
                XMLByte* const  toFill
        , const unsigned int    maxToRead
    );

	static void Cleanup();


private :
    // -----------------------------------------------------------------------
    //  Private data members
    //
    //  fSocketHandle
    //      The socket representing the connection to the remote file.
    //      We deliberately did not define the type to be SOCKET, so as to
    //      avoid bringing in any Windows header into this file.
    //  fBytesProcessed
    //      Its a rolling count of the number of bytes processed off this
    //      input stream.
    //  fBuffer
    //      Holds the http header, plus the first part of the actual
    //      data.  Filled at the time the stream is opened, data goes
    //      out to user in response to readBytes().
    //  fBufferPos, fBufferEnd
    //      Pointers into fBuffer, showing start and end+1 of content
    //      that readBytes must return.
    // -----------------------------------------------------------------------

    unsigned int        fSocketHandle;
    unsigned int        fClientSocketHandle ;
    unsigned int        fBytesProcessed;
    char                fBuffer[4000];
    char *              fBufferEnd;
    char *              fBufferPos;
    static bool         fInitialized;
    static XMLMutex*        fInitMutex;
  void WinSocketConstructor(const XMLURL& urlSource);
	void UnxSocketConstructor(const XMLURL& urlSource);
	static void Initialize();
};


inline unsigned int BinSocketInputStream::curPos() const
{
    return fBytesProcessed;
}

XERCES_CPP_NAMESPACE_END

#endif // BinSocketInputStream_HPP
