/****************************************************************************************************

		MCNetStream.h
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Charles
		Date:	5/11/2004

****************************************************************************************************/

#ifndef __MCNetStream__
#define __MCNetStream__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCStream.h"
#include "MCArray.h"

struct IMCSocket;

/// \addtogroup MCCore
/// \{


/// TMCNetStream allows reading and writting data on a socket (TMCSocket)
///
class  TMCNetStream : public TMCiostream
{
	enum
	{
		kBufferSize = 256
	};
public:
				TMCNetStream(IMCSocket* socket);
				~TMCNetStream				();
		
	virtual int32	tell					();
	virtual void	seek					(int32 off, seek_dir dir=beg);
	virtual void	putback					(int8 c);
	virtual void	read					(int8* s,int32 n);
	virtual void	write					(const int8* s, int32 n);
	virtual	void	get						(int8& c);

	void			AttachToSocket(IMCSocket* socket);

	// send the data of the write buffer on the network
	void			Flush();

	void Close();

	// returns true if there is more data to read in the buffer
	boolean		MoreDataAvailable();
protected:
	TMCCountedPtr<IMCSocket>	fSocket;
	TMCArray<int8>				fBuffer;

	int32					fBufferCount;			///< number of characters read in the buffer
	int32					fCurrentPosition;		///< position in the buffer

	TMCArray<int8>			fWriteBuffer;
};    

/// \}








#endif
