1 #include "ace/config-lite.h"
2 #include "ace/OS_NS_string.h"
3 #include "ace/Get_Opt.h"
7 #endif /* (ACE_NTRACE != 1) */
9 #include "JAWS/Server.h"
10 #include "JAWS/Data_Block.h"
11 #include "JAWS/Concurrency.h"
12 #include "JAWS/Jaws_IO.h"
13 #include "JAWS/IO_Handler.h"
14 #include "JAWS/IO_Acceptor.h"
15 #include "JAWS/Pipeline_Tasks.h"
19 JAWS_Server::JAWS_Server (void)
29 JAWS_Server::JAWS_Server (int argc
, char *argv
[])
38 this->init (argc
, argv
);
42 JAWS_Server::init (int argc
, char *argv
[])
44 this->parse_args (argc
, argv
);
46 this->policy_
.ratio (this->ratio_
);
48 if (this->concurrency_
== 1)
50 JAWS_Thread_Per_Singleton::instance ()->make (this->flags_
,
52 this->policy_
.concurrency (JAWS_Thread_Per_Singleton::instance ());
56 JAWS_Thread_Pool_Singleton::instance ()->make (this->flags_
,
59 this->policy_
.concurrency (JAWS_Thread_Pool_Singleton::instance ());
62 #if !(defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS))
64 #endif /* !(ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS) */
66 if (this->dispatch_
== 1)
68 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
69 this->policy_
.io (JAWS_Asynch_IO_Singleton::instance ());
70 this->policy_
.ioh_factory
71 (JAWS_Asynch_IO_Handler_Factory_Singleton::instance ());
72 this->policy_
.acceptor (JAWS_IO_Asynch_Acceptor_Singleton::instance ());
73 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */
77 this->policy_
.io (JAWS_Synch_IO_Singleton::instance ());
78 this->policy_
.ioh_factory
79 (JAWS_Synch_IO_Handler_Factory_Singleton::instance ());
80 this->policy_
.acceptor (JAWS_IO_Synch_Acceptor_Singleton::instance ());
83 //FUZZ: disable check_for_lack_ACE_OS
84 ACE_INET_Addr
inet_addr (this->port_
);
85 //FUZZ: enable check_for_lack_ACE_OS
87 this->policy_
.acceptor ()->open (inet_addr
);
91 JAWS_Server::open (JAWS_Pipeline_Handler
*protocol
,
92 JAWS_Dispatch_Policy
*policy
)
95 policy
= &this->policy_
;
97 JAWS_Data_Block
*db
= new JAWS_Data_Block
;
100 ACE_DEBUG ((LM_DEBUG
,
101 "(%t) JAWS_Server::open, could not create Data_Block\n"));
105 // initialize data block
107 db
->task (JAWS_Pipeline_Accept_Task_Singleton::instance ());
111 db
->task ()->next (protocol
);
113 // prime the acceptor if appropriate
114 if (this->dispatch_
== 1)
116 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
118 int n
= this->nthreads_
;
119 if (this->concurrency_
== 1)
122 for (int i
= 0; i
< n
* this->ratio_
- n
; i
++)
123 db
->task ()->put (db
);
125 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */
128 // The message block should contain an INET_Addr, and call the
129 // io->accept (INET_Addr) method!
131 policy
->concurrency ()->put (db
);
133 ACE_Thread_Manager::instance ()->wait ();
141 JAWS_Server::parse_args (int argc
, ACE_TCHAR
*argv
[])
146 //FUZZ: disable check_for_lack_ACE_OS
147 ACE_Get_Opt
getopt (argc
, argv
, ACE_TEXT("t" "p:c:d:n:m:f:r:"));
148 while ((c
= getopt ()) != -1)
149 //FUZZ: enable check_for_lack_ACE_OS
156 this->port_
= ACE_OS::atoi (getopt
.opt_arg ());
159 if (ACE_OS::strcmp (getopt
.opt_arg (), "PER_REQUEST") == 0)
160 this->concurrency_
= 1;
161 else this->concurrency_
= 0;
164 if (ACE_OS::strcmp (getopt
.opt_arg (), "ASYNCH") == 0)
166 else this->dispatch_
= 0;
169 this->nthreads_
= ACE_OS::atoi (getopt
.opt_arg ());
172 this->maxthreads_
= ACE_OS::atoi (getopt
.opt_arg ());
175 if (ACE_OS::strcmp (getopt
.opt_arg (), "THR_BOUND") == 0)
176 this->flags_
|= THR_BOUND
;
177 else if (ACE_OS::strcmp (getopt
.opt_arg (), "THR_DAEMON") == 0)
178 this->flags_
|= THR_DAEMON
;
179 else if (ACE_OS::strcmp (getopt
.opt_arg (), "THR_DETACHED") == 0)
180 this->flags_
|= THR_DETACHED
;
183 this->ratio_
= ACE_OS::atoi (getopt
.opt_arg ());
187 #if (ACE_NTRACE != 1)
189 ACE_Trace::start_tracing ();
191 ACE_Trace::stop_tracing ();
192 #endif /* ACE_NTRACE != 1*/
194 if (this->port_
== 0) this->port_
= 5432;
195 if (this->nthreads_
== 0) this->nthreads_
= 5;
196 if (this->maxthreads_
== 0) this->maxthreads_
= 20;