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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
|
// $Id$
#define ACE_BUILD_DLL
#include "ace/Proactor.h"
ACE_RCSID(ace, Proactor, "$Id$")
#if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) \
|| (defined (ACE_HAS_AIO_CALLS))
// This only works on Win32 platforms and on Unix platforms with aio
// calls.
#include "ace/Task_T.h"
#include "ace/Log_Msg.h"
#include "ace/Object_Manager.h"
#if !defined (__ACE_INLINE__)
#include "ace/Proactor.i"
#endif /* __ACE_INLINE__ */
// Process-wide ACE_Proactor.
ACE_Proactor *ACE_Proactor::proactor_ = 0;
// Controls whether the Proactor is deleted when we shut down (we can
// only delete it safely if we created it!)
int ACE_Proactor::delete_proactor_ = 0;
// Terminate the eventloop.
sig_atomic_t ACE_Proactor::end_event_loop_ = 0;
class ACE_Export ACE_Proactor_Timer_Handler : public ACE_Task <ACE_NULL_SYNCH>
// = TITLE
// A Handler for timer. It helps in the management of timers
// registered with the Proactor.
//
// = DESCRIPTION
// This object has a thread that will wait on the earliest time
// in a list of timers and an event. When a timer expires, the
// thread will post a completion event on the port and go back
// to waiting on the timer queue and event. If the event is
// signaled, the thread will refresh the time it is currently
// waiting on (in case the earliest time has changed)
{
friend class ACE_Proactor;
// Proactor has special privileges
// Access needed to: timer_event_
public:
ACE_Proactor_Timer_Handler (ACE_Proactor &proactor);
// Constructor
~ACE_Proactor_Timer_Handler (void);
// Destructor
protected:
virtual int svc (void);
// Run by a daemon thread to handle deferred processing. In other
// words, this method will do the waiting on the earliest timer and
// event.
ACE_Auto_Event timer_event_;
// Event to wait on.
ACE_Proactor &proactor_;
// Proactor.
int shutting_down_;
// Flag used to indicate when we are shutting down.
};
ACE_Proactor_Timer_Handler::ACE_Proactor_Timer_Handler (ACE_Proactor &proactor)
: ACE_Task <ACE_NULL_SYNCH> (&proactor.thr_mgr_),
proactor_ (proactor),
shutting_down_ (0)
{
}
ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler (void)
{
// Mark for closing down
this->shutting_down_ = 1;
// Signal timer event
this->timer_event_.signal ();
}
int
ACE_Proactor_Timer_Handler::svc (void)
{
#if defined (ACE_HAS_AIO_CALLS)
// @@ Alex, can you please document why this is a "no-op" for the
// AIO calls?
return 0;
#else /* ACE_HAS_AIO_CALLS */
u_long time;
ACE_Time_Value absolute_time;
while (this->shutting_down_ == 0)
{
// default value
time = ACE_INFINITE;
// If the timer queue is not empty
if (!this->proactor_.timer_queue ()->is_empty ())
{
// Get the earliest absolute time.
absolute_time
= this->proactor_.timer_queue ()->earliest_time ()
- this->proactor_.timer_queue ()->gettimeofday ();
// Time to wait.
time = absolute_time.msec ();
// Make sure the time is positive.
if (time < 0)
time = 0;
}
// Wait for event upto <time> milli seconds
int result = ::WaitForSingleObject (this->timer_event_.handle (),
time);
switch (result)
{
case ACE_WAIT_TIMEOUT:
// timeout: expire timers
this->proactor_.timer_queue ()->expire ();
break;
case ACE_WAIT_FAILED:
// error
ACE_ERROR_RETURN ((LM_ERROR,
ASYS_TEXT ("%p\n"),
ASYS_TEXT ("WaitForSingleObject")), -1);
}
}
return 0;
#endif /* ACE_HAS_AIO_CALLS */
}
ACE_Proactor_Handle_Timeout_Upcall::ACE_Proactor_Handle_Timeout_Upcall (void)
: proactor_ (0)
{
}
int
ACE_Proactor_Handle_Timeout_Upcall::timeout (TIMER_QUEUE &timer_queue,
ACE_Handler *handler,
const void *act,
const ACE_Time_Value &time)
{
ACE_UNUSED_ARG (timer_queue);
if (this->proactor_ == 0)
ACE_ERROR_RETURN ((LM_ERROR,
ASYS_TEXT ("(%t) No Proactor set in ACE_Proactor_Handle_Timeout_Upcall,")
ASYS_TEXT (" no completion port to post timeout to?!@\n")),
-1);
// Create the Asynch_Timer.
ACE_Proactor::Asynch_Timer *asynch_timer;
ACE_NEW_RETURN (asynch_timer,
ACE_Proactor::Asynch_Timer (*handler,
act,
time),
-1);
// Post a completion.
if (this->proactor_->post_completion (asynch_timer) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ASYS_TEXT ("Failure in dealing with timers: ")
ASYS_TEXT ("PostQueuedCompletionStatus failed\n")),
-1);
return 0;
}
int
ACE_Proactor_Handle_Timeout_Upcall::cancellation (TIMER_QUEUE &timer_queue,
ACE_Handler *handler)
{
ACE_UNUSED_ARG (timer_queue);
ACE_UNUSED_ARG (handler);
// Do nothing
return 0;
}
int
ACE_Proactor_Handle_Timeout_Upcall::deletion (TIMER_QUEUE &timer_queue,
ACE_Handler *handler,
const void *arg)
{
ACE_UNUSED_ARG (timer_queue);
ACE_UNUSED_ARG (handler);
ACE_UNUSED_ARG (arg);
// Do nothing
return 0;
}
int
ACE_Proactor_Handle_Timeout_Upcall::proactor (ACE_Proactor &proactor)
{
if (this->proactor_ == 0)
{
this->proactor_ = &proactor;
return 0;
}
else
ACE_ERROR_RETURN ((LM_ERROR,
ASYS_TEXT ("ACE_Proactor_Handle_Timeout_Upcall is only suppose")
ASYS_TEXT (" to be used with ONE (and only one) Proactor\n")),
-1);
}
ACE_Proactor::ACE_Proactor (size_t number_of_threads,
Timer_Queue *tq,
int used_with_reactor_event_loop)
:
#if defined (ACE_HAS_AIO_CALLS)
#if defined (_POSIX_RTSIG_MAX)
aiocb_list_max_size_ (_POSIX_RTSIG_MAX),
#else /* _POSIX_RTSIG_MAX */
// @@ Alex, please fix this to NOT use magic numbers...
aiocb_list_max_size_ (8),
#endif /* AIO_LISTIO_MAX */
aiocb_list_cur_size_ (0),
#else /* ACE_HAS_AIO_CALLS */
// This *MUST* be 0, *NOT* ACE_INVALID_HANDLE!!!!
completion_port_ (0),
#endif /* ACE_HAS_AIO_CALLS */
number_of_threads_ (number_of_threads),
timer_queue_ (0),
delete_timer_queue_ (0),
timer_handler_ (0),
used_with_reactor_event_loop_ (used_with_reactor_event_loop)
{
#if defined (ACE_HAS_AIO_CALLS)
// Initialize the array.
for (size_t ai = 0;
ai < this->aiocb_list_max_size_;
ai++)
aiocb_list_[ai] = 0;
ACE_UNUSED_ARG (tq);
ACE_DEBUG ((LM_DEBUG,
"aiocb_list: Maxsize = %d, Cursize = %d\n",
aiocb_list_max_size_,
aiocb_list_cur_size_));
#else /* ACE_HAS_AIO_CALLS */
// create the completion port
this->completion_port_ = ::CreateIoCompletionPort (INVALID_HANDLE_VALUE,
this->completion_port_,
0,
this->number_of_threads_);
if (this->completion_port_ == 0)
ACE_ERROR ((LM_ERROR,
ASYS_TEXT ("%p\n"),
ASYS_TEXT ("CreateIoCompletionPort")));
// set the timer queue
this->timer_queue (tq);
// Create the timer handler
ACE_NEW (this->timer_handler_,
ACE_Proactor_Timer_Handler (*this));
// activate <timer_handler>
if (this->timer_handler_->activate (THR_NEW_LWP | THR_DETACHED) == -1)
ACE_ERROR ((LM_ERROR,
ASYS_TEXT ("%p Could not create thread\n"),
ASYS_TEXT ("Task::activate")));
#endif /* ACE_HAS_AIO_CALLS */
}
ACE_Proactor *
ACE_Proactor::instance (size_t threads)
{
ACE_TRACE ("ACE_Proactor::instance");
if (ACE_Proactor::proactor_ == 0)
{
// Perform Double-Checked Locking Optimization.
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
*ACE_Static_Object_Lock::instance (),
0));
if (ACE_Proactor::proactor_ == 0)
{
ACE_NEW_RETURN (ACE_Proactor::proactor_,
ACE_Proactor (threads),
0);
ACE_Proactor::delete_proactor_ = 1;
}
}
return ACE_Proactor::proactor_;
}
ACE_Proactor *
ACE_Proactor::instance (ACE_Proactor *r)
{
ACE_TRACE ("ACE_Proactor::instance");
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
*ACE_Static_Object_Lock::instance (), 0));
ACE_Proactor *t = ACE_Proactor::proactor_;
// We can't safely delete it since we don't know who created it!
ACE_Proactor::delete_proactor_ = 0;
ACE_Proactor::proactor_ = r;
return t;
}
void
ACE_Proactor::close_singleton (void)
{
ACE_TRACE ("ACE_Proactor::close_singleton");
ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
*ACE_Static_Object_Lock::instance ()));
if (ACE_Proactor::delete_proactor_)
{
delete ACE_Proactor::proactor_;
ACE_Proactor::proactor_ = 0;
ACE_Proactor::delete_proactor_ = 0;
}
}
int
ACE_Proactor::run_event_loop (void)
{
ACE_TRACE ("ACE_Proactor::run_event_loop");
while (ACE_Proactor::end_event_loop_ == 0)
{
int result = ACE_Proactor::instance ()->handle_events ();
if (ACE_Service_Config::reconfig_occurred ())
ACE_Service_Config::reconfigure ();
else if (result == -1)
return -1;
}
/* NOTREACHED */
return 0;
}
// Handle events for -tv- time. handle_events updates -tv- to reflect
// time elapsed, so do not return until -tv- == 0, or an error occurs.
int
ACE_Proactor::run_event_loop (ACE_Time_Value &tv)
{
ACE_TRACE ("ACE_Proactor::run_event_loop");
while (ACE_Proactor::end_event_loop_ == 0
&& tv != ACE_Time_Value::zero)
{
int result = ACE_Proactor::instance ()->handle_events (tv);
if (ACE_Service_Config::reconfig_occurred ())
ACE_Service_Config::reconfigure ();
// An error has occurred.
else if (result == -1)
return result;
}
/* NOTREACHED */
return 0;
}
int
ACE_Proactor::end_event_loop (void)
{
ACE_TRACE ("ACE_Proactor::end_event_loop");
ACE_Proactor::end_event_loop_ = 1;
// ACE_Proactor::instance()->notify ();
return 0;
}
/* static */
int
ACE_Proactor::event_loop_done (void)
{
ACE_TRACE ("ACE_Proactor::event_loop_done");
return ACE_Proactor::end_event_loop_ != 0;
}
ACE_Proactor::~ACE_Proactor (void)
{
this->close ();
}
int
ACE_Proactor::close (void)
{
#if defined (ACE_HAS_AIO_CALLS)
// @@ Alex, shouldn't we be handling the cleanup of the timer queue
// stuff for the POSIX version of the Proactor, as well?!
return 0;
#else /* ACE_HAS_AIO_CALLS */
// Take care of the timer handler
if (this->timer_handler_)
{
delete this->timer_handler_;
this->timer_handler_ = 0;
}
// Take care of the timer queue
if (this->delete_timer_queue_)
{
delete this->timer_queue_;
this->timer_queue_ = 0;
this->delete_timer_queue_ = 0;
}
// Close the completion port
if (this->completion_port_ != 0)
{
int result = ACE_OS::close (this->completion_port_);
this->completion_port_ = 0;
return result;
}
else
return 0;
#endif /* ACE_HAS_AIO_CALLS */
}
int
ACE_Proactor::register_handle (ACE_HANDLE handle,
const void *completion_key)
{
#if defined (ACE_HAS_AIO_CALLS)
ACE_UNUSED_ARG (handle);
ACE_UNUSED_ARG (completion_key);
return 0;
#else /* ACE_HAS_AIO_CALLS */
// No locking is needed here as no state changes.
ACE_HANDLE cp = ::CreateIoCompletionPort (handle,
this->completion_port_,
(u_long) completion_key,
this->number_of_threads_);
if (cp == 0)
{
errno = ::GetLastError ();
// If errno == ERROR_INVALID_PARAMETER, then this handle was
// already registered.
if (errno != ERROR_INVALID_PARAMETER)
ACE_ERROR_RETURN ((LM_ERROR,
ASYS_TEXT ("%p\n"),
ASYS_TEXT ("CreateIoCompletionPort")), -1);
}
return 0;
#endif /* ACE_HAS_AIO_CALLS */
}
long
ACE_Proactor::schedule_timer (ACE_Handler &handler,
const void *act,
const ACE_Time_Value &time)
{
return this->schedule_timer (handler,
act,
time,
ACE_Time_Value::zero);
}
long
ACE_Proactor::schedule_repeating_timer (ACE_Handler &handler,
const void *act,
const ACE_Time_Value &interval)
{
return this->schedule_timer (handler,
act,
interval,
interval);
}
long
ACE_Proactor::schedule_timer (ACE_Handler &handler,
const void *act,
const ACE_Time_Value &time,
const ACE_Time_Value &interval)
{
// absolute time.
ACE_Time_Value absolute_time =
this->timer_queue_->gettimeofday () + time;
// Only one guy goes in here at a time
ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->timer_queue_->mutex (), -1);
// Schedule the timer
long result = this->timer_queue_->schedule (&handler,
act,
absolute_time,
interval);
if (result != -1)
{
// no failures: check to see if we are the earliest time
if (this->timer_queue_->earliest_time () == absolute_time)
// wake up the timer thread
if (this->timer_handler_->timer_event_.signal () == -1)
{
// Cancel timer
this->timer_queue_->cancel (result);
result = -1;
}
}
return result;
}
int
ACE_Proactor::cancel_timer (long timer_id,
const void **arg,
int dont_call_handle_close)
{
// No need to singal timer event here. Even if the cancel timer was
// the earliest, we will have an extra wakeup.
return this->timer_queue_->cancel (timer_id,
arg,
dont_call_handle_close);
}
int
ACE_Proactor::cancel_timer (ACE_Handler &handler,
int dont_call_handle_close)
{
// No need to signal timer event here. Even if the cancel timer was
// the earliest, we will have an extra wakeup.
return this->timer_queue_->cancel (&handler,
dont_call_handle_close);
}
int
ACE_Proactor::handle_signal (int, siginfo_t *, ucontext_t *)
{
// Perform a non-blocking "poll" for all the I/O events that have
// completed in the I/O completion queue.
ACE_Time_Value timeout (0, 0);
int result;
while ((result = this->handle_events (timeout)) == 1)
continue;
// If our handle_events failed, we'll report a failure to the
// Reactor.
return result == -1 ? -1 : 0;
}
int
ACE_Proactor::handle_close (ACE_HANDLE handle,
ACE_Reactor_Mask close_mask)
{
ACE_UNUSED_ARG (close_mask);
ACE_UNUSED_ARG (handle);
return this->close ();
}
// @@ get_handle () implementation.
ACE_HANDLE
ACE_Proactor::get_handle (void) const
{
#if defined (ACE_HAS_AIO_CALLS)
return ACE_INVALID_HANDLE;
#else /* ACE_HAS_AIO_CALLS */
if (this->used_with_reactor_event_loop_)
return this->event_.handle ();
else
return 0;
#endif /* ACE_HAS_AIO_CALLS */
}
int
ACE_Proactor::handle_events (ACE_Time_Value &wait_time)
{
// Decrement <wait_time> with the amount of time spent in the method
ACE_Countdown_Time countdown (&wait_time);
return this->handle_events (wait_time.msec ());
}
int
ACE_Proactor::handle_events (void)
{
return this->handle_events (ACE_INFINITE);
}
int
ACE_Proactor::handle_events (unsigned long milli_seconds)
{
#if defined (ACE_HAS_AIO_CALLS)
// Is there any entries in the list.
if (this->aiocb_list_cur_size_ == 0)
// No aio is pending.
return 0;
// Wait for asynch operation to complete.
timespec timeout;
timeout.tv_sec = milli_seconds;
timeout.tv_nsec = 0;
// @@ Alex, I think we want to revise this implementation so that it
// DOESN'T need to use aio_suspend, which is going to be
// non-scalable since we need to search the aiocb_list... Instead,
// we need to use the sigtimedwait(3R) in conjunction with the POSIX
// real-time signal mechanism, which should be much more scalable.
// Let's talk about how to make this work.
if (aio_suspend (this->aiocb_list_,
this->aiocb_list_max_size_,
&timeout) == -1)
// If failure is coz of timeout, then return *0* but set errno
// appropriately. This is what the WinNT proactor does.
if (errno == EAGAIN)
ACE_ERROR_RETURN ((LM_ERROR,
"(%p):aio_suspend"),
0);
else
ACE_ERROR_RETURN ((LM_ERROR,
"(%p):aio_suspend"),
-1);
// Check which aio has finished.
size_t ai;
ssize_t nbytes = 0;
for (ai = 0; ai < this->aiocb_list_max_size_; ai++)
{
if (aiocb_list_ [ai] == 0)
continue;
// Analyze error and return values.
if (aio_error (aiocb_list_[ai]) != EINPROGRESS)
{
nbytes = aio_return (aiocb_list_[ai]);
if (nbytes == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"(%p):AIO failed"),
-1);
else
{
ACE_DEBUG ((LM_DEBUG,
"An aio has finished\n"));
// This AIO is done.
break;
}
}
}
if (ai == this->aiocb_list_max_size_)
// Nothing completed.
return 0;
// Get the values for the completed aio.
// Bytes transfered is what the aio_return gives back.
size_t bytes_transferred = nbytes;
// @@
void *completion_key = 0;
// Retrive the result pointer.
ACE_Asynch_Result *asynch_result = (ACE_Asynch_Result *)
aiocb_list_[ai]->aio_sigevent.sigev_value.sival_ptr;
// Invalidate entry in the aiocb list.
delete this->aiocb_list_[ai];
this->aiocb_list_[ai] = 0;
this->aiocb_list_cur_size_--;
// Call the application code.
this->application_specific_code (asynch_result,
bytes_transferred,
1,
completion_key,
0);
return 0;
#else /* ACE_HAS_AIO_CALLS */
ACE_OVERLAPPED *overlapped = 0;
u_long bytes_transferred = 0;
u_long completion_key = 0;
// Get the next asynchronous operation that completes
BOOL result = ::GetQueuedCompletionStatus (this->completion_port_,
&bytes_transferred,
&completion_key,
&overlapped,
milli_seconds);
if (result == FALSE && overlapped == 0)
{
errno = ::GetLastError ();
if (errno == WAIT_TIMEOUT)
{
errno = ETIME;
return 0;
}
else
ACE_ERROR_RETURN ((LM_ERROR,
ASYS_TEXT ("%p\n"),
ASYS_TEXT ("GetQueuedCompletionStatus")),
-1);
}
else
{
// Narrow the result.
ACE_Asynch_Result *asynch_result = (ACE_Asynch_Result *) overlapped;
// If errors happen, grab the error.
if (result == FALSE)
errno = ::GetLastError ();
this->application_specific_code (asynch_result,
bytes_transferred,
result,
(void *) completion_key,
errno);
}
return 0;
#endif /* ACE_HAS_AIO_CALLS */
}
void
ACE_Proactor::application_specific_code (ACE_Asynch_Result *asynch_result,
u_long bytes_transferred,
int success,
const void *completion_key,
u_long error)
{
ACE_SEH_TRY
{
// Call completion hook
asynch_result->complete (bytes_transferred,
success,
(void *) completion_key,
error);
}
ACE_SEH_FINALLY
{
// This is crucial to prevent memory leaks
delete asynch_result;
}
}
int
ACE_Proactor::post_completion (ACE_Asynch_Result *result)
{
#if defined (ACE_HAS_AIO_CALLS)
ACE_UNUSED_ARG (result);
return 0;
#else /* ACE_HAS_AIO_CALLS */
// Grab the event associated with the Proactor
HANDLE handle = this->get_handle ();
// If Proactor event is valid, signal it
if (handle != ACE_INVALID_HANDLE &&
handle != 0)
ACE_OS::event_signal (&handle);
// Post a completion
if (::PostQueuedCompletionStatus (this->completion_port_, // completion port
0, // number of bytes tranferred
0, // completion key
result // overlapped
) == FALSE)
{
delete result;
ACE_ERROR_RETURN ((LM_ERROR, "Failure in dealing with timers: PostQueuedCompletionStatus failed\n"), -1);
}
return 0;
#endif /* ACE_HAS_AIO_CALLS */
}
int
ACE_Proactor::wake_up_dispatch_threads (void)
{
return 0;
}
int
ACE_Proactor::close_dispatch_threads (int)
{
return 0;
}
size_t
ACE_Proactor::number_of_threads (void) const
{
return this->number_of_threads_;
}
void
ACE_Proactor::number_of_threads (size_t threads)
{
this->number_of_threads_ = threads;
}
ACE_Proactor::Timer_Queue *
ACE_Proactor::timer_queue (void) const
{
return this->timer_queue_;
}
void
ACE_Proactor::timer_queue (Timer_Queue *tq)
{
// cleanup old timer queue
if (this->delete_timer_queue_)
{
delete this->timer_queue_;
this->delete_timer_queue_ = 0;
}
// new timer queue
if (tq == 0)
{
this->timer_queue_ = new Timer_Heap;
this->delete_timer_queue_ = 1;
}
else
{
this->timer_queue_ = tq;
this->delete_timer_queue_ = 0;
}
// Set the proactor in the timer queue's functor
this->timer_queue_->upcall_functor ().proactor (*this);
}
ACE_Proactor::Asynch_Timer::Asynch_Timer (ACE_Handler &handler,
const void *act,
const ACE_Time_Value &tv,
ACE_HANDLE event)
: ACE_Asynch_Result (handler, act, event),
time_ (tv)
{
}
void
ACE_Proactor::Asynch_Timer::complete (u_long bytes_transferred,
int success,
const void *completion_key,
u_long error)
{
ACE_UNUSED_ARG (error);
ACE_UNUSED_ARG (completion_key);
ACE_UNUSED_ARG (success);
ACE_UNUSED_ARG (bytes_transferred);
this->handler_.handle_time_out (this->time_, this->act ());
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Timer_Queue_T<ACE_Handler *,
ACE_Proactor_Handle_Timeout_Upcall,
ACE_SYNCH_RECURSIVE_MUTEX>;
template class ACE_Timer_Queue_Iterator_T<ACE_Handler *,
ACE_Proactor_Handle_Timeout_Upcall,
ACE_SYNCH_RECURSIVE_MUTEX>;
template class ACE_Timer_List_T<ACE_Handler *,
ACE_Proactor_Handle_Timeout_Upcall,
ACE_SYNCH_RECURSIVE_MUTEX>;
template class ACE_Timer_List_Iterator_T<ACE_Handler *,
ACE_Proactor_Handle_Timeout_Upcall,
ACE_SYNCH_RECURSIVE_MUTEX>;
template class ACE_Timer_Node_T<ACE_Handler *>;
template class ACE_Unbounded_Set<ACE_Timer_Node_T<ACE_Handler *> *>;
template class ACE_Unbounded_Set_Iterator<ACE_Timer_Node_T<ACE_Handler *> *>;
template class ACE_Node <ACE_Timer_Node_T<ACE_Handler *> *>;
template class ACE_Free_List<ACE_Timer_Node_T<ACE_Handler *> >;
template class ACE_Locked_Free_List<ACE_Timer_Node_T<ACE_Handler *>, ACE_Null_Mutex>;
template class ACE_Timer_Heap_T<ACE_Handler *,
ACE_Proactor_Handle_Timeout_Upcall,
ACE_SYNCH_RECURSIVE_MUTEX>;
template class ACE_Timer_Heap_Iterator_T<ACE_Handler *,
ACE_Proactor_Handle_Timeout_Upcall,
ACE_SYNCH_RECURSIVE_MUTEX>;
template class ACE_Timer_Wheel_T<ACE_Handler *,
ACE_Proactor_Handle_Timeout_Upcall,
ACE_SYNCH_RECURSIVE_MUTEX>;
template class ACE_Timer_Wheel_Iterator_T<ACE_Handler *,
ACE_Proactor_Handle_Timeout_Upcall,
ACE_SYNCH_RECURSIVE_MUTEX>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Timer_Queue_T<ACE_Handler *,\
ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX>
#pragma instantiate ACE_Timer_Queue_Iterator_T<ACE_Handler *,\
ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX>
#pragma instantiate ACE_Timer_List_T<ACE_Handler *,\
ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX>
#pragma instantiate ACE_Timer_List_Iterator_T<ACE_Handler *,\
ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX>
#pragma instantiate ACE_Timer_Heap_T<ACE_Handler *,\
ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX>
#pragma instantiate ACE_Timer_Heap_Iterator_T<ACE_Handler *,\
ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX>
#pragma instantiate ACE_Timer_Wheel_T<ACE_Handler *,
ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX>
#pragma instantiate ACE_Timer_Wheel_Iterator_T<ACE_Handler *,\
ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
#else /* ACE_WIN32 */
ACE_Proactor *
ACE_Proactor::instance (size_t threads)
{
ACE_UNUSED_ARG (threads);
return 0;
}
ACE_Proactor *
ACE_Proactor::instance (ACE_Proactor *)
{
return 0;
}
void
ACE_Proactor::close_singleton (void)
{
}
int
ACE_Proactor::run_event_loop (void)
{
// not implemented
return -1;
}
int
ACE_Proactor::run_event_loop (ACE_Time_Value &tv)
{
// not implemented
ACE_UNUSED_ARG (tv);
return -1;
}
int
ACE_Proactor::end_event_loop (void)
{
// not implemented
return -1;
}
sig_atomic_t
ACE_Proactor::event_loop_done (void)
{
return sig_atomic_t (1);
}
#endif /* ACE_WIN32 || ACE_HAS_AIO_CALLS*/
|