Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Server.cpp
blobf98e91966391532200a4612b997a31ebd74a3a16
1 #include "ace/config-lite.h"
2 #include "ace/OS_NS_string.h"
3 #include "ace/Get_Opt.h"
5 #if (ACE_NTRACE != 1)
6 #include "ace/Trace.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 ()
19 : port_ (5432),
20 concurrency_ (0),
21 dispatch_ (0),
22 nthreads_ (5),
23 maxthreads_ (20),
24 flags_ (THR_NEW_LWP)
28 JAWS_Server::JAWS_Server (int argc, char *argv[])
29 : ratio_ (1),
30 port_ (5432),
31 concurrency_ (0),
32 dispatch_ (0),
33 nthreads_ (5),
34 maxthreads_ (20),
35 flags_ (THR_NEW_LWP)
37 this->init (argc, argv);
40 void
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_,
50 this->maxthreads_);
51 this->policy_.concurrency (JAWS_Thread_Per_Singleton::instance ());
53 else
55 JAWS_Thread_Pool_Singleton::instance ()->make (this->flags_,
56 this->nthreads_,
57 this->maxthreads_);
58 this->policy_.concurrency (JAWS_Thread_Pool_Singleton::instance ());
61 #if !(defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS))
62 this->dispatch_ = 0;
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 */
74 else
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);
89 int
90 JAWS_Server::open (JAWS_Pipeline_Handler *protocol,
91 JAWS_Dispatch_Policy *policy)
93 if (policy == 0)
94 policy = &this->policy_;
96 JAWS_Data_Block *db = new JAWS_Data_Block;
97 if (db == 0)
99 ACE_DEBUG ((LM_DEBUG,
100 "(%t) JAWS_Server::open, could not create Data_Block\n"));
101 return -1;
104 // initialize data block
106 db->task (JAWS_Pipeline_Accept_Task_Singleton::instance ());
107 db->policy (policy);
108 db->io_handler (0);
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)
119 n = 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 ();
134 db->release ();
136 return 0;
139 void
140 JAWS_Server::parse_args (int argc, ACE_TCHAR *argv[])
142 int c;
143 int t = 0;
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
149 switch (c)
151 case 't':
152 t = !t;
153 break;
154 case 'p':
155 this->port_ = ACE_OS::atoi (getopt.opt_arg ());
156 break;
157 case 'c':
158 if (ACE_OS::strcmp (getopt.opt_arg (), "PER_REQUEST") == 0)
159 this->concurrency_ = 1;
160 else this->concurrency_ = 0;
161 break;
162 case 'd':
163 if (ACE_OS::strcmp (getopt.opt_arg (), "ASYNCH") == 0)
164 this->dispatch_ = 1;
165 else this->dispatch_ = 0;
166 break;
167 case 'n':
168 this->nthreads_ = ACE_OS::atoi (getopt.opt_arg ());
169 break;
170 case 'm':
171 this->maxthreads_ = ACE_OS::atoi (getopt.opt_arg ());
172 break;
173 case 'f':
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;
180 break;
181 case 'r':
182 this->ratio_ = ACE_OS::atoi (getopt.opt_arg ());
183 break;
186 #if (ACE_NTRACE != 1)
187 if (t)
188 ACE_Trace::start_tracing ();
189 else
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;