summaryrefslogtreecommitdiffstats
path: root/WebServer/Socket.h
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-17 14:09:56 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-17 14:09:56 +0100
commit62c4ed1c2e81615f54ade6b4e3b1d77798468105 (patch)
tree28a5ac534b5379d091dc5d96bbd39450891fddee /WebServer/Socket.h
parentLots of logging added (diff)
downloadcuberite-62c4ed1c2e81615f54ade6b4e3b1d77798468105.tar
cuberite-62c4ed1c2e81615f54ade6b4e3b1d77798468105.tar.gz
cuberite-62c4ed1c2e81615f54ade6b4e3b1d77798468105.tar.bz2
cuberite-62c4ed1c2e81615f54ade6b4e3b1d77798468105.tar.lz
cuberite-62c4ed1c2e81615f54ade6b4e3b1d77798468105.tar.xz
cuberite-62c4ed1c2e81615f54ade6b4e3b1d77798468105.tar.zst
cuberite-62c4ed1c2e81615f54ade6b4e3b1d77798468105.zip
Diffstat (limited to '')
-rw-r--r--WebServer/Socket.h86
1 files changed, 50 insertions, 36 deletions
diff --git a/WebServer/Socket.h b/WebServer/Socket.h
index e38df69ea..5f1248107 100644
--- a/WebServer/Socket.h
+++ b/WebServer/Socket.h
@@ -39,6 +39,7 @@
#ifndef _WIN32
typedef int SOCKET;
#define SOCKET_ERROR (-1)
+ #define INVALID_SOCKET (-1)
#define closesocket close
#endif // !_WIN32
@@ -48,66 +49,79 @@
enum TypeSocket {BlockingSocket, NonBlockingSocket};
-class Socket {
+
+
+
+
+class Socket
+{
public:
- virtual ~Socket();
- Socket(const Socket&);
- Socket& operator=(Socket&);
+ virtual ~Socket();
+ Socket(const Socket&);
+ Socket& operator=(Socket&);
- std::string ReceiveLine();
- std::string ReceiveBytes( unsigned int a_Length );
+ std::string ReceiveLine();
+ std::string ReceiveBytes( unsigned int a_Length );
+
+ bool IsValid(void) const;
- void Close( bool a_WaitSend = false );
+ void Close( bool a_WaitSend = false );
- // The parameter of SendLine is not a const reference
- // because SendLine modifes the std::string passed.
- void SendLine (std::string);
+ // The parameter of SendLine is not a const reference
+ // because SendLine modifes the std::string passed.
+ void SendLine (std::string);
- // The parameter of SendBytes is a const reference
- // because SendBytes does not modify the std::string passed
- // (in contrast to SendLine).
- void SendBytes(const std::string&);
+ // The parameter of SendBytes is a const reference
+ // because SendBytes does not modify the std::string passed
+ // (in contrast to SendLine).
+ void SendBytes(const std::string&);
protected:
- friend class SocketServer;
- friend class SocketSelect;
+ friend class SocketServer;
+ friend class SocketSelect;
- Socket(SOCKET s);
- Socket();
+ Socket(SOCKET s);
+ Socket();
- SOCKET s_;
+ SOCKET s_;
- int* refCounter_;
+ int* refCounter_;
private:
- static void Start();
- static void End();
- static int nofSockets_;
+ static void Start();
+ static void End();
+ static int nofSockets_;
};
-class SocketClient : public Socket {
-public:
- SocketClient(const std::string& host, int port);
-};
-class SocketServer : public Socket {
+
+
+
+class SocketServer :
+ public Socket
+{
public:
- SocketServer(int port, int connections, TypeSocket type=BlockingSocket);
+ SocketServer(int port, int connections, TypeSocket type=BlockingSocket);
- Socket* Accept();
+ Socket* Accept();
};
+
+
+
+
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/wsapiref_2tiq.asp
-class SocketSelect {
- public:
- SocketSelect(Socket const * const s1, Socket const * const s2=NULL, TypeSocket type=BlockingSocket);
+class SocketSelect
+{
+public:
+ SocketSelect(Socket const * const s1, Socket const * const s2=NULL, TypeSocket type=BlockingSocket);
- bool Readable(Socket const * const s);
+ bool Readable(Socket const * const s);
- private:
- fd_set fds_;
+private:
+ fd_set fds_;
};
#endif