summaryrefslogtreecommitdiff
path: root/apps/JAWS/server/HTTP_Server.h
blob: d682ffbc88fa65be3587e60492a07c17eac7eab1 (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
// -*- C++ -*-
// $Id$

// ============================================================================
//
// = LIBRARY
//   jaws
// 
// = FILENAME
//    HTTP_Server.h
//
// = AUTHOR
//    James Hu
// 
// ============================================================================

#if !defined (HTTP_SERVER_H)
#define HTTP_SERVER_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 "HTTP_Handler.h"

// Forward declaration.
class ACE_Proactor;

#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 : public ACE_Service_Object
  // = TITLE
  //     This server is used to create HTTP Handlers for the Web
  //     server
  // 
  // = DESCRIPTION
{
public:
  virtual int init (int argc, char *argv[]);
  // Initialization

  virtual int fini (void);
  // Exit hooks

protected:
  virtual int thread_per_request (void);
  // Thread Per Request implementation

  virtual int asynch_thread_pool (void);
  // Asynch Thread Pool implementation
  
  virtual int synch_thread_pool (void);
  // Synch Thread Pool implementation
  
private:
  // James, comment these data members.
  void parse_args (int argc, char **argv);
  int port_;
  int threads_;
  int strategy_;
  int backlog_;
  int throttle_;
  ACE_Thread_Manager tm_;
  HTTP_Acceptor acceptor_;
};

class Synch_Thread_Pool_Task : public ACE_Task<ACE_NULL_SYNCH>
  // = TITLE
  //     Used to implement Synch Thread Pool
  // 
  // = DESCRIPTION
  //     Describe this and the others below.
{
public:
  Synch_Thread_Pool_Task (HTTP_Acceptor &acceptor,
                          ACE_Thread_Manager &tm,
                          int threads);
  virtual int svc (void);

private:
  HTTP_Acceptor &acceptor_;
};

class Thread_Per_Request_Task : public ACE_Task<ACE_NULL_SYNCH>
  // = TITLE
  //     Used to implement Thread Per Request.
  // 
  // = DESCRIPTION
  //     Spawns a new thread for every new incoming connection.  The
  //     handle below is the socket stream of the incoming connection.
{
public:
  Thread_Per_Request_Task (ACE_HANDLE handle,
                           ACE_Thread_Manager &tm,
                           int &grp_id);
  virtual int open (void *args = 0);
  virtual int close (u_long);
  virtual int svc (void);

private:
  ACE_HANDLE handle_;
  int &grp_id_;
};

// This only works on Win32
#if defined (ACE_WIN32)
class Asynch_Thread_Pool_Task : public ACE_Task<ACE_NULL_SYNCH>
  // = TITLE
  //     Used to implement Asynch Thread Pool
  // 
  // = DESCRIPTION
  //     The proactor below utilizes WaitForMultipleObjects.
{
public:
  Asynch_Thread_Pool_Task (ACE_Proactor &proactor,
                           ACE_Thread_Manager &tm);
  virtual int svc (void);

private:
  ACE_Proactor &proactor_;
};
#endif /* ACE_WIN32 */

ACE_STATIC_SVC_DECLARE (HTTP_Server)

#endif /* HTTP_SERVER_H */