blob: c7afbf729e087c8294f03c260451c510c92f24cd (
plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
// -*- C++ -*-
//=============================================================================
/**
* @file HTTP_Server.h
*
* $Id$
*
* @author James Hu
*/
//=============================================================================
#ifndef HTTP_SERVER_H
#define HTTP_SERVER_H
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "ace/Service_Config.h"
#include "ace/Service_Object.h"
#include "ace/Thread_Manager.h"
#include "ace/Acceptor.h"
#include "ace/LOCK_SOCK_Acceptor.h"
#include "ace/Task_T.h"
#include "ace/Asynch_IO.h"
#include "ace/svc_export.h"
#include "HTTP_Handler.h"
#include "ace/Synch_Traits.h"
#include "ace/Thread_Mutex.h"
#include "ace/Null_Mutex.h"
#include "ace/Global_Macros.h"
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
// Forward declaration.
class ACE_Proactor;
ACE_END_VERSIONED_NAMESPACE_DECL
#if defined (ACE_HAS_THREAD_SAFE_ACCEPT)
typedef ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_NULL_MUTEX> HTTP_SOCK_Acceptor;
#else
typedef ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_MUTEX> HTTP_SOCK_Acceptor;
#endif /* ACE_HAS_THREAD_SAFE_ACCEPT */
typedef HTTP_SOCK_Acceptor HTTP_Acceptor;
/**
* @class HTTP_Server
*
* @brief This server is used to create HTTP Handlers for the Web
* server
*
*/
class ACE_Svc_Export HTTP_Server : public ACE_Service_Object
{
public:
/// Initialization
virtual int init (int argc, ACE_TCHAR *argv[]);
/// Exit hooks
virtual int fini (void);
protected:
/// Thread Per Request implementation
virtual int thread_per_request (HTTP_Handler_Factory &factory);
/// Asynch Thread Pool implementation
virtual int asynch_thread_pool (void);
/// Synch Thread Pool implementation
virtual int synch_thread_pool (HTTP_Handler_Factory &factory);
private:
// James, comment these data members.
void parse_args (int argc, ACE_TCHAR **argv);
int port_;
int threads_;
int strategy_;
int backlog_;
int throttle_;
bool caching_;
ACE_Thread_Manager tm_;
HTTP_Acceptor acceptor_;
};
/**
* @class Synch_Thread_Pool_Task
*
* @brief Used to implement Synch Thread Pool
*
* Describe this and the others below.
* NOTE: this class was modified to make caching disabling possible
*/
class Synch_Thread_Pool_Task : public ACE_Task<ACE_NULL_SYNCH>
{
public:
Synch_Thread_Pool_Task (HTTP_Acceptor &acceptor,
ACE_Thread_Manager &tm,
int threads,
HTTP_Handler_Factory &factory);
virtual int svc (void);
private:
HTTP_Acceptor &acceptor_;
HTTP_Handler_Factory &factory_;
};
/**
* @class Thread_Per_Request_Task
*
* @brief Used to implement Thread Per Request.
*
* Spawns a new thread for every new incoming connection. The
* handle below is the socket stream of the incoming connection.
* NOTE: this class was modified to make caching disabling possible
*/
class Thread_Per_Request_Task : public ACE_Task<ACE_NULL_SYNCH>
{
public:
Thread_Per_Request_Task (ACE_HANDLE handle,
ACE_Thread_Manager &tm,
int &grp_id,
HTTP_Handler_Factory &factory);
virtual int open (void *args = 0);
virtual int close (u_long);
virtual int svc (void);
private:
ACE_HANDLE handle_;
int &grp_id_;
HTTP_Handler_Factory &factory_;
};
// This only works on Win32
#if defined (ACE_HAS_WIN32_OVERLAPPED_IO)
/**
* @class Asynch_Thread_Pool_Task
*
* @brief Used to implement Asynch Thread Pool
*
* The proactor below utilizes WaitForMultipleObjects.
*/
class Asynch_Thread_Pool_Task : public ACE_Task<ACE_NULL_SYNCH>
{
public:
Asynch_Thread_Pool_Task (ACE_Proactor &proactor,
ACE_Thread_Manager &tm);
virtual int svc (void);
private:
ACE_Proactor &proactor_;
};
#endif /* ACE_HAS_WIN32_OVERLAPPED_IO */
ACE_SVC_FACTORY_DECLARE (HTTP_Server)
ACE_STATIC_SVC_DECLARE_EXPORT (ACE_Svc, HTTP_Server)
#endif /* HTTP_SERVER_H */
|