| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #ifndef Network_H
- #define Network_H
- #ifdef WIN32
- # ifdef _DEBUG
- # ifndef _LTMDB
- # define _CRTDBG_MAP_ALLOC
- # include <crtdbg.h>
- # include <stdlib.h>
- # define DEBUG_CLIENTBLOCK new (_CLIENT_BLOCK, __FILE__, __LINE__)
- # define new DEBUG_CLIENTBLOCK
- # define _LTMDB
- # endif
- # endif
- # define _WINSOCK_DEPRECATED_NO_WARNINGS
- # include <WinSock2.h>
- #else
- # include <arpa/inet.h>
- # include <fcntl.h>
- # include <iostream>
- # include <netinet/in.h>
- # include <sys/socket.h>
- # include <sys/time.h>
- # include <unistd.h>
- # define __declspec(x)
- # define __int64 long long
- # ifndef SOCKET
- # define SOCKET int
- # define SOCKADDR_IN sockaddr_in
- # define ADDR_ANY INADDR_ANY
- # define closesocket close
- # define PHOSTENT hostent*
- # endif
- #endif
- #include <Reader.h>
- #include <Writer.h>
- namespace Framework
- {
- class Text;
- }
- namespace Network
- {
- __declspec(dllexport) void Start(int maxClients);
- __declspec(dllexport) void getHostName(char* name, int bufferLen);
- __declspec(dllexport) char* getHostAddress();
- __declspec(dllexport) void Exit();
- class Connection
- {
- public:
- virtual bool send(const char* message, int len)
- = 0; // sends message
- virtual bool getMessage(char* message, int len)
- = 0; // receives message
- };
- class EncryptedConnection : public Connection
- {
- public:
- virtual bool sendEncrypted(const char* message, int len)
- = 0; // sends message
- virtual bool getMessageEncrypted(char* message, int len)
- = 0; // receives message
- };
- class NetworkReader : public Framework::StreamReader
- {
- private:
- Connection* connection;
- public:
- __declspec(dllexport) NetworkReader(Connection* v);
- __declspec(dllexport) virtual ~NetworkReader();
- //! Reads from the resource
- //! \param bytes An array to be filled with bytes from the resource
- //! \param len How many bytes to read from the resource
- __declspec(dllexport) void read(char* bytes, int len) override;
- //! Reads the next line from the resource
- //! \return The read line as text with line break
- __declspec(dllexport) Framework::Text* readLine() override;
- //! Checks whether the resource has been fully read
- //! return 1 if the resource has been fully read. 0 otherwise
- __declspec(dllexport) bool isEnd() const override;
- };
- class NetworkWriter : public Framework::StreamWriter
- {
- private:
- Connection* connection;
- public:
- __declspec(dllexport) NetworkWriter(Connection* v);
- __declspec(dllexport) virtual ~NetworkWriter();
- //! Writes to the resource
- //! \param bytes An array containing the bytes to write to the resource
- //! \param len How many bytes to write to the resource
- __declspec(dllexport) void write(const char* bytes, int len) override;
- //! Checks whether the resource has been fully written
- //! return 1 if the resource has been fully written. 0 otherwise
- __declspec(dllexport) bool isEnd() const override;
- };
- class EncryptedNetworkReader : public Framework::StreamReader
- {
- private:
- EncryptedConnection* connection;
- public:
- __declspec(dllexport) EncryptedNetworkReader(EncryptedConnection* v);
- //! Reads from the resource
- //! \param bytes An array to be filled with bytes from the resource
- //! \param len How many bytes to read from the resource
- __declspec(dllexport) void read(char* bytes, int len) override;
- //! Reads the next line from the resource
- //! \return The read line as text with line break
- __declspec(dllexport) Framework::Text* readLine() override;
- //! Checks whether the resource has been fully read
- //! return 1 if the resource has been fully read. 0 otherwise
- __declspec(dllexport) bool isEnd() const override;
- };
- class EncryptedNetworkWriter : public Framework::StreamWriter
- {
- private:
- EncryptedConnection* connection;
- public:
- __declspec(dllexport) EncryptedNetworkWriter(EncryptedConnection* v);
- //! Writes to the resource
- //! \param bytes An array containing the bytes to write to the resource
- //! \param len How many bytes to write to the resource
- __declspec(dllexport) void write(const char* bytes, int len) override;
- //! Checks whether the resource has been fully written
- //! return 1 if the resource has been fully written. 0 otherwise
- __declspec(dllexport) bool isEnd() const override;
- };
- } // namespace Network
- #endif
|