PageRenderTime 28ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/dep/acelite/ace/Proactor.cpp

https://github.com/chucho/FaceCore
C++ | 1171 lines | 887 code | 172 blank | 112 comment | 83 complexity | 524c1bb2e14ee1bbd17235d230b2f58b MD5 | raw file
  1. // $Id: Proactor.cpp 91368 2010-08-16 13:03:34Z mhengstmengel $
  2. #include "ace/config-lite.h"
  3. #include "ace/Proactor.h"
  4. #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
  5. // This only works on Win32 platforms and on Unix platforms with aio
  6. // calls.
  7. #include "ace/Auto_Ptr.h"
  8. #include "ace/Proactor_Impl.h"
  9. #include "ace/Object_Manager.h"
  10. #include "ace/Task_T.h"
  11. #if !defined (ACE_HAS_WINCE) && !defined (ACE_LACKS_ACE_SVCCONF)
  12. # include "ace/Service_Config.h"
  13. #endif /* !ACE_HAS_WINCE && !ACE_LACKS_ACE_SVCCONF */
  14. #include "ace/Task_T.h"
  15. #include "ace/Log_Msg.h"
  16. #include "ace/Framework_Component.h"
  17. #if defined (ACE_HAS_AIO_CALLS)
  18. # include "ace/POSIX_Proactor.h"
  19. # include "ace/POSIX_CB_Proactor.h"
  20. #else /* !ACE_HAS_AIO_CALLS */
  21. # include "ace/WIN32_Proactor.h"
  22. #endif /* ACE_HAS_AIO_CALLS */
  23. #if !defined (__ACE_INLINE__)
  24. #include "ace/Proactor.inl"
  25. #endif /* __ACE_INLINE__ */
  26. #include "ace/Auto_Event.h"
  27. ACE_BEGIN_VERSIONED_NAMESPACE_DECL
  28. /// Process-wide ACE_Proactor.
  29. ACE_Proactor *ACE_Proactor::proactor_ = 0;
  30. /// Controls whether the Proactor is deleted when we shut down (we can
  31. /// only delete it safely if we created it!)
  32. bool ACE_Proactor::delete_proactor_ = false;
  33. /**
  34. * @class ACE_Proactor_Timer_Handler
  35. *
  36. * @brief A Handler for timer. It helps in the management of timers
  37. * registered with the Proactor.
  38. *
  39. * This object has a thread that will wait on the earliest time
  40. * in a list of timers and an event. When a timer expires, the
  41. * thread will post a completion event on the port and go back
  42. * to waiting on the timer queue and event. If the event is
  43. * signaled, the thread will refresh the time it is currently
  44. * waiting on (in case the earliest time has changed).
  45. */
  46. class ACE_Proactor_Timer_Handler : public ACE_Task<ACE_NULL_SYNCH>
  47. {
  48. /// Proactor has special privileges
  49. /// Access needed to: timer_event_
  50. friend class ACE_Proactor;
  51. public:
  52. /// Constructor.
  53. ACE_Proactor_Timer_Handler (ACE_Proactor &proactor);
  54. /// Destructor.
  55. virtual ~ACE_Proactor_Timer_Handler (void);
  56. /// Proactor calls this to shut down the timer handler
  57. /// gracefully. Just calling the destructor alone doesnt do what
  58. /// <destroy> does. <destroy> make sure the thread exits properly.
  59. int destroy (void);
  60. protected:
  61. /// Run by a daemon thread to handle deferred processing. In other
  62. /// words, this method will do the waiting on the earliest timer and
  63. /// event.
  64. virtual int svc (void);
  65. /// Event to wait on.
  66. ACE_Auto_Event timer_event_;
  67. /// Proactor.
  68. ACE_Proactor &proactor_;
  69. /// Flag used to indicate when we are shutting down.
  70. int shutting_down_;
  71. };
  72. ACE_Proactor_Timer_Handler::ACE_Proactor_Timer_Handler (ACE_Proactor &proactor)
  73. : ACE_Task <ACE_NULL_SYNCH> (&proactor.thr_mgr_),
  74. proactor_ (proactor),
  75. shutting_down_ (0)
  76. {
  77. }
  78. ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler (void)
  79. {
  80. // Mark for closing down.
  81. this->shutting_down_ = 1;
  82. // Signal timer event.
  83. this->timer_event_.signal ();
  84. // Wait for the Timer Handler thread to exit.
  85. this->wait ();
  86. }
  87. int
  88. ACE_Proactor_Timer_Handler::svc (void)
  89. {
  90. ACE_Time_Value absolute_time;
  91. ACE_Time_Value relative_time;
  92. int result = 0;
  93. while (this->shutting_down_ == 0)
  94. {
  95. // Check whether the timer queue has any items in it.
  96. if (this->proactor_.timer_queue ()->is_empty () == 0)
  97. {
  98. // Get the earliest absolute time.
  99. absolute_time = this->proactor_.timer_queue ()->earliest_time ();
  100. // Get current time from timer queue since we don't know
  101. // which <gettimeofday> was used.
  102. ACE_Time_Value cur_time = this->proactor_.timer_queue ()->gettimeofday ();
  103. // Compare absolute time with curent time received from the
  104. // timer queue.
  105. if (absolute_time > cur_time)
  106. relative_time = absolute_time - cur_time;
  107. else
  108. relative_time = ACE_Time_Value::zero;
  109. // Block for relative time.
  110. result = this->timer_event_.wait (&relative_time, 0);
  111. }
  112. else
  113. // The timer queue has no entries, so wait indefinitely.
  114. result = this->timer_event_.wait ();
  115. // Check for timer expiries.
  116. if (result == -1)
  117. {
  118. switch (errno)
  119. {
  120. case ETIME:
  121. // timeout: expire timers
  122. this->proactor_.timer_queue ()->expire ();
  123. break;
  124. default:
  125. // Error.
  126. ACE_ERROR_RETURN ((LM_ERROR,
  127. ACE_TEXT ("%N:%l:(%P | %t):%p\n"),
  128. ACE_TEXT ("ACE_Proactor_Timer_Handler::svc:wait failed")),
  129. -1);
  130. }
  131. }
  132. }
  133. return 0;
  134. }
  135. // *********************************************************************
  136. ACE_Proactor_Handle_Timeout_Upcall::ACE_Proactor_Handle_Timeout_Upcall (void)
  137. : proactor_ (0)
  138. {
  139. }
  140. int
  141. ACE_Proactor_Handle_Timeout_Upcall::registration (TIMER_QUEUE &,
  142. ACE_Handler *,
  143. const void *)
  144. {
  145. return 0;
  146. }
  147. int
  148. ACE_Proactor_Handle_Timeout_Upcall::preinvoke (TIMER_QUEUE &,
  149. ACE_Handler *,
  150. const void *,
  151. int,
  152. const ACE_Time_Value &,
  153. const void *&)
  154. {
  155. return 0;
  156. }
  157. int
  158. ACE_Proactor_Handle_Timeout_Upcall::postinvoke (TIMER_QUEUE &,
  159. ACE_Handler *,
  160. const void *,
  161. int,
  162. const ACE_Time_Value &,
  163. const void *)
  164. {
  165. return 0;
  166. }
  167. int
  168. ACE_Proactor_Handle_Timeout_Upcall::timeout (TIMER_QUEUE &,
  169. ACE_Handler *handler,
  170. const void *act,
  171. int,
  172. const ACE_Time_Value &time)
  173. {
  174. if (this->proactor_ == 0)
  175. ACE_ERROR_RETURN ((LM_ERROR,
  176. ACE_TEXT ("(%t) No Proactor set in ACE_Proactor_Handle_Timeout_Upcall,")
  177. ACE_TEXT (" no completion port to post timeout to?!@\n")),
  178. -1);
  179. // Create the Asynch_Timer.
  180. ACE_Asynch_Result_Impl *asynch_timer =
  181. this->proactor_->create_asynch_timer (handler->proxy (),
  182. act,
  183. time,
  184. ACE_INVALID_HANDLE,
  185. 0,
  186. -1);
  187. if (asynch_timer == 0)
  188. ACE_ERROR_RETURN ((LM_ERROR,
  189. ACE_TEXT ("%N:%l:(%P | %t):%p\n"),
  190. ACE_TEXT ("ACE_Proactor_Handle_Timeout_Upcall::timeout:")
  191. ACE_TEXT ("create_asynch_timer failed")),
  192. -1);
  193. auto_ptr<ACE_Asynch_Result_Impl> safe_asynch_timer (asynch_timer);
  194. // Post a completion.
  195. if (-1 == safe_asynch_timer->post_completion
  196. (this->proactor_->implementation ()))
  197. ACE_ERROR_RETURN ((LM_ERROR,
  198. ACE_TEXT ("Failure in dealing with timers: ")
  199. ACE_TEXT ("PostQueuedCompletionStatus failed\n")),
  200. -1);
  201. // The completion has been posted. The proactor is now responsible
  202. // for managing the asynch_timer memory.
  203. (void) safe_asynch_timer.release ();
  204. return 0;
  205. }
  206. int
  207. ACE_Proactor_Handle_Timeout_Upcall::cancel_type (TIMER_QUEUE &,
  208. ACE_Handler *,
  209. int,
  210. int &)
  211. {
  212. // Do nothing
  213. return 0;
  214. }
  215. int
  216. ACE_Proactor_Handle_Timeout_Upcall::cancel_timer (TIMER_QUEUE &,
  217. ACE_Handler *,
  218. int,
  219. int)
  220. {
  221. // Do nothing
  222. return 0;
  223. }
  224. int
  225. ACE_Proactor_Handle_Timeout_Upcall::deletion (TIMER_QUEUE &,
  226. ACE_Handler *,
  227. const void *)
  228. {
  229. // Do nothing
  230. return 0;
  231. }
  232. int
  233. ACE_Proactor_Handle_Timeout_Upcall::proactor (ACE_Proactor &proactor)
  234. {
  235. if (this->proactor_ == 0)
  236. {
  237. this->proactor_ = &proactor;
  238. return 0;
  239. }
  240. else
  241. ACE_ERROR_RETURN ((LM_ERROR,
  242. ACE_TEXT ("ACE_Proactor_Handle_Timeout_Upcall is only suppose")
  243. ACE_TEXT (" to be used with ONE (and only one) Proactor\n")),
  244. -1);
  245. }
  246. // *********************************************************************
  247. ACE_Proactor::ACE_Proactor (ACE_Proactor_Impl *implementation,
  248. bool delete_implementation,
  249. TIMER_QUEUE *tq)
  250. : implementation_ (0),
  251. delete_implementation_ (delete_implementation),
  252. timer_handler_ (0),
  253. timer_queue_ (0),
  254. delete_timer_queue_ (0),
  255. end_event_loop_ (0),
  256. event_loop_thread_count_ (0)
  257. {
  258. this->implementation (implementation);
  259. if (this->implementation () == 0)
  260. {
  261. #if defined (ACE_HAS_AIO_CALLS)
  262. // POSIX Proactor.
  263. # if defined (ACE_POSIX_AIOCB_PROACTOR)
  264. ACE_NEW (implementation, ACE_POSIX_AIOCB_Proactor);
  265. # elif defined (ACE_POSIX_SIG_PROACTOR)
  266. ACE_NEW (implementation, ACE_POSIX_SIG_Proactor);
  267. # else /* Default order: CB, SIG, AIOCB */
  268. # if !defined(ACE_HAS_BROKEN_SIGEVENT_STRUCT)
  269. ACE_NEW (implementation, ACE_POSIX_CB_Proactor);
  270. # else
  271. # if defined(ACE_HAS_POSIX_REALTIME_SIGNALS)
  272. ACE_NEW (implementation, ACE_POSIX_SIG_Proactor);
  273. # else
  274. ACE_NEW (implementation, ACE_POSIX_AIOCB_Proactor);
  275. # endif /* ACE_HAS_POSIX_REALTIME_SIGNALS */
  276. # endif /* !ACE_HAS_BROKEN_SIGEVENT_STRUCT */
  277. # endif /* ACE_POSIX_AIOCB_PROACTOR */
  278. #elif (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE))
  279. // WIN_Proactor.
  280. ACE_NEW (implementation,
  281. ACE_WIN32_Proactor);
  282. #endif /* ACE_HAS_AIO_CALLS */
  283. this->implementation (implementation);
  284. this->delete_implementation_ = true;
  285. }
  286. // Set the timer queue.
  287. this->timer_queue (tq);
  288. // Create the timer handler
  289. ACE_NEW (this->timer_handler_,
  290. ACE_Proactor_Timer_Handler (*this));
  291. // Activate <timer_handler>.
  292. if (this->timer_handler_->activate () == -1)
  293. ACE_ERROR ((LM_ERROR,
  294. ACE_TEXT ("%N:%l:(%P | %t):%p\n"),
  295. ACE_TEXT ("Task::activate:could not create thread\n")));
  296. }
  297. ACE_Proactor::~ACE_Proactor (void)
  298. {
  299. this->close ();
  300. }
  301. ACE_Proactor *
  302. ACE_Proactor::instance (size_t /* threads */)
  303. {
  304. ACE_TRACE ("ACE_Proactor::instance");
  305. if (ACE_Proactor::proactor_ == 0)
  306. {
  307. // Perform Double-Checked Locking Optimization.
  308. ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
  309. *ACE_Static_Object_Lock::instance (),
  310. 0));
  311. if (ACE_Proactor::proactor_ == 0)
  312. {
  313. ACE_NEW_RETURN (ACE_Proactor::proactor_,
  314. ACE_Proactor,
  315. 0);
  316. ACE_Proactor::delete_proactor_ = true;
  317. ACE_REGISTER_FRAMEWORK_COMPONENT(ACE_Proactor, ACE_Proactor::proactor_);
  318. }
  319. }
  320. return ACE_Proactor::proactor_;
  321. }
  322. ACE_Proactor *
  323. ACE_Proactor::instance (ACE_Proactor * r, bool delete_proactor)
  324. {
  325. ACE_TRACE ("ACE_Proactor::instance");
  326. ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
  327. *ACE_Static_Object_Lock::instance (), 0));
  328. ACE_Proactor *t = ACE_Proactor::proactor_;
  329. ACE_Proactor::delete_proactor_ = delete_proactor;
  330. ACE_Proactor::proactor_ = r;
  331. ACE_REGISTER_FRAMEWORK_COMPONENT(ACE_Proactor, ACE_Proactor::proactor_);
  332. return t;
  333. }
  334. void
  335. ACE_Proactor::close_singleton (void)
  336. {
  337. ACE_TRACE ("ACE_Proactor::close_singleton");
  338. ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
  339. *ACE_Static_Object_Lock::instance ()));
  340. if (ACE_Proactor::delete_proactor_)
  341. {
  342. delete ACE_Proactor::proactor_;
  343. ACE_Proactor::proactor_ = 0;
  344. ACE_Proactor::delete_proactor_ = false;
  345. }
  346. }
  347. const ACE_TCHAR *
  348. ACE_Proactor::dll_name (void)
  349. {
  350. return ACE_TEXT ("ACE");
  351. }
  352. const ACE_TCHAR *
  353. ACE_Proactor::name (void)
  354. {
  355. return ACE_TEXT ("ACE_Proactor");
  356. }
  357. int
  358. ACE_Proactor::check_reconfiguration (ACE_Proactor *)
  359. {
  360. #if !defined (ACE_HAS_WINCE) && !defined (ACE_LACKS_ACE_SVCCONF)
  361. if (ACE_Service_Config::reconfig_occurred ())
  362. {
  363. ACE_Service_Config::reconfigure ();
  364. return 1;
  365. }
  366. #endif /* ! ACE_HAS_WINCE || ! ACE_LACKS_ACE_SVCCONF */
  367. return 0;
  368. }
  369. int
  370. ACE_Proactor::proactor_run_event_loop (PROACTOR_EVENT_HOOK eh)
  371. {
  372. ACE_TRACE ("ACE_Proactor::proactor_run_event_loop");
  373. int result = 0;
  374. {
  375. ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1));
  376. // Early check. It is ok to do this without lock, since we care just
  377. // whether it is zero or non-zero.
  378. if (this->end_event_loop_ != 0)
  379. return 0;
  380. // First time you are in. Increment the thread count.
  381. this->event_loop_thread_count_ ++;
  382. }
  383. // Run the event loop.
  384. for (;;)
  385. {
  386. // Check the end loop flag. It is ok to do this without lock,
  387. // since we care just whether it is zero or non-zero.
  388. if (this->end_event_loop_ != 0)
  389. break;
  390. // <end_event_loop> is not set. Ready to do <handle_events>.
  391. result = this->handle_events ();
  392. if (eh != 0 && (*eh) (this))
  393. continue;
  394. if (result == -1)
  395. break;
  396. }
  397. // Leaving the event loop. Decrement the thread count.
  398. {
  399. // Obtain the lock in the MT environments.
  400. ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1));
  401. // Decrement the thread count.
  402. this->event_loop_thread_count_ --;
  403. if (this->event_loop_thread_count_ > 0
  404. && this->end_event_loop_ != 0)
  405. this->proactor_post_wakeup_completions (1);
  406. }
  407. return result;
  408. }
  409. // Handle events for -tv- time. handle_events updates -tv- to reflect
  410. // time elapsed, so do not return until -tv- == 0, or an error occurs.
  411. int
  412. ACE_Proactor::proactor_run_event_loop (ACE_Time_Value &tv,
  413. PROACTOR_EVENT_HOOK eh)
  414. {
  415. ACE_TRACE ("ACE_Proactor::proactor_run_event_loop");
  416. int result = 0;
  417. {
  418. ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1));
  419. // Early check. It is ok to do this without lock, since we care just
  420. // whether it is zero or non-zero.
  421. if (this->end_event_loop_ != 0
  422. || tv == ACE_Time_Value::zero)
  423. return 0;
  424. // First time you are in. Increment the thread count.
  425. this->event_loop_thread_count_ ++;
  426. }
  427. // Run the event loop.
  428. for (;;)
  429. {
  430. // Check the end loop flag. It is ok to do this without lock,
  431. // since we care just whether it is zero or non-zero.
  432. if (this->end_event_loop_ != 0)
  433. break;
  434. // <end_event_loop> is not set. Ready to do <handle_events>.
  435. result = this->handle_events (tv);
  436. if (eh != 0 && (*eh) (this))
  437. continue;
  438. if (result == -1 || result == 0)
  439. break;
  440. }
  441. // Leaving the event loop. Decrement the thread count.
  442. {
  443. ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1));
  444. // Decrement the thread count.
  445. this->event_loop_thread_count_ --;
  446. if (this->event_loop_thread_count_ > 0
  447. && this->end_event_loop_ != 0)
  448. this->proactor_post_wakeup_completions (1);
  449. }
  450. return result;
  451. }
  452. int
  453. ACE_Proactor::proactor_reset_event_loop(void)
  454. {
  455. ACE_TRACE ("ACE_Proactor::proactor_reset_event_loop");
  456. // Obtain the lock in the MT environments.
  457. ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1));
  458. this->end_event_loop_ = 0;
  459. return 0;
  460. }
  461. int
  462. ACE_Proactor::proactor_end_event_loop (void)
  463. {
  464. ACE_TRACE ("ACE_Proactor::proactor_end_event_loop");
  465. int how_many = 0;
  466. {
  467. // Obtain the lock, set the end flag and post the wakeup
  468. // completions.
  469. ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1));
  470. // Set the end flag.
  471. this->end_event_loop_ = 1;
  472. // Number of completions to post.
  473. how_many = this->event_loop_thread_count_;
  474. if (how_many == 0)
  475. return 0;
  476. }
  477. // Post completions to all the threads so that they will all wake
  478. // up.
  479. return this->proactor_post_wakeup_completions (how_many);
  480. }
  481. int
  482. ACE_Proactor::proactor_event_loop_done (void)
  483. {
  484. ACE_TRACE ("ACE_Proactor::proactor_event_loop_done");
  485. ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1));
  486. return this->end_event_loop_ != 0 ? 1 : 0 ;
  487. }
  488. int
  489. ACE_Proactor::close (void)
  490. {
  491. // Close the implementation.
  492. if (this->implementation ()->close () == -1)
  493. ACE_ERROR ((LM_ERROR,
  494. ACE_TEXT ("%N:%l:(%P | %t):%p\n"),
  495. ACE_TEXT ("ACE_Proactor::close: implementation close")));
  496. // Delete the implementation.
  497. if (this->delete_implementation_)
  498. {
  499. delete this->implementation ();
  500. this->implementation_ = 0;
  501. }
  502. // Delete the timer handler.
  503. if (this->timer_handler_)
  504. {
  505. delete this->timer_handler_;
  506. this->timer_handler_ = 0;
  507. }
  508. // Delete the timer queue.
  509. if (this->delete_timer_queue_)
  510. {
  511. delete this->timer_queue_;
  512. this->timer_queue_ = 0;
  513. this->delete_timer_queue_ = 0;
  514. }
  515. return 0;
  516. }
  517. int
  518. ACE_Proactor::register_handle (ACE_HANDLE handle,
  519. const void *completion_key)
  520. {
  521. return this->implementation ()->register_handle (handle,
  522. completion_key);
  523. }
  524. long
  525. ACE_Proactor::schedule_timer (ACE_Handler &handler,
  526. const void *act,
  527. const ACE_Time_Value &time)
  528. {
  529. return this->schedule_timer (handler,
  530. act,
  531. time,
  532. ACE_Time_Value::zero);
  533. }
  534. long
  535. ACE_Proactor::schedule_repeating_timer (ACE_Handler &handler,
  536. const void *act,
  537. const ACE_Time_Value &interval)
  538. {
  539. return this->schedule_timer (handler,
  540. act,
  541. interval,
  542. interval);
  543. }
  544. long
  545. ACE_Proactor::schedule_timer (ACE_Handler &handler,
  546. const void *act,
  547. const ACE_Time_Value &time,
  548. const ACE_Time_Value &interval)
  549. {
  550. // absolute time.
  551. ACE_Time_Value absolute_time =
  552. this->timer_queue_->gettimeofday () + time;
  553. // Only one guy goes in here at a time
  554. ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_RECURSIVE_MUTEX,
  555. ace_mon,
  556. this->timer_queue_->mutex (),
  557. -1));
  558. // Remember the old proactor.
  559. ACE_Proactor *old_proactor = handler.proactor ();
  560. // Assign *this* Proactor to the handler.
  561. handler.proactor (this);
  562. // Schedule the timer
  563. long result = this->timer_queue_->schedule (&handler,
  564. act,
  565. absolute_time,
  566. interval);
  567. if (result != -1)
  568. {
  569. // no failures: check to see if we are the earliest time
  570. if (this->timer_queue_->earliest_time () == absolute_time)
  571. // wake up the timer thread
  572. if (this->timer_handler_->timer_event_.signal () == -1)
  573. {
  574. // Cancel timer
  575. this->timer_queue_->cancel (result);
  576. result = -1;
  577. }
  578. }
  579. if (result == -1)
  580. {
  581. // Reset the old proactor in case of failures.
  582. handler.proactor (old_proactor);
  583. }
  584. return result;
  585. }
  586. int
  587. ACE_Proactor::cancel_timer (long timer_id,
  588. const void **arg,
  589. int dont_call_handle_close)
  590. {
  591. // No need to singal timer event here. Even if the cancel timer was
  592. // the earliest, we will have an extra wakeup.
  593. return this->timer_queue_->cancel (timer_id,
  594. arg,
  595. dont_call_handle_close);
  596. }
  597. int
  598. ACE_Proactor::cancel_timer (ACE_Handler &handler,
  599. int dont_call_handle_close)
  600. {
  601. // No need to signal timer event here. Even if the cancel timer was
  602. // the earliest, we will have an extra wakeup.
  603. return this->timer_queue_->cancel (&handler,
  604. dont_call_handle_close);
  605. }
  606. int
  607. ACE_Proactor::handle_events (ACE_Time_Value &wait_time)
  608. {
  609. return implementation ()->handle_events (wait_time);
  610. }
  611. int
  612. ACE_Proactor::handle_events (void)
  613. {
  614. return this->implementation ()->handle_events ();
  615. }
  616. int
  617. ACE_Proactor::wake_up_dispatch_threads (void)
  618. {
  619. return 0;
  620. }
  621. int
  622. ACE_Proactor::close_dispatch_threads (int)
  623. {
  624. return 0;
  625. }
  626. size_t
  627. ACE_Proactor::number_of_threads (void) const
  628. {
  629. return this->implementation ()->number_of_threads ();
  630. }
  631. void
  632. ACE_Proactor::number_of_threads (size_t threads)
  633. {
  634. this->implementation ()->number_of_threads (threads);
  635. }
  636. ACE_Proactor::TIMER_QUEUE *
  637. ACE_Proactor::timer_queue (void) const
  638. {
  639. return this->timer_queue_;
  640. }
  641. void
  642. ACE_Proactor::timer_queue (TIMER_QUEUE *tq)
  643. {
  644. // Cleanup old timer queue.
  645. if (this->delete_timer_queue_)
  646. {
  647. delete this->timer_queue_;
  648. this->delete_timer_queue_ = 0;
  649. }
  650. // New timer queue.
  651. if (tq == 0)
  652. {
  653. ACE_NEW (this->timer_queue_,
  654. TIMER_HEAP);
  655. this->delete_timer_queue_ = 1;
  656. }
  657. else
  658. {
  659. this->timer_queue_ = tq;
  660. this->delete_timer_queue_ = 0;
  661. }
  662. // Set the proactor in the timer queue's functor
  663. this->timer_queue_->upcall_functor ().proactor (*this);
  664. }
  665. ACE_HANDLE
  666. ACE_Proactor::get_handle (void) const
  667. {
  668. return this->implementation ()->get_handle ();
  669. }
  670. ACE_Proactor_Impl *
  671. ACE_Proactor::implementation (void) const
  672. {
  673. return this->implementation_;
  674. }
  675. ACE_Asynch_Read_Stream_Impl *
  676. ACE_Proactor::create_asynch_read_stream (void)
  677. {
  678. return this->implementation ()->create_asynch_read_stream ();
  679. }
  680. ACE_Asynch_Write_Stream_Impl *
  681. ACE_Proactor::create_asynch_write_stream (void)
  682. {
  683. return this->implementation ()->create_asynch_write_stream ();
  684. }
  685. ACE_Asynch_Read_Dgram_Impl *
  686. ACE_Proactor::create_asynch_read_dgram (void)
  687. {
  688. return this->implementation ()->create_asynch_read_dgram ();
  689. }
  690. ACE_Asynch_Write_Dgram_Impl *
  691. ACE_Proactor::create_asynch_write_dgram (void)
  692. {
  693. return this->implementation ()->create_asynch_write_dgram ();
  694. }
  695. ACE_Asynch_Read_File_Impl *
  696. ACE_Proactor::create_asynch_read_file (void)
  697. {
  698. return this->implementation ()->create_asynch_read_file ();
  699. }
  700. ACE_Asynch_Write_File_Impl *
  701. ACE_Proactor::create_asynch_write_file (void)
  702. {
  703. return this->implementation ()->create_asynch_write_file ();
  704. }
  705. ACE_Asynch_Accept_Impl *
  706. ACE_Proactor::create_asynch_accept (void)
  707. {
  708. return this->implementation ()->create_asynch_accept ();
  709. }
  710. ACE_Asynch_Connect_Impl *
  711. ACE_Proactor::create_asynch_connect (void)
  712. {
  713. return this->implementation ()->create_asynch_connect ();
  714. }
  715. ACE_Asynch_Transmit_File_Impl *
  716. ACE_Proactor::create_asynch_transmit_file (void)
  717. {
  718. return this->implementation ()->create_asynch_transmit_file ();
  719. }
  720. ACE_Asynch_Read_Stream_Result_Impl *
  721. ACE_Proactor::create_asynch_read_stream_result
  722. (ACE_Handler::Proxy_Ptr &handler_proxy,
  723. ACE_HANDLE handle,
  724. ACE_Message_Block &message_block,
  725. u_long bytes_to_read,
  726. const void* act,
  727. ACE_HANDLE event,
  728. int priority,
  729. int signal_number)
  730. {
  731. return this->implementation ()->create_asynch_read_stream_result
  732. (handler_proxy,
  733. handle,
  734. message_block,
  735. bytes_to_read,
  736. act,
  737. event,
  738. priority,
  739. signal_number);
  740. }
  741. ACE_Asynch_Write_Stream_Result_Impl *
  742. ACE_Proactor::create_asynch_write_stream_result
  743. (ACE_Handler::Proxy_Ptr &handler_proxy,
  744. ACE_HANDLE handle,
  745. ACE_Message_Block &message_block,
  746. u_long bytes_to_write,
  747. const void* act,
  748. ACE_HANDLE event,
  749. int priority,
  750. int signal_number)
  751. {
  752. return this->implementation ()->create_asynch_write_stream_result
  753. (handler_proxy,
  754. handle,
  755. message_block,
  756. bytes_to_write,
  757. act,
  758. event,
  759. priority,
  760. signal_number);
  761. }
  762. ACE_Asynch_Read_File_Result_Impl *
  763. ACE_Proactor::create_asynch_read_file_result
  764. (ACE_Handler::Proxy_Ptr &handler_proxy,
  765. ACE_HANDLE handle,
  766. ACE_Message_Block &message_block,
  767. u_long bytes_to_read,
  768. const void* act,
  769. u_long offset,
  770. u_long offset_high,
  771. ACE_HANDLE event,
  772. int priority,
  773. int signal_number)
  774. {
  775. return this->implementation ()->create_asynch_read_file_result
  776. (handler_proxy,
  777. handle,
  778. message_block,
  779. bytes_to_read,
  780. act,
  781. offset,
  782. offset_high,
  783. event,
  784. priority,
  785. signal_number);
  786. }
  787. ACE_Asynch_Write_File_Result_Impl *
  788. ACE_Proactor::create_asynch_write_file_result
  789. (ACE_Handler::Proxy_Ptr &handler_proxy,
  790. ACE_HANDLE handle,
  791. ACE_Message_Block &message_block,
  792. u_long bytes_to_write,
  793. const void* act,
  794. u_long offset,
  795. u_long offset_high,
  796. ACE_HANDLE event,
  797. int priority,
  798. int signal_number)
  799. {
  800. return this->implementation ()->create_asynch_write_file_result
  801. (handler_proxy,
  802. handle,
  803. message_block,
  804. bytes_to_write,
  805. act,
  806. offset,
  807. offset_high,
  808. event,
  809. priority,
  810. signal_number);
  811. }
  812. ACE_Asynch_Read_Dgram_Result_Impl *
  813. ACE_Proactor::create_asynch_read_dgram_result
  814. (ACE_Handler::Proxy_Ptr &handler_proxy,
  815. ACE_HANDLE handle,
  816. ACE_Message_Block *message_block,
  817. size_t bytes_to_read,
  818. int flags,
  819. int protocol_family,
  820. const void* act,
  821. ACE_HANDLE event,
  822. int priority,
  823. int signal_number)
  824. {
  825. return this->implementation()->create_asynch_read_dgram_result
  826. (handler_proxy,
  827. handle,
  828. message_block,
  829. bytes_to_read,
  830. flags,
  831. protocol_family,
  832. act,
  833. event,
  834. priority,
  835. signal_number);
  836. }
  837. ACE_Asynch_Write_Dgram_Result_Impl *
  838. ACE_Proactor::create_asynch_write_dgram_result
  839. (ACE_Handler::Proxy_Ptr &handler_proxy,
  840. ACE_HANDLE handle,
  841. ACE_Message_Block *message_block,
  842. size_t bytes_to_write,
  843. int flags,
  844. const void* act,
  845. ACE_HANDLE event,
  846. int priority,
  847. int signal_number)
  848. {
  849. return this->implementation()->create_asynch_write_dgram_result
  850. (handler_proxy,
  851. handle,
  852. message_block,
  853. bytes_to_write,
  854. flags,
  855. act,
  856. event,
  857. priority,
  858. signal_number);
  859. }
  860. ACE_Asynch_Accept_Result_Impl *
  861. ACE_Proactor::create_asynch_accept_result
  862. (ACE_Handler::Proxy_Ptr &handler_proxy,
  863. ACE_HANDLE listen_handle,
  864. ACE_HANDLE accept_handle,
  865. ACE_Message_Block &message_block,
  866. u_long bytes_to_read,
  867. const void* act,
  868. ACE_HANDLE event,
  869. int priority,
  870. int signal_number)
  871. {
  872. return this->implementation ()->create_asynch_accept_result
  873. (handler_proxy,
  874. listen_handle,
  875. accept_handle,
  876. message_block,
  877. bytes_to_read,
  878. act,
  879. event,
  880. priority,
  881. signal_number);
  882. }
  883. ACE_Asynch_Connect_Result_Impl *
  884. ACE_Proactor::create_asynch_connect_result
  885. (ACE_Handler::Proxy_Ptr &handler_proxy,
  886. ACE_HANDLE connect_handle,
  887. const void* act,
  888. ACE_HANDLE event,
  889. int priority,
  890. int signal_number)
  891. {
  892. return this->implementation ()->create_asynch_connect_result
  893. (handler_proxy,
  894. connect_handle,
  895. act,
  896. event,
  897. priority,
  898. signal_number);
  899. }
  900. ACE_Asynch_Transmit_File_Result_Impl *
  901. ACE_Proactor::create_asynch_transmit_file_result
  902. (ACE_Handler::Proxy_Ptr &handler_proxy,
  903. ACE_HANDLE socket,
  904. ACE_HANDLE file,
  905. ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer,
  906. u_long bytes_to_write,
  907. u_long offset,
  908. u_long offset_high,
  909. u_long bytes_per_send,
  910. u_long flags,
  911. const void *act,
  912. ACE_HANDLE event,
  913. int priority,
  914. int signal_number)
  915. {
  916. return this->implementation ()->create_asynch_transmit_file_result
  917. (handler_proxy,
  918. socket,
  919. file,
  920. header_and_trailer,
  921. bytes_to_write,
  922. offset,
  923. offset_high,
  924. bytes_per_send,
  925. flags,
  926. act,
  927. event,
  928. priority,
  929. signal_number);
  930. }
  931. ACE_Asynch_Result_Impl *
  932. ACE_Proactor::create_asynch_timer
  933. (ACE_Handler::Proxy_Ptr &handler_proxy,
  934. const void *act,
  935. const ACE_Time_Value &tv,
  936. ACE_HANDLE event,
  937. int priority,
  938. int signal_number)
  939. {
  940. return this->implementation ()->create_asynch_timer
  941. (handler_proxy,
  942. act,
  943. tv,
  944. event,
  945. priority,
  946. signal_number);
  947. }
  948. int
  949. ACE_Proactor::proactor_post_wakeup_completions (int how_many)
  950. {
  951. return this->implementation ()->post_wakeup_completions (how_many);
  952. }
  953. void
  954. ACE_Proactor::implementation (ACE_Proactor_Impl *implementation)
  955. {
  956. this->implementation_ = implementation;
  957. }
  958. ACE_END_VERSIONED_NAMESPACE_DECL
  959. #else /* !ACE_WIN32 || !ACE_HAS_AIO_CALLS */
  960. ACE_BEGIN_VERSIONED_NAMESPACE_DECL
  961. ACE_Proactor *
  962. ACE_Proactor::instance (size_t /* threads */)
  963. {
  964. return 0;
  965. }
  966. ACE_Proactor *
  967. ACE_Proactor::instance (ACE_Proactor *)
  968. {
  969. return 0;
  970. }
  971. void
  972. ACE_Proactor::close_singleton (void)
  973. {
  974. }
  975. int
  976. ACE_Proactor::run_event_loop (void)
  977. {
  978. // not implemented
  979. return -1;
  980. }
  981. int
  982. ACE_Proactor::run_event_loop (ACE_Time_Value &)
  983. {
  984. // not implemented
  985. return -1;
  986. }
  987. int
  988. ACE_Proactor::end_event_loop (void)
  989. {
  990. // not implemented
  991. return -1;
  992. }
  993. sig_atomic_t
  994. ACE_Proactor::event_loop_done (void)
  995. {
  996. return sig_atomic_t (1);
  997. }
  998. ACE_END_VERSIONED_NAMESPACE_DECL
  999. #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */