Go to the documentation of this file.00001 #ifndef _string_socket_h
00002 #define _string_socket_h
00003
00004
00005
00006 #include "../common/utilit.h"
00007
00008 enum NetworkErrorsEnum {
00009 neSuccess = 0,
00010 neNetworkError = 1,
00011 neTimeout = 2,
00012 neProtocolError = 3,
00013 neSubcorpusNotFound = 4,
00014 neInternalReadAccessError = 5,
00015 neCouldNotOpenSocket = 6,
00016 neCouldNotSendData = 7,
00017 neCouldNotReceiveData = 8,
00018
00019 };
00020
00021
00022 enum ProtocolDensityEnum {
00023 pdWeakDensity = 0,
00024 pdMediumDensity = 1,
00025 pdHeavyDensity = 2,
00026 };
00027
00028 #define SOCKET int
00029 #ifdef WIN32
00030 struct sockaddr_in;
00031 #endif
00032
00033
00034 class CHost
00035 {
00036 string m_HostName;
00037 int m_Port;
00038 SOCKET m_ListenSocket;
00039 bool m_bDoubleMessage;
00040 string m_LocalPath;
00041 ProtocolDensityEnum m_pdProtocolDensity;
00042
00043 void AnswerByRequest (SOCKET rConnectedSocket, const struct sockaddr_in* client_addr, int TimeOut, bool& bCloseSocket );
00044
00045 protected:
00046 virtual string ProcessSocketString(const string& S, SOCKET rConnectedSocket);
00047
00048 public:
00049
00050 string m_CorporaName;
00051 void (*m_LogFunction)(const string&);
00052
00053
00054 CHost(bool bDoubleMessage, ProtocolDensityEnum pdProtocolDensity);
00055 bool ReadFromString (string S);
00056 void CreateListener();
00057 void CopyAddressParametersFrom(const CHost& X);
00058 void StopAcceptingThread();
00059 void RunThread();
00060 int CreateAndConnectSocket(string& strError) const;
00061 string GetAddressStr() const;
00062 const string& GetLocalPathOfIndex() const;
00063 };
00064
00065 extern string GetNetworkErrorString(const NetworkErrorsEnum& t);
00066 extern bool SendString (int client_fd, const char* Str, uint32_t StrLen, string& ErrorStr);
00067 extern NetworkErrorsEnum RecieveString (int client_fd, string& Result, int TimeOut);
00068 extern bool SetSocketRecieveBuffer(int socket_fd, int BufferSize);
00069 extern bool SetSocketSendBuffer(int socket_fd, int BufferSize);
00070 extern bool SocketInitialize(bool bReadFromLocalFile);
00071 extern bool SocketDeinitialize();
00072 extern bool LoadHosts (string Path, vector<CHost>& Hosts);
00073 bool CloseSocket(int l_socket);
00074
00075
00076 #endif