#include <WIN32_Asynch_IO.h>
Inheritance diagram for ACE_WIN32_Asynch_Connect:
Public Member Functions | |
ACE_WIN32_Asynch_Connect (ACE_WIN32_Proactor *win32_proactor) | |
Constructor. | |
virtual | ~ACE_WIN32_Asynch_Connect (void) |
Destructor. | |
int | open (const ACE_Handler::Proxy_Ptr &handler_proxy, ACE_HANDLE handle, const void *completion_key, ACE_Proactor *proactor=0) |
int | connect (ACE_HANDLE connect_handle, const ACE_Addr &remote_sap, const ACE_Addr &local_sap, int reuse_addr, const void *act, int priority, int signal_number=0) |
int | cancel (void) |
int | close (void) |
ACE_HANDLE | get_handle (void) const |
Virtual from ACE_Event_Handler. | |
void | set_handle (ACE_HANDLE handle) |
Virtual from ACE_Event_Handler. | |
int | handle_input (ACE_HANDLE handle) |
Virtual from ACE_Event_Handler. | |
int | handle_output (ACE_HANDLE handle) |
int | handle_exception (ACE_HANDLE handle) |
Called when an exceptional events occur (e.g., SIGURG). | |
int | handle_close (ACE_HANDLE handle, ACE_Reactor_Mask close_mask) |
Virtual from ACE_Event_Handler. | |
ACE_Proactor * | proactor (void) const |
Return the underlying proactor. | |
Private Types | |
typedef ACE_Map_Manager< ACE_HANDLE, ACE_WIN32_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX > | MAP_MANAGER |
Private Member Functions | |
int | connect_i (ACE_WIN32_Asynch_Connect_Result *result, const ACE_Addr &remote_sap, const ACE_Addr &local_sap, int reuse_addr) |
int | post_result (ACE_WIN32_Asynch_Connect_Result *result, bool flg_post) |
int | cancel_uncompleted (bool flg_notify, ACE_Handle_Set &set) |
Cancel uncompleted connect operations. | |
Private Attributes | |
bool | flg_open_ |
MAP_MANAGER | result_map_ |
ACE_SYNCH_MUTEX | lock_ |
|
Definition at line 1335 of file WIN32_Asynch_IO.h. |
|
Constructor.
Definition at line 2318 of file WIN32_Asynch_IO.cpp.
02319 : ACE_Asynch_Operation_Impl (), 02320 ACE_Asynch_Connect_Impl (), 02321 ACE_WIN32_Asynch_Operation (win32_proactor), 02322 flg_open_ (false) 02323 { 02324 } |
|
Destructor.
Definition at line 2326 of file WIN32_Asynch_IO.cpp. References close(), and ACE_Event_Handler::reactor().
|
|
Cancel all pending pseudo-asynchronus requests Behavior as usual AIO request Reimplemented from ACE_WIN32_Asynch_Operation. Definition at line 2628 of file WIN32_Asynch_IO.cpp. References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX, ACE_TRACE, cancel_uncompleted(), ACE_WIN32_Proactor::get_asynch_pseudo_task(), and ACE_Asynch_Pseudo_Task::remove_io_handler().
02629 { 02630 ACE_TRACE ("ACE_WIN32_Asynch_Connect::cancel"); 02631 02632 int rc = -1 ; // ERRORS 02633 02634 ACE_Handle_Set set; 02635 int num_cancelled = 0; 02636 { 02637 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1)); 02638 02639 num_cancelled = cancel_uncompleted (flg_open_, set); 02640 } 02641 if (num_cancelled == 0) 02642 rc = 1; // AIO_ALLDONE 02643 else if (num_cancelled > 0) 02644 rc = 0; // AIO_CANCELED 02645 02646 if (!this->flg_open_) 02647 return rc; 02648 02649 ACE_Asynch_Pseudo_Task & task = 02650 this->win32_proactor_->get_asynch_pseudo_task (); 02651 02652 task.remove_io_handler (set); 02653 return rc; 02654 } |
|
Cancel uncompleted connect operations.
Definition at line 2598 of file WIN32_Asynch_IO.cpp. References ACE_TRACE, post_result(), ACE_Handle_Set::reset(), ACE_Handle_Set::set_bit(), ACE_WIN32_Asynch_Result::set_bytes_transferred(), and ACE_WIN32_Asynch_Result::set_error(). Referenced by cancel(), and close().
02600 { 02601 ACE_TRACE ("ACE_WIN32_Asynch_Connect::cancel_uncompleted"); 02602 02603 int retval = 0; 02604 02605 MAP_MANAGER::ITERATOR iter (result_map_); 02606 MAP_MANAGER::ENTRY * me = 0; 02607 02608 set.reset (); 02609 02610 for (; iter.next (me) != 0; retval++, iter.advance ()) 02611 { 02612 ACE_HANDLE handle = me->ext_id_; 02613 ACE_WIN32_Asynch_Connect_Result* result = me->int_id_ ; 02614 02615 set.set_bit (handle); 02616 02617 result->set_bytes_transferred (0); 02618 result->set_error (ERROR_OPERATION_ABORTED); 02619 this->post_result (result, flg_notify); 02620 } 02621 02622 result_map_.unbind_all (); 02623 02624 return retval; 02625 } |
|
Close performs cancellation of all pending requests and close the connect handle Definition at line 2657 of file WIN32_Asynch_IO.cpp. References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX, ACE_TRACE, cancel_uncompleted(), ACE_WIN32_Proactor::get_asynch_pseudo_task(), and ACE_Asynch_Pseudo_Task::remove_io_handler(). Referenced by ~ACE_WIN32_Asynch_Connect().
02658 { 02659 ACE_TRACE ("ACE_WIN32_Asynch_Connect::close"); 02660 02661 ACE_Handle_Set set; 02662 int num_cancelled = 0; 02663 { 02664 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1)); 02665 02666 num_cancelled = cancel_uncompleted (flg_open_, set); 02667 } 02668 if (num_cancelled == 0 || this->flg_open_ == 0) 02669 { 02670 this->flg_open_ = false; 02671 return 0; 02672 } 02673 02674 ACE_Asynch_Pseudo_Task & task = 02675 this->win32_proactor_->get_asynch_pseudo_task (); 02676 02677 task.remove_io_handler (set); 02678 return 0; 02679 } |
|
Start an asynchronous connect.
Implements ACE_Asynch_Connect_Impl. Definition at line 2384 of file WIN32_Asynch_IO.cpp. References ACE_ERROR, ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_SYNCH_MUTEX, ACE_TRACE, ACE_WIN32_Asynch_Connect_Result::connect_handle(), connect_i(), ACE_WIN32_Proactor::get_asynch_pseudo_task(), LM_ERROR, post_result(), ACE_Asynch_Pseudo_Task::register_io_handler(), and ACE_WIN32_Asynch_Result::set_error().
02391 { 02392 ACE_TRACE ("ACE_WIN32_Asynch_Connect::connect"); 02393 02394 if (!this->flg_open_) 02395 ACE_ERROR_RETURN ((LM_ERROR, 02396 ACE_LIB_TEXT ("%N:%l:ACE_WIN32_Asynch_Connect::connect") 02397 ACE_LIB_TEXT ("connector was not opened before\n")), 02398 -1); 02399 02400 // Common code for both WIN and WIN32. 02401 // Create future Asynch_Connect_Result 02402 ACE_WIN32_Asynch_Connect_Result *result = 0; 02403 ACE_NEW_RETURN (result, 02404 ACE_WIN32_Asynch_Connect_Result (this->handler_proxy_, 02405 connect_handle, 02406 act, 02407 this->win32_proactor_->get_handle (), 02408 priority, 02409 signal_number), 02410 -1); 02411 02412 int rc = connect_i (result, 02413 remote_sap, 02414 local_sap, 02415 reuse_addr); 02416 02417 // update handle 02418 connect_handle = result->connect_handle (); 02419 02420 if (rc != 0) 02421 return post_result (result, true); 02422 02423 // Enqueue result we will wait for completion 02424 { 02425 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1)); 02426 02427 if (this->result_map_.bind (connect_handle, result) == -1) 02428 { 02429 ACE_ERROR ((LM_ERROR, 02430 ACE_LIB_TEXT ("ACE_WIN32_Asynch_Connect::connect: %p\n"), 02431 ACE_LIB_TEXT ("bind"))); 02432 result->set_error (EFAULT); 02433 return post_result (result, true); 02434 } 02435 } 02436 02437 ACE_Asynch_Pseudo_Task & task = 02438 this->win32_proactor_->get_asynch_pseudo_task (); 02439 02440 if (-1 == task.register_io_handler (connect_handle, 02441 this, 02442 ACE_Event_Handler::CONNECT_MASK, 02443 0)) // not to suspend after register 02444 { 02445 result = 0; 02446 { 02447 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1)); 02448 this->result_map_.unbind (connect_handle, result); 02449 } 02450 if (result != 0) 02451 { 02452 result->set_error (EFAULT); 02453 this->post_result (result, true); 02454 } 02455 } 02456 02457 return 0; 02458 } |
|
Definition at line 2491 of file WIN32_Asynch_IO.cpp. References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NONBLOCK, ACE_OS::bind(), ACE_WIN32_Asynch_Connect_Result::connect_handle(), EINPROGRESS, EWOULDBLOCK, ACE_Addr::get_addr(), ACE_Addr::get_size(), ACE_Addr::get_type(), LM_ERROR, ACE_WIN32_Asynch_Result::set_bytes_transferred(), ACE_WIN32_Asynch_Result::set_error(), ACE::set_flags(), ACE_OS::setsockopt(), and ACE_OS::socket(). Referenced by connect().
02495 { 02496 result->set_bytes_transferred (0); 02497 02498 ACE_HANDLE handle = result->connect_handle (); 02499 if (handle == ACE_INVALID_HANDLE) 02500 { 02501 int protocol_family = remote_sap.get_type (); 02502 handle = ACE_OS::socket (protocol_family, 02503 SOCK_STREAM, 02504 0); 02505 02506 // save it 02507 result->connect_handle (handle); 02508 if (handle == ACE_INVALID_HANDLE) 02509 { 02510 result->set_error (errno); 02511 ACE_ERROR_RETURN 02512 ((LM_ERROR, 02513 ACE_LIB_TEXT ("ACE_WIN32_Asynch_Connect::connect_i: %p\n"), 02514 ACE_LIB_TEXT ("socket")), 02515 -1); 02516 } 02517 02518 // Reuse the address 02519 int one = 1; 02520 if (protocol_family != PF_UNIX && 02521 reuse_addr != 0 && 02522 ACE_OS::setsockopt (handle, 02523 SOL_SOCKET, 02524 SO_REUSEADDR, 02525 (const char*) &one, 02526 sizeof one) == -1) 02527 { 02528 result->set_error (errno); 02529 ACE_ERROR_RETURN 02530 ((LM_ERROR, 02531 ACE_LIB_TEXT ("ACE_WIN32_Asynch_Connect::connect_i: %p\n"), 02532 ACE_LIB_TEXT ("setsockopt")), 02533 -1); 02534 } 02535 } 02536 02537 if (local_sap != ACE_Addr::sap_any) 02538 { 02539 sockaddr * laddr = reinterpret_cast<sockaddr *> (local_sap.get_addr ()); 02540 int size = local_sap.get_size (); 02541 if (ACE_OS::bind (handle, laddr, size) == -1) 02542 { 02543 result->set_error (errno); 02544 ACE_ERROR_RETURN 02545 ((LM_ERROR, 02546 ACE_LIB_TEXT ("ACE_WIN32_Asynch_Connect::connect_i: %p\n"), 02547 ACE_LIB_TEXT ("bind")), 02548 -1); 02549 } 02550 } 02551 02552 // set non blocking mode 02553 if (ACE::set_flags (handle, ACE_NONBLOCK) != 0) 02554 { 02555 result->set_error (errno); 02556 ACE_ERROR_RETURN 02557 ((LM_ERROR, 02558 ACE_LIB_TEXT ("ACE_WIN32_Asynch_Connect::connect_i: %p\n"), 02559 ACE_LIB_TEXT ("set_flags")), 02560 -1); 02561 } 02562 02563 for (;;) 02564 { 02565 int rc = ACE_OS::connect 02566 (handle, 02567 reinterpret_cast<sockaddr *> (remote_sap.get_addr ()), 02568 remote_sap.get_size ()); 02569 02570 if (rc < 0) // failure 02571 { 02572 if (errno == EWOULDBLOCK || errno == EINPROGRESS) 02573 return 0; // connect started 02574 02575 if (errno == EINTR) 02576 continue; 02577 02578 result->set_error (errno); 02579 } 02580 return 1 ; // connect finished 02581 } 02582 } |
|
Virtual from ACE_Event_Handler.
Reimplemented from ACE_Event_Handler. Definition at line 2339 of file WIN32_Asynch_IO.cpp. References ACE_ASSERT.
02340 { 02341 02342 ACE_ASSERT (0); 02343 return ACE_INVALID_HANDLE; 02344 } |
|
Virtual from ACE_Event_Handler.
Reimplemented from ACE_Event_Handler. Definition at line 2732 of file WIN32_Asynch_IO.cpp. References ACE_GUARD_RETURN, ACE_Reactor_Mask, ACE_SYNCH_MUTEX, ACE_TRACE, ACE_WIN32_Proactor::get_asynch_pseudo_task(), post_result(), ACE_Asynch_Pseudo_Task::remove_io_handler(), ACE_WIN32_Asynch_Result::set_bytes_transferred(), and ACE_WIN32_Asynch_Result::set_error().
02733 { 02734 ACE_TRACE ("ACE_WIN32_Asynch_Connect::handle_close"); 02735 02736 ACE_Asynch_Pseudo_Task & task = 02737 this->win32_proactor_->get_asynch_pseudo_task (); 02738 task.remove_io_handler (fd); 02739 02740 ACE_WIN32_Asynch_Connect_Result* result = 0; 02741 02742 { 02743 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0)); 02744 if (this->result_map_.unbind (fd, result) != 0) // not found 02745 return -1; 02746 } 02747 02748 result->set_bytes_transferred (0); 02749 result->set_error (ERROR_OPERATION_ABORTED); 02750 this->post_result (result, this->flg_open_); 02751 02752 return 0; 02753 } |
|
Called when an exceptional events occur (e.g., SIGURG).
Reimplemented from ACE_Event_Handler. Definition at line 2682 of file WIN32_Asynch_IO.cpp. References ACE_TRACE, and handle_output().
02683 { 02684 ACE_TRACE ("ACE_WIN32_Asynch_Connect::handle_exception"); 02685 return handle_output (fd); 02686 } |
|
Virtual from ACE_Event_Handler.
Reimplemented from ACE_Event_Handler. Definition at line 2689 of file WIN32_Asynch_IO.cpp. References ACE_TRACE, and handle_output().
02690 { 02691 ACE_TRACE ("ACE_WIN32_Asynch_Connect::handle_input"); 02692 return handle_output (fd); 02693 } |
|
Called when output events are possible (e.g., when flow control abates or non-blocking connection completes). Reimplemented from ACE_Event_Handler. Definition at line 2696 of file WIN32_Asynch_IO.cpp. References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX, ACE_TRACE, ACE_WIN32_Proactor::get_asynch_pseudo_task(), ACE_OS::getsockopt(), post_result(), ACE_Asynch_Pseudo_Task::remove_io_handler(), ACE_WIN32_Asynch_Result::set_bytes_transferred(), and ACE_WIN32_Asynch_Result::set_error(). Referenced by handle_exception(), and handle_input().
02697 { 02698 ACE_TRACE ("ACE_WIN32_Asynch_Connect::handle_output"); 02699 02700 ACE_WIN32_Asynch_Connect_Result* result = 0; 02701 02702 { 02703 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0)); 02704 if (this->result_map_.unbind (fd, result) != 0) // not found 02705 return -1; 02706 } 02707 02708 int sockerror = 0 ; 02709 int lsockerror = sizeof sockerror; 02710 02711 ACE_OS::getsockopt (fd, 02712 SOL_SOCKET, 02713 SO_ERROR, 02714 (char*) & sockerror, 02715 & lsockerror); 02716 02717 // This previously just did a "return -1" and let handle_close() clean 02718 // things up. However, this entire object may be gone as a result of 02719 // the application's completion handler, so don't count on 'this' being 02720 // legitimate on return from post_result(). 02721 // remove_io_handler() contains flag DONT_CALL 02722 this->win32_proactor_->get_asynch_pseudo_task().remove_io_handler (fd); 02723 02724 result->set_bytes_transferred (0); 02725 result->set_error (sockerror); 02726 this->post_result (result, this->flg_open_); 02727 return 0; 02728 } |
|
This open belongs to ACE_WIN32_Asynch_Operation. We forward this call to that method. We have put this here to avoid the compiler warnings. Reimplemented from ACE_WIN32_Asynch_Operation. Definition at line 2353 of file WIN32_Asynch_IO.cpp. References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, ACE_WIN32_Asynch_Operation::open(), and ACE_Handler::Proxy_Ptr.
02357 { 02358 ACE_TRACE ("ACE_WIN32_Asynch_Connect::open"); 02359 02360 // if we are already opened, 02361 // we could not create a new handler without closing the previous 02362 if (this->flg_open_) 02363 ACE_ERROR_RETURN ((LM_ERROR, 02364 ACE_LIB_TEXT ("%N:%l:ACE_WIN32_Asynch_Connect::open:") 02365 ACE_LIB_TEXT ("connector already open \n")), 02366 -1); 02367 02368 //int result = 02369 ACE_WIN32_Asynch_Operation::open (handler_proxy, 02370 ACE_INVALID_HANDLE, 02371 completion_key, 02372 proactor); 02373 02374 // Ignore result as we pass ACE_INVALID_HANDLE 02375 //if (result == -1) 02376 // return result; 02377 02378 this->flg_open_ = true; 02379 02380 return 0; 02381 } |
|
Definition at line 2460 of file WIN32_Asynch_IO.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_OS::closesocket(), ACE_WIN32_Asynch_Connect_Result::connect_handle(), LM_ERROR, and ACE_WIN32_Proactor::post_completion(). Referenced by cancel_uncompleted(), connect(), handle_close(), and handle_output().
02462 { 02463 if (this->flg_open_ && post_enable) 02464 { 02465 if (this->win32_proactor_ ->post_completion (result) == 0) 02466 return 0; 02467 02468 ACE_ERROR ((LM_ERROR, 02469 ACE_LIB_TEXT ("Error:(%P | %t):%p\n"), 02470 ACE_LIB_TEXT ("ACE_WIN32_Asynch_Connect::post_result: ") 02471 ACE_LIB_TEXT (" <post_completion> failed"))); 02472 } 02473 02474 ACE_HANDLE handle = result->connect_handle (); 02475 02476 if (handle != ACE_INVALID_HANDLE) 02477 ACE_OS::closesocket (handle); 02478 02479 delete result; 02480 02481 return -1; 02482 } |
|
Return the underlying proactor.
Reimplemented from ACE_WIN32_Asynch_Operation. Definition at line 2333 of file WIN32_Asynch_IO.cpp. References ACE_WIN32_Asynch_Operation::proactor().
02334 { 02335 return ACE_WIN32_Asynch_Operation::proactor (); 02336 } |
|
Virtual from ACE_Event_Handler.
Reimplemented from ACE_Event_Handler. Definition at line 2347 of file WIN32_Asynch_IO.cpp. References ACE_ASSERT.
02348 { 02349 ACE_ASSERT (0) ; 02350 } |
|
true - Connect is registered in ACE_Asynch_Pseudo_Task false - Accept is deregisted in ACE_Asynch_Pseudo_Task Definition at line 1332 of file WIN32_Asynch_IO.h. |
|
The lock to protect the result map which is shared. The queue is updated by main thread in the register function call and through the auxillary thread in the asynch pseudo task. Definition at line 1344 of file WIN32_Asynch_IO.h. |
|
Map of Result pointers that correspond to all the 's pending. Definition at line 1339 of file WIN32_Asynch_IO.h. |