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"
18 JAWS_Server::JAWS_Server ()
28 JAWS_Server::JAWS_Server (int argc
, char *argv
[])
37 this->init (argc
, argv
);
41 JAWS_Server::init (int argc
, char *argv
[])
43 this->parse_args (argc
, argv
);
45 this->policy_
.ratio (this->ratio_
);
47 if (this->concurrency_
== 1)
49 JAWS_Thread_Per_Singleton::instance ()->make (this->flags_
,
51 this->policy_
.concurrency (JAWS_Thread_Per_Singleton::instance ());
55 JAWS_Thread_Pool_Singleton::instance ()->make (this->flags_
,
58 this->policy_
.concurrency (JAWS_Thread_Pool_Singleton::instance ());
61 #if !(defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS))
63 #endif /* !(ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS) */
65 if (this->dispatch_
== 1)
67 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
68 this->policy_
.io (JAWS_Asynch_IO_Singleton::instance ());
69 this->policy_
.ioh_factory
70 (JAWS_Asynch_IO_Handler_Factory_Singleton::instance ());
71 this->policy_
.acceptor (JAWS_IO_Asynch_Acceptor_Singleton::instance ());
72 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */
76 this->policy_
.io (JAWS_Synch_IO_Singleton::instance ());
77 this->policy_
.ioh_factory
78 (JAWS_Synch_IO_Handler_Factory_Singleton::instance ());
79 this->policy_
.acceptor (JAWS_IO_Synch_Acceptor_Singleton::instance ());
82 //FUZZ: disable check_for_lack_ACE_OS
83 ACE_INET_Addr
inet_addr (this->port_
);
84 //FUZZ: enable check_for_lack_ACE_OS
86 this->policy_
.acceptor ()->open (inet_addr
);
90 JAWS_Server::open (JAWS_Pipeline_Handler
*protocol
,
91 JAWS_Dispatch_Policy
*policy
)
94 policy
= &this->policy_
;
96 JAWS_Data_Block
*db
= new JAWS_Data_Block
;
100 "(%t) JAWS_Server::open, could not create Data_Block\n"));
104 // initialize data block
106 db
->task (JAWS_Pipeline_Accept_Task_Singleton::instance ());
110 db
->task ()->next (protocol
);
112 // prime the acceptor if appropriate
113 if (this->dispatch_
== 1)
115 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
117 int n
= this->nthreads_
;
118 if (this->concurrency_
== 1)
121 for (int i
= 0; i
< n
* this->ratio_
- n
; i
++)
122 db
->task ()->put (db
);
124 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */
127 // The message block should contain an INET_Addr, and call the
128 // io->accept (INET_Addr) method!
130 policy
->concurrency ()->put (db
);
132 ACE_Thread_Manager::instance ()->wait ();
140 JAWS_Server::parse_args (int argc
, ACE_TCHAR
*argv
[])
145 //FUZZ: disable check_for_lack_ACE_OS
146 ACE_Get_Opt
getopt (argc
, argv
, ACE_TEXT("t" "p:c:d:n:m:f:r:"));
147 while ((c
= getopt ()) != -1)
148 //FUZZ: enable check_for_lack_ACE_OS
155 this->port_
= ACE_OS::atoi (getopt
.opt_arg ());
158 if (ACE_OS::strcmp (getopt
.opt_arg (), "PER_REQUEST") == 0)
159 this->concurrency_
= 1;
160 else this->concurrency_
= 0;
163 if (ACE_OS::strcmp (getopt
.opt_arg (), "ASYNCH") == 0)
165 else this->dispatch_
= 0;
168 this->nthreads_
= ACE_OS::atoi (getopt
.opt_arg ());
171 this->maxthreads_
= ACE_OS::atoi (getopt
.opt_arg ());
174 if (ACE_OS::strcmp (getopt
.opt_arg (), "THR_BOUND") == 0)
175 this->flags_
|= THR_BOUND
;
176 else if (ACE_OS::strcmp (getopt
.opt_arg (), "THR_DAEMON") == 0)
177 this->flags_
|= THR_DAEMON
;
178 else if (ACE_OS::strcmp (getopt
.opt_arg (), "THR_DETACHED") == 0)
179 this->flags_
|= THR_DETACHED
;
182 this->ratio_
= ACE_OS::atoi (getopt
.opt_arg ());
186 #if (ACE_NTRACE != 1)
188 ACE_Trace::start_tracing ();
190 ACE_Trace::stop_tracing ();
191 #endif /* ACE_NTRACE != 1*/
193 if (this->port_
== 0) this->port_
= 5432;
194 if (this->nthreads_
== 0) this->nthreads_
= 5;
195 if (this->maxthreads_
== 0) this->maxthreads_
= 20;