ReactOS  0.4.15-dev-4570-g4f8bbd1
socket.h
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS HTTP Daemon
4  * FILE: include/socket.h
5  */
6 #ifndef __SOCKET_H
7 #define __SOCKET_H
8 #include <stdio.h>
9 #include <winsock2.h>
10 #include <thread.h>
11 #include <list.h>
12 #include <exception>
13 #include <assert.h>
14 
15 #define MAX_PENDING_CONNECTS 4 // The backlog allowed for listen()
16 
19 
20 class CSocket;
21 class CClientSocket;
25 
26 typedef CSocket* LPCSocket;
27 typedef CClientSocket* LPCClientSocket;
31 
32 class ESocket {
33 public:
36  LPTSTR what() { return Description; }
37 protected:
39 };
40 
41 class ESocketWinsock : public ESocket {
42 public:
44 };
45 
46 class ESocketDll : public ESocket {
47 public:
49 };
50 
51 class ESocketOpen : public ESocket {
52 public:
54 };
55 
56 class ESocketClose : public ESocket {
57 public:
59 };
60 
61 class ESocketSend : public ESocket {
62 public:
64 };
65 
66 class ESocketReceive : public ESocket {
67 public:
69 };
70 
71 
72 class CSocket {
73 public:
74  CSocket();
75  virtual ~CSocket();
76  virtual SOCKET GetSocket();
77  virtual VOID SetSocket(SOCKET socket);
78  virtual SOCKADDR_IN GetSockAddrIn();
79  virtual VOID SetSockAddrIn(SOCKADDR_IN sockaddrin);
80  virtual VOID SetEvents(LONG lEvents);
81  virtual LONG GetEvents();
82  virtual VOID SetPort( UINT nPort) {};
83  virtual VOID Open();
84  virtual VOID Close();
85  virtual INT Transmit( LPCSTR lpsBuffer, UINT nLength) { return 0; };
86  virtual INT Receive(LPSTR lpsBuffer, UINT nLength) { return 0; };
87  virtual INT SendText( LPCSTR lpsStr) { return 0; };
88 protected:
89  SOCKET Socket;
94 private:
96 };
97 
98 class CServerClientSocket : public CSocket {
99 public:
101  CServerClientSocket(LPCServerSocket lpServerSocket);
103  virtual INT Transmit( LPCSTR lpsBuffer, UINT nLength);
104  virtual INT Receive(LPSTR lpsBuffer, UINT nLength);
105  virtual INT SendText( LPCSTR lpsText);
106  virtual VOID MessageLoop();
107  virtual VOID OnRead() {};
108  //virtual VOID OnWrite() {};
109  virtual VOID OnClose() {};
110 protected:
112 };
113 
114 class CServerClientThread : public CThread {
115 public:
118  virtual ~CServerClientThread();
119 protected:
121 };
122 
123 class CServerSocket : public CSocket {
124 public:
125  CServerSocket();
126  virtual ~CServerSocket();
127  virtual VOID SetPort( UINT nPort);
128  virtual VOID Open();
129  virtual VOID Close();
130  virtual LPCServerClientSocket OnGetSocket(LPCServerSocket lpServerSocket);
132  virtual VOID OnAccept( LPCServerClientThread lpThread) {};
133  virtual VOID MessageLoop();
136 protected:
138 };
139 
140 #endif /* __SOCKET_H */
virtual VOID SetPort(UINT nPort)
Definition: socket.h:82
virtual LPCServerClientThread OnGetThread(LPCServerClientSocket lpSocket)
Definition: socket.cpp:312
virtual INT Transmit(LPCSTR lpsBuffer, UINT nLength)
Definition: socket.cpp:109
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
BOOL Active
Definition: socket.h:93
virtual ~CSocket()
Definition: socket.cpp:36
virtual VOID Open()
Definition: socket.cpp:90
virtual INT Receive(LPSTR lpsBuffer, UINT nLength)
Definition: socket.cpp:126
Definition: thread.h:18
virtual VOID SetSockAddrIn(SOCKADDR_IN sockaddrin)
Definition: socket.cpp:60
CClientSocket * LPCClientSocket
Definition: socket.h:27
virtual VOID SetEvents(LONG lEvents)
Definition: socket.cpp:66
SOCKADDR_IN SockAddrIn
Definition: socket.h:90
#define WSAEVENT
Definition: winsock2.h:585
_In_ DWORD nLength
Definition: wincon.h:473
virtual SOCKADDR_IN GetSockAddrIn()
Definition: socket.cpp:54
VOID InitWinsock()
Definition: socket.cpp:319
ESocketDll(LPTSTR description)
Definition: socket.h:48
const char * description
Definition: directx.c:2497
virtual INT SendText(LPCSTR lpsStr)
Definition: socket.h:87
char * LPSTR
Definition: xmlstorage.h:182
virtual INT SendText(LPCSTR lpsText)
Definition: socket.cpp:115
CSocket()
Definition: socket.cpp:18
int32_t INT
Definition: typedefs.h:58
virtual ~CServerSocket()
Definition: socket.cpp:176
CHAR * LPTSTR
Definition: xmlstorage.h:192
virtual VOID Close()
Definition: socket.cpp:95
virtual VOID OnAccept(LPCServerClientThread lpThread)
Definition: socket.h:132
virtual VOID MessageLoop()
Definition: socket.cpp:132
CServerClientSocket * LPCServerClientSocket
Definition: socket.h:28
VOID RemoveClient(LPCServerClientThread lpClient)
Definition: socket.cpp:300
LPTSTR what()
Definition: socket.h:36
VOID DeinitWinsock()
Definition: socket.cpp:340
LONG Events
Definition: socket.h:95
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
virtual VOID Close()
Definition: socket.cpp:212
SOCKET Socket
Definition: socket.h:87
Definition: socket.h:72
virtual INT Receive(LPSTR lpsBuffer, UINT nLength)
Definition: socket.h:86
virtual VOID SetSocket(SOCKET socket)
Definition: socket.cpp:47
const char * LPCSTR
Definition: xmlstorage.h:183
ESocketWinsock(LPTSTR description)
Definition: socket.h:43
virtual VOID OnClose()
Definition: socket.h:109
virtual VOID SetPort(UINT nPort)
Definition: socket.cpp:243
virtual SOCKET GetSocket()
Definition: socket.cpp:41
virtual VOID MessageLoop()
Definition: socket.cpp:251
virtual ~CServerClientThread()
Definition: socket.cpp:162
ESocket(LPTSTR description)
Definition: socket.h:35
LPCServerSocket ServerSocket
Definition: socket.h:109
CServerSocket * LPCServerSocket
Definition: socket.h:30
ESocketOpen(LPTSTR description)
Definition: socket.h:53
CList< LPCServerClientThread > Connections
Definition: socket.h:137
ESocketSend(LPTSTR description)
Definition: socket.h:63
ESocketClose(LPTSTR description)
Definition: socket.h:58
virtual LONG GetEvents()
Definition: socket.cpp:84
WSAEVENT Event
Definition: socket.h:91
virtual LPCServerClientSocket OnGetSocket(LPCServerSocket lpServerSocket)
Definition: socket.cpp:306
Definition: list.h:34
ESocket()
Definition: socket.h:34
VOID InsertClient(LPCServerClientThread lpClient)
Definition: socket.cpp:294
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
virtual INT Transmit(LPCSTR lpsBuffer, UINT nLength)
Definition: socket.h:85
Definition: socket.h:32
CServerClientThread * LPCServerClientThread
Definition: socket.h:29
UINT Port
Definition: socket.h:92
CSocket * LPCSocket
Definition: socket.h:24
CServerClientSocket * ClientSocket
Definition: socket.h:120
UINT_PTR SOCKET
Definition: winsock.h:47
LPTSTR Description
Definition: socket.h:38
virtual VOID OnRead()
Definition: socket.h:107
ESocketReceive(LPTSTR description)
Definition: socket.h:68
virtual VOID Open()
Definition: socket.cpp:183
CServerSocket * GetServerSocket()
Definition: socket.cpp:149