/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__NIONETCLIENT__
#define	__NIONETCLIENT__


		#include "io_net/io_net_client_worker_thread.h"
		#include "memory/nauto_ptr.h"


namespace GS {
	namespace IO {

//
class	NetHandle : public Handle
{
		friend class Net;

		int			remote_id;

public:

		NetHandle(Base *io, int id) : Handle(io), remote_id(id) {}
		~NetHandle();
};

/*!
	@short	Networked I/O client.
	@author	Emmanuel Julien (ejulien@nworks.fr)
*/
class	Net : public Base
{
		NetWorkerThread worker;

		bool		QueueTask(NetWorkerBaseTask &);

public:

virtual	uint		GetCaps() const;

virtual	Handle		*Open(const char *, Mode = ModeRead);
virtual	void		Close(Handle *);

virtual	String		Hash(const char *uri);
virtual	bool		Delete(const char *) { return false; }

virtual	size_t		Tell(Handle *);
virtual	size_t		Seek(Handle *, ptrdiff_t offset, SeekRef = SeekCurrent);

virtual	size_t		Read(Handle *, void *, size_t);
virtual	size_t		Write(Handle *, const void *, size_t) { return 0; }

virtual	bool		MkDir(const char *) { return false; }

		//---------------------------------------------------------------------
		bool		IsConnected() const;

		bool		Connect(const char *ip, int port);
		void		Disconnect();
		//---------------------------------------------------------------------

		~Net() { Disconnect(); }
};

	}	// IO
}	// GS


#endif	// __NIONETCLIENT__
