diff options
author | Steve Huston <shuston@riverace.com> | 2002-11-13 22:42:48 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2002-11-13 22:42:48 +0000 |
commit | 9e37f16a66812b7561fff65ee2ffd37576129b20 (patch) | |
tree | d441c46e010c9632b5909a9ca14dafc432918fce /ace | |
parent | f64e71b071042c68670c79c3b6ca5c2ea4505ac4 (diff) | |
download | ATCD-9e37f16a66812b7561fff65ee2ffd37576129b20.tar.gz |
ChangeLogTag:Wed Nov 13 17:39:41 2002 Steve Huston <shuston@riverace.com>
Diffstat (limited to 'ace')
-rw-r--r-- | ace/POSIX_Proactor.cpp | 63 | ||||
-rw-r--r-- | ace/POSIX_Proactor.h | 4 | ||||
-rw-r--r-- | ace/SUN_Proactor.cpp | 151 | ||||
-rw-r--r-- | ace/SUN_Proactor.h | 18 |
4 files changed, 75 insertions, 161 deletions
diff --git a/ace/POSIX_Proactor.cpp b/ace/POSIX_Proactor.cpp index 91785d36877..6216717f8eb 100644 --- a/ace/POSIX_Proactor.cpp +++ b/ace/POSIX_Proactor.cpp @@ -1026,13 +1026,13 @@ ACE_POSIX_AIOCB_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 ()); + return this->handle_events_i (wait_time.msec ()); } int ACE_POSIX_AIOCB_Proactor::handle_events (void) { - return this->handle_events (ACE_INFINITE); + return this->handle_events_i (ACE_INFINITE); } int @@ -1129,7 +1129,7 @@ int ACE_POSIX_AIOCB_Proactor::process_result_queue (void) } int -ACE_POSIX_AIOCB_Proactor::handle_events (u_long milli_seconds) +ACE_POSIX_AIOCB_Proactor::handle_events_i (u_long milli_seconds) { int result_suspend = 0; int retval= 0; @@ -1317,24 +1317,20 @@ ACE_POSIX_AIOCB_Proactor::start_aio (ACE_POSIX_Asynch_Result *result, ret_val = start_aio_i (result); switch (ret_val) { - case 0 : // started OK + case 0: // started OK aiocb_list_[index] = result; return 0; - case 1 : //OS AIO queue overflow + case 1: // OS AIO queue overflow num_deferred_aiocb_ ++; return 0; - default: //Invalid request, there is no point + default: // Invalid request, there is no point break; // to start it later } result_list_[index] = 0; aiocb_list_cur_size_--; - - ACE_ERROR ((LM_ERROR, - "%N:%l:(%P | %t)::%p\n", - "start_aio: Invalid request to start <aio>\n")); return -1; } @@ -1413,11 +1409,11 @@ ACE_POSIX_AIOCB_Proactor::start_aio_i (ACE_POSIX_Asynch_Result *result) this->num_started_aio_++; else // if (ret_val == -1) { - if (errno == EAGAIN) //Ok, it will be deferred AIO - ret_val = 1; + if (errno == EAGAIN || errno == ENOMEM) //Ok, it will be deferred AIO + ret_val = 1; else ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%N:%l:(%P | %t)::start_aio: aio_%s %p\n"), + ACE_LIB_TEXT ("%N:%l:(%P | %t)::start_aio_i: aio_%s %p\n"), ptype, ACE_LIB_TEXT ("queueing failed\n"))); } @@ -1514,38 +1510,38 @@ ACE_POSIX_AIOCB_Proactor::cancel_aio (ACE_HANDLE handle) size_t ai = 0; - for (ai = 0; ai < aiocb_list_max_size_; ai++) + for (ai = 0; ai < this->aiocb_list_max_size_; ai++) { - if (result_list_[ai] == 0) //skip empty slot - continue; + if (this->result_list_[ai] == 0) // Skip empty slot + continue; - if (result_list_[ai]->aio_fildes != handle) //skip not our slot - continue; + if (this->result_list_[ai]->aio_fildes != handle) // Not ours + continue; num_total++; - ACE_POSIX_Asynch_Result *asynch_result = result_list_[ai]; + ACE_POSIX_Asynch_Result *asynch_result = this->result_list_[ai]; - if (aiocb_list_ [ai] == 0) //deferred aio + if (this->aiocb_list_[ai] == 0) // Canceling a deferred operation { - num_cancelled ++; - num_deferred_aiocb_ --; + num_cancelled++; + this->num_deferred_aiocb_--; - aiocb_list_[ai] = 0; - result_list_[ai] = 0; - aiocb_list_cur_size_--; + this->aiocb_list_[ai] = 0; + this->result_list_[ai] = 0; + this->aiocb_list_cur_size_--; asynch_result->set_error (ECANCELED); asynch_result->set_bytes_transferred (0); this->putq_result (asynch_result); // we are with locked mutex_ here ! } - else //cancel started aio + else // Cancel started aio { int rc_cancel = this->cancel_aiocb (asynch_result); if (rc_cancel == 0) //notification in the future - num_cancelled ++; //it is OS responsiblity + num_cancelled++; //it is OS responsiblity } } @@ -1563,8 +1559,8 @@ ACE_POSIX_AIOCB_Proactor::cancel_aio (ACE_HANDLE handle) int ACE_POSIX_AIOCB_Proactor::cancel_aiocb (ACE_POSIX_Asynch_Result * result) { - // This new method is called from cancel_aio - // to cancel concrete running AIO request + // This method is called from cancel_aio + // to cancel a previously submitted AIO request int rc = ::aio_cancel (0, result); // Check the return value and return 0/1/2 appropriately. @@ -1572,15 +1568,8 @@ ACE_POSIX_AIOCB_Proactor::cancel_aiocb (ACE_POSIX_Asynch_Result * result) return 0; else if (rc == AIO_ALLDONE) return 1; - else if (rc == AIO_NOTCANCELED) + else // (rc == AIO_NOTCANCELED) return 2; - - ACE_ERROR_RETURN ((LM_ERROR, - "%N:%l:(%P | %t)::%p\n", - "cancel_aiocb:" - "Unexpected result from <aio_cancel>"), - -1); - } diff --git a/ace/POSIX_Proactor.h b/ace/POSIX_Proactor.h index 6eddf84e49b..cb9f4847627 100644 --- a/ace/POSIX_Proactor.h +++ b/ace/POSIX_Proactor.h @@ -422,7 +422,7 @@ protected: * before any events occur, return 0. Return 1 if a completion * dispatched. Return -1 on errors. */ - virtual int handle_events (u_long milli_seconds); + int handle_events_i (u_long milli_seconds); /// Start deferred AIO if necessary int start_deferred_aio (void); @@ -440,7 +440,7 @@ protected: virtual ssize_t allocate_aio_slot (ACE_POSIX_Asynch_Result *result); /// Initiate an aio operation. - int start_aio_i (ACE_POSIX_Asynch_Result *result); + virtual int start_aio_i (ACE_POSIX_Asynch_Result *result); /// Notify queue of "post_completed" ACE_POSIX_Asynch_Results /// called from post_completion method diff --git a/ace/SUN_Proactor.cpp b/ace/SUN_Proactor.cpp index 5a53c4f8be9..b3d374d1f12 100644 --- a/ace/SUN_Proactor.cpp +++ b/ace/SUN_Proactor.cpp @@ -38,13 +38,13 @@ ACE_SUN_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 ()); + return this->handle_events_i (&wait_time); } int ACE_SUN_Proactor::handle_events (void) { - return this->handle_events (ACE_INFINITE); + return this->handle_events_i (0); } int ACE_SUN_Proactor::wait_for_start (ACE_Time_Value * abstime) @@ -53,10 +53,10 @@ int ACE_SUN_Proactor::wait_for_start (ACE_Time_Value * abstime) ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1)); - if (num_started_aio_ != 0) // double check + if (this->num_started_aio_ != 0) // double check return 0; - return condition_.wait (abstime) ; + return this->condition_.wait (abstime); #else @@ -66,33 +66,31 @@ int ACE_SUN_Proactor::wait_for_start (ACE_Time_Value * abstime) } int -ACE_SUN_Proactor::handle_events (u_long milli_seconds) +ACE_SUN_Proactor::handle_events_i (ACE_Time_Value *delta) { int retval = 0; aio_result_t *result = 0; - if (milli_seconds == ACE_INFINITE) + if (0 == delta) { - if (num_started_aio_ == 0) - wait_for_start (0); + if (this->num_started_aio_ == 0) + this->wait_for_start (0); result = aiowait (0); } else { - struct timeval timeout; - timeout.tv_sec = milli_seconds / 1000; - timeout.tv_usec = (milli_seconds - (timeout.tv_sec * 1000)) * 1000; - - if (num_started_aio_ == 0) + if (this->num_started_aio_ == 0) { - ACE_Time_Value tv (timeout); - + // Decrement delta with the amount of time spent waiting + ACE_Countdown_Time countdown (delta); + ACE_Time_Value tv (*delta); tv += ACE_OS::gettimeofday (); - - wait_for_start (&tv); + if (this->wait_for_start (&tv) == -1) + return -1; } - result = aiowait (&timeout); + struct timeval delta_tv = *delta; + result = aiowait (&delta_tv); } if (result == 0) @@ -165,21 +163,8 @@ ACE_SUN_Proactor::get_result_status (ACE_POSIX_Asynch_Result* asynch_result, if (error_status == EINPROGRESS || op_return == AIO_INPROGRESS) return 0; // not completed - if (error_status == -1) // should never be - ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%N:%l:(%P | %t)::%p\n"), - ACE_LIB_TEXT ("ACE_SUN_Proactor::get_result_status:") - ACE_LIB_TEXT ("<aio_errno> has failed\n"))); - if (op_return < 0) - { - transfer_count = 0; // zero bytes transferred - if (error_status == 0) // nonsense - ACE_ERROR ((LM_ERROR, - "%N:%l:(%P | %t)::%p\n", - "ACE_SUN_Proactor::get_result_status:" - "<aio_return> failed\n")); - } + transfer_count = 0; // zero bytes transferred else transfer_count = ACE_static_cast (size_t, op_return); @@ -233,15 +218,15 @@ ACE_SUN_Proactor::find_completed_aio (aio_result_t *result, return asynch_result; } -// start_aio has new return codes +// start_aio_i has new return codes // 0 successful start // 1 try later, OS queue overflow // -1 invalid request and other errors int -ACE_SUN_Proactor::start_aio (ACE_POSIX_Asynch_Result *result) +ACE_SUN_Proactor::start_aio_i (ACE_POSIX_Asynch_Result *result) { - ACE_TRACE ("ACE_SUN_Proactor::start_aio"); + ACE_TRACE ("ACE_SUN_Proactor::start_aio_i"); int ret_val; const ACE_TCHAR *ptype; @@ -286,19 +271,19 @@ ACE_SUN_Proactor::start_aio (ACE_POSIX_Asynch_Result *result) if (ret_val == 0) { - num_started_aio_++; - if (num_started_aio_ == 1) // wake up condition - condition_.broadcast (); + this->num_started_aio_++; + if (this->num_started_aio_ == 1) // wake up condition + this->condition_.broadcast (); } else // if (ret_val == -1) { - if (errno == EAGAIN) //try later, it will be deferred AIO - ret_val = 1; + if (errno == EAGAIN || errno == ENOMEM) // Defer - retry this later. + ret_val = 1; else - ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%N:%l:(%P | %t)::start_aio: aio%s %p\n"), - ptype, - ACE_LIB_TEXT ("queueing failed\n"))); + ACE_ERROR ((LM_ERROR, + ACE_LIB_TEXT ("%N:%l:(%P | %t)::start_aio: aio%s %p\n"), + ptype, + ACE_LIB_TEXT ("queueing failed\n"))); } return ret_val; @@ -308,75 +293,21 @@ int ACE_SUN_Proactor::cancel_aiocb (ACE_POSIX_Asynch_Result *result) { ACE_TRACE ("ACE_SUN_Proactor::cancel_aiocb"); - int rc = ::aiocancel (& result->aio_resultp); - + int rc = ::aiocancel (&result->aio_resultp); if (rc == 0) // AIO_CANCELED - return 0; + { + // after aiocancel Sun does not notify us + // so we should send notification + // to save POSIX behavoir. + // Also we should do this for deffered aio's + + result->set_error (ECANCELED); + result->set_bytes_transferred (0); + this->putq_result (result); + return 0; + } return 2; } -int -ACE_SUN_Proactor::cancel_aio (ACE_HANDLE handle) -{ - ACE_TRACE ("ACE_SUN_Proactor::cancel_aio"); - - int num_total = 0; - int num_cancelled = 0; - - { - ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->mutex_, -1)); - - size_t ai = 0; - - for (ai = 0; ai < aiocb_list_max_size_; ai++) - { - if (result_list_[ai] == 0) //skip empty slot - continue ; - - if (result_list_[ai]->aio_fildes != handle) //skip not our slot - continue ; - - num_total++ ; - - ACE_POSIX_Asynch_Result *asynch_result = result_list_[ai]; - - int rc_cancel = 0 ; // let assume canceled - - if (aiocb_list_ [ai] == 0) //deferred aio - num_deferred_aiocb_--; - else //cancel started aio - rc_cancel = this->cancel_aiocb (asynch_result); - - if (rc_cancel == 0) - { - num_cancelled ++ ; - - aiocb_list_[ai] = 0; - result_list_[ai] = 0; - aiocb_list_cur_size_--; - - // after aiocancel Sun does not notify us - // so we should send notification - // to save POSIX behavoir. - // Also we should do this for deffered aio's - - asynch_result->set_error (ECANCELED); - asynch_result->set_bytes_transferred (0); - this->putq_result (asynch_result); - } - } - - } // release mutex_ - - - if (num_total == 0) - return 1; // ALLDONE - - if (num_cancelled == num_total) - return 0; // CANCELLED - - return 2; // NOT CANCELLED -} - #endif /* ACE_HAS_AIO_CALLS && sun */ diff --git a/ace/SUN_Proactor.h b/ace/SUN_Proactor.h index 9a08cc9e7f4..3f9ad335df4 100644 --- a/ace/SUN_Proactor.h +++ b/ace/SUN_Proactor.h @@ -82,23 +82,18 @@ protected: virtual int handle_events (ACE_Time_Value &wait_time); /** - * Dispatch a single set of events. If <milli_seconds> elapses - * before any events occur, return 0. Return 1 if a completion is - * dispatched. Return -1 on errors. - */ - virtual int handle_events (u_long milli_seconds); - - /** * Block indefinitely until at least one event is dispatched. - * Dispatch a single set of events. If <wait_time> elapses before - * any events occur, return 0. Return 1 on success i.e., when a + * Dispatch a single set of events. Return 1 on success i.e., when a * completion is dispatched, non-zero (-1) on errors and errno is * set accordingly. */ virtual int handle_events (void); - /// From ACE_POSIX_AIOCB_Proactor. - virtual int start_aio (ACE_POSIX_Asynch_Result *result); + /// Internal completion detection and dispatching. + int handle_events_i (ACE_Time_Value *delta); + + /// Initiate an aio operation. + virtual int start_aio_i (ACE_POSIX_Asynch_Result *result); /// Check AIO for completion, error and result status /// Return: 1 - AIO completed , 0 - not completed yet @@ -114,7 +109,6 @@ protected: /// From ACE_POSIX_AIOCB_Proactor. /// Attempt to cancel running request virtual int cancel_aiocb (ACE_POSIX_Asynch_Result *result); - virtual int cancel_aio (ACE_HANDLE handle); /// Specific Sun aiowait int wait_for_start (ACE_Time_Value * abstime); |