af80807e66d4fe8434120ffeec55d0f84c2bc171
[reactos.git] / reactos / apps / utils / net / roshttpd / include / socket.h
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 <crtdll/stdio.h>
9 #include <windows.h>
10 #include <winsock2.h>
11 #include <thread.h>
12 #include <list.h>
13 #include <exception>
14 #include <assert.h>
15
16 #define MAX_PENDING_CONNECTS 4 // The backlog allowed for listen()
17
18 VOID InitWinsock();
19 VOID DeinitWinsock();
20
21 class CSocket;
22 class CClientSocket;
23 class CServerClientSocket;
24 class CServerClientThread;
25 class CServerSocket;
26
27 typedef CSocket* LPCSocket;
28 typedef CClientSocket* LPCClientSocket;
29 typedef CServerClientSocket* LPCServerClientSocket;
30 typedef CServerClientThread* LPCServerClientThread;
31 typedef CServerSocket* LPCServerSocket;
32
33 class ESocket {
34 public:
35 ESocket() { Description = NULL; }
36 ESocket(LPTSTR description) { Description = description; }
37 LPTSTR what() { return Description; }
38 protected:
39 LPTSTR Description;
40 };
41
42 class ESocketWinsock : public ESocket {
43 public:
44 ESocketWinsock(LPTSTR description) { Description = description; }
45 };
46
47 class ESocketDll : public ESocket {
48 public:
49 ESocketDll(LPTSTR description) { Description = description; }
50 };
51
52 class ESocketOpen : public ESocket {
53 public:
54 ESocketOpen(LPTSTR description) { Description = description; }
55 };
56
57 class ESocketClose : public ESocket {
58 public:
59 ESocketClose(LPTSTR description) { Description = description; }
60 };
61
62 class ESocketSend : public ESocket {
63 public:
64 ESocketSend(LPTSTR description) { Description = description; }
65 };
66
67 class ESocketReceive : public ESocket {
68 public:
69 ESocketReceive(LPTSTR description) { Description = description; }
70 };
71
72
73 class CSocket {
74 public:
75 CSocket();
76 virtual ~CSocket();
77 virtual SOCKET GetSocket();
78 virtual VOID SetSocket(SOCKET socket);
79 virtual SOCKADDR_IN GetSockAddrIn();
80 virtual VOID SetSockAddrIn(SOCKADDR_IN sockaddrin);
81 virtual VOID SetEvents(LONG lEvents);
82 virtual LONG GetEvents();
83 virtual VOID SetPort( UINT nPort) {};
84 virtual VOID Open();
85 virtual VOID Close();
86 virtual INT Transmit( LPSTR lpsBuffer, UINT nLength) { return 0; };
87 virtual INT Receive(LPSTR lpsBuffer, UINT nLength) { return 0; };
88 virtual INT SendText( LPSTR lpsStr) { return 0; };
89 protected:
90 SOCKET Socket;
91 SOCKADDR_IN SockAddrIn;
92 WSAEVENT Event;
93 UINT Port;
94 BOOL Active;
95 private:
96 LONG Events;
97 };
98
99 class CServerClientSocket : public CSocket {
100 public:
101 CServerClientSocket() {};
102 CServerClientSocket(LPCServerSocket lpServerSocket);
103 CServerSocket *GetServerSocket();
104 virtual INT Transmit( LPSTR lpsBuffer, UINT nLength);
105 virtual INT Receive(LPSTR lpsBuffer, UINT nLength);
106 virtual INT SendText( LPSTR lpsText);
107 virtual VOID MessageLoop();
108 virtual VOID OnRead() {};
109 //virtual VOID OnWrite() {};
110 virtual VOID OnClose() {};
111 protected:
112 LPCServerSocket ServerSocket;
113 };
114
115 class CServerClientThread : public CThread {
116 public:
117 CServerClientThread() {};
118 CServerClientThread(CServerClientSocket *socket);
119 virtual ~CServerClientThread();
120 protected:
121 CServerClientSocket *ClientSocket;
122 };
123
124 class CServerSocket : public CSocket {
125 public:
126 CServerSocket();
127 virtual ~CServerSocket();
128 virtual VOID SetPort( UINT nPort);
129 virtual VOID Open();
130 virtual VOID Close();
131 virtual LPCServerClientSocket OnGetSocket(LPCServerSocket lpServerSocket);
132 virtual LPCServerClientThread OnGetThread(LPCServerClientSocket lpSocket);
133 virtual VOID OnAccept( LPCServerClientThread lpThread) {};
134 virtual VOID MessageLoop();
135 VOID InsertClient(LPCServerClientThread lpClient);
136 VOID RemoveClient(LPCServerClientThread lpClient);
137 protected:
138 CList<LPCServerClientThread> Connections;
139 };
140
141 #endif /* __SOCKET_H */