ReactOS 0.4.16-dev-125-g798ea90
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
20class CSocket;
21class CClientSocket;
24class CServerSocket;
25
27typedef CClientSocket* LPCClientSocket;
31
32class ESocket {
33public:
36 LPTSTR what() { return Description; }
37protected:
39};
40
41class ESocketWinsock : public ESocket {
42public:
44};
45
46class ESocketDll : public ESocket {
47public:
49};
50
51class ESocketOpen : public ESocket {
52public:
54};
55
56class ESocketClose : public ESocket {
57public:
59};
60
61class ESocketSend : public ESocket {
62public:
64};
65
66class ESocketReceive : public ESocket {
67public:
69};
70
71
72class CSocket {
73public:
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; };
88protected:
94private:
96};
97
99public:
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() {};
110protected:
112};
113
115public:
118 virtual ~CServerClientThread();
119protected:
121};
122
123class CServerSocket : public CSocket {
124public:
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();
136protected:
138};
139
140#endif /* __SOCKET_H */
Definition: list.h:34
virtual INT Receive(LPSTR lpsBuffer, UINT nLength)
Definition: socket.cpp:126
LPCServerSocket ServerSocket
Definition: socket.h:111
virtual VOID OnClose()
Definition: socket.h:109
CServerSocket * GetServerSocket()
Definition: socket.cpp:149
virtual INT Transmit(LPCSTR lpsBuffer, UINT nLength)
Definition: socket.cpp:109
virtual INT SendText(LPCSTR lpsText)
Definition: socket.cpp:115
virtual VOID MessageLoop()
Definition: socket.cpp:132
virtual VOID OnRead()
Definition: socket.h:107
virtual ~CServerClientThread()
Definition: socket.cpp:162
CServerClientThread(CServerClientSocket *socket)
CServerClientSocket * ClientSocket
Definition: socket.h:120
virtual LPCServerClientSocket OnGetSocket(LPCServerSocket lpServerSocket)
Definition: socket.cpp:306
virtual ~CServerSocket()
Definition: socket.cpp:176
virtual VOID OnAccept(LPCServerClientThread lpThread)
Definition: socket.h:132
virtual VOID Open()
Definition: socket.cpp:183
virtual VOID MessageLoop()
Definition: socket.cpp:251
virtual LPCServerClientThread OnGetThread(LPCServerClientSocket lpSocket)
Definition: socket.cpp:312
virtual VOID Close()
Definition: socket.cpp:212
CList< LPCServerClientThread > Connections
Definition: socket.h:137
VOID RemoveClient(LPCServerClientThread lpClient)
Definition: socket.cpp:300
VOID InsertClient(LPCServerClientThread lpClient)
Definition: socket.cpp:294
Definition: socket.h:72
virtual INT Transmit(LPCSTR lpsBuffer, UINT nLength)
Definition: socket.h:85
LONG Events
Definition: socket.h:95
WSAEVENT Event
Definition: socket.h:91
virtual ~CSocket()
Definition: socket.cpp:36
SOCKET Socket
Definition: socket.h:89
UINT Port
Definition: socket.h:92
virtual LONG GetEvents()
Definition: socket.cpp:84
virtual SOCKET GetSocket()
Definition: socket.cpp:41
virtual VOID SetSockAddrIn(SOCKADDR_IN sockaddrin)
Definition: socket.cpp:60
CSocket()
Definition: socket.cpp:18
virtual INT SendText(LPCSTR lpsStr)
Definition: socket.h:87
virtual VOID SetSocket(SOCKET socket)
Definition: socket.cpp:47
virtual INT Receive(LPSTR lpsBuffer, UINT nLength)
Definition: socket.h:86
virtual VOID SetEvents(LONG lEvents)
Definition: socket.cpp:66
virtual VOID Open()
Definition: socket.cpp:90
virtual VOID Close()
Definition: socket.cpp:95
virtual VOID SetPort(UINT nPort)
Definition: socket.h:82
virtual SOCKADDR_IN GetSockAddrIn()
Definition: socket.cpp:54
BOOL Active
Definition: socket.h:93
SOCKADDR_IN SockAddrIn
Definition: socket.h:90
Definition: thread.h:18
ESocketClose(LPTSTR description)
Definition: socket.h:58
ESocketDll(LPTSTR description)
Definition: socket.h:48
ESocketOpen(LPTSTR description)
Definition: socket.h:53
ESocketReceive(LPTSTR description)
Definition: socket.h:68
ESocketSend(LPTSTR description)
Definition: socket.h:63
ESocketWinsock(LPTSTR description)
Definition: socket.h:43
Definition: socket.h:32
LPTSTR what()
Definition: socket.h:36
ESocket(LPTSTR description)
Definition: socket.h:35
LPTSTR Description
Definition: socket.h:38
ESocket()
Definition: socket.h:34
#define NULL
Definition: types.h:112
unsigned int BOOL
Definition: ntddk_ex.h:94
CServerClientSocket * LPCServerClientSocket
Definition: socket.h:28
VOID DeinitWinsock()
Definition: socket.cpp:340
CClientSocket * LPCClientSocket
Definition: socket.h:27
CSocket * LPCSocket
Definition: socket.h:26
CServerSocket * LPCServerSocket
Definition: socket.h:30
CServerClientThread * LPCServerClientThread
Definition: socket.h:29
VOID InitWinsock()
Definition: socket.cpp:319
unsigned int UINT
Definition: ndis.h:50
long LONG
Definition: pedump.c:60
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
int32_t INT
Definition: typedefs.h:58
_In_ DWORD nLength
Definition: wincon.h:473
const char * description
Definition: directx.c:2497
DWORD WSAEVENT
Definition: winsock2.h:606
UINT_PTR SOCKET
Definition: winsock.h:47
#define SetPort
Definition: winspool.h:1247
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
CHAR * LPTSTR
Definition: xmlstorage.h:192