#ifndef _string_socket_h
#define _string_socket_h



#include "../common/utilit.h"

enum NetworkErrorsEnum {
	neSuccess = 0,
	neNetworkError = 1,
	neTimeout = 2,
	neProtocolError = 3,
	neSubcorpusNotFound = 4,
	neInternalReadAccessError = 5
};


enum ProtocolDensityEnum {
	pdWeakDensity = 0,
	pdMediumDensity = 1,
	pdHeavyDensity = 2,
};

#ifndef WIN32
	#define SOCKET int
#endif

struct CHost  
{
	string				m_HostName;
	int					m_Port;
	string				m_LocalPath;
	string				m_CorporaName;
	bool				m_bThreadIsRunning;
	void			(*m_LogFunction)(const string&);
	ProtocolDensityEnum			m_pdProtocolDensity;
	bool				m_bDoubleMessage;

	CHost();
	

	bool			ReadFromString (string S);
	void			CreateListener();
	virtual string	ProcessSocketString(const string& S, SOCKET rConnectedSocket);
	virtual bool	InitHostData() {return true;};
	virtual bool	FreeHostData() {return true;};
	void			CopyFrom(const CHost& X);
};

extern string GetNetworkErrorString(const NetworkErrorsEnum& t);
extern bool SendString (int client_fd, const char* Str, size_t StrLen, string& ErrorStr);
extern NetworkErrorsEnum RecieveString (int  client_fd, string& Result, int TimeOut);
extern bool SetSocketRecieveBuffer(int socket_fd, int BufferSize);
extern bool SetSocketSendBuffer(int socket_fd, int BufferSize);
extern SOCKET create_and_bind (const char* HostName, int Port, string& strError);
extern SOCKET create_and_connect (const char* HostName, int Port, string& strError);
extern bool SocketInitialize(bool bReadFromLocalFile);
extern bool SocketDeinitialize();
extern bool	LoadHosts (string Path, vector<CHost>& Hosts);
bool CloseSocket(int l_socket);

	
#endif
