1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
//
// CScriptSocket
//
// This class represents a socket. It can be used to set up listeners for
// connecting incoming clients, and also to connect to a server. The socket
// class will create threads in the background to handle the communication
// and update a send and a receive buffer so the script will not have to deal
// with that.
//
#ifndef SCRIPTSOCKET_H
#define SCRIPTSOCKET_H
#include <string>
#include <list>
#ifdef _WIN32
#include <winsock2.h>
#endif
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include <angelscript.h>
#endif
BEGIN_AS_NAMESPACE
#ifdef _WIN32
class CScriptSocket
{
public:
CScriptSocket();
// Memory management
void AddRef() const;
void Release() const;
// Methods
int Listen(asWORD port);
int Close();
CScriptSocket* Accept(asINT64 timeoutMicrosec = 0);
int Connect(asUINT ipv4Address, asWORD port);
int Send(const std::string& data);
std::string Receive(asINT64 timeoutMicrosec = 0);
bool IsActive() const;
protected:
~CScriptSocket();
int Select(asINT64 timeoutMicrosec = 0);
mutable int m_refCount;
int m_socket;
bool m_isListening;
};
#endif
int RegisterScriptSocket(asIScriptEngine* engine);
END_AS_NAMESPACE
#endif
|