Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_POSIX_Asynch_Connect Class Reference

#include <POSIX_Asynch_IO.h>

Inheritance diagram for ACE_POSIX_Asynch_Connect:

Inheritance graph
[legend]
Collaboration diagram for ACE_POSIX_Asynch_Connect:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_POSIX_Asynch_Connect (ACE_POSIX_Proactor *posix_proactor)
 Constructor. More...

virtual ~ACE_POSIX_Asynch_Connect (void)
 Destructor. More...

int open (ACE_Handler &handler, 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. More...

void set_handle (ACE_HANDLE handle)
 virtual from ACE_Event_Handler. More...

int handle_input (ACE_HANDLE handle)
 virtual from ACE_Event_Handler Called when accept event comes up on <listen_hanlde>. More...

int handle_output (ACE_HANDLE handle)
 Called when output events are possible (e.g., when flow control abates or non-blocking connection completes). More...

int handle_exception (ACE_HANDLE handle)
 Called when an exceptional events occur (e.g., SIGURG). More...

int handle_close (ACE_HANDLE handle, ACE_Reactor_Mask close_mask)
 virtual from ACE_Event_Handler. More...


Private Types

typedef ACE_Map_Manager< ACE_HANDLE,
ACE_POSIX_Asynch_Connect_Result *,
ACE_SYNCH_NULL_MUTEX > 
MAP_MANAGER
typedef ACE_Map_Iterator<
ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *,
ACE_SYNCH_NULL_MUTEX > 
MAP_ITERATOR
typedef ACE_Map_Entry< ACE_HANDLE,
ACE_POSIX_Asynch_Connect_Result * > 
MAP_ENTRY

Private Methods

int connect_i (ACE_POSIX_Asynch_Connect_Result *result, const ACE_Addr &remote_sap, const ACE_Addr &local_sap, int reuse_addr)
int post_result (ACE_POSIX_Asynch_Connect_Result *result, int flg_post)
int cancel_uncompleted (int flg_notify, ACE_Handle_Set &set)
 Cancel uncompleted connect operations. More...


Private Attributes

int flg_open_
int task_lock_count_
 1 - Connect is registered in ACE_Asynch_Pseudo_Task 0 - Aceept is deregisted in ACE_Asynch_Pseudo_Task to prevent ACE_Asynch_Pseudo_Task from deletion while we make a call to the ACE_Asynch_Pseudo_Task This is extra cost !!! we could avoid them if all applications will follow the rule: Proactor should be deleted only after deletion all AsynchOperation objects connected with it. More...

MAP_MANAGER result_map_
 Map of Result pointers that correspond to all the <accept>'s pending. More...

ACE_SYNCH_MUTEX lock_
 The lock to protect the result queue which is shared. The queue is updated by main thread in the register function call and through the auxillary thread in the deregister fun. So let us mutex it. More...


Member Typedef Documentation

typedef ACE_Map_Entry<ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *> ACE_POSIX_Asynch_Connect::MAP_ENTRY [private]
 

Definition at line 908 of file POSIX_Asynch_IO.h.

typedef ACE_Map_Iterator<ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX> ACE_POSIX_Asynch_Connect::MAP_ITERATOR [private]
 

Definition at line 906 of file POSIX_Asynch_IO.h.

typedef ACE_Map_Manager<ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX> ACE_POSIX_Asynch_Connect::MAP_MANAGER [private]
 

Definition at line 904 of file POSIX_Asynch_IO.h.


Constructor & Destructor Documentation

ACE_POSIX_Asynch_Connect::ACE_POSIX_Asynch_Connect ACE_POSIX_Proactor   posix_proactor
 

Constructor.

Definition at line 1274 of file POSIX_Asynch_IO.cpp.

01275   : ACE_Asynch_Operation_Impl (),
01276     ACE_Asynch_Connect_Impl (),
01277     ACE_POSIX_Asynch_Operation (posix_proactor),
01278     flg_open_ (0),
01279     task_lock_count_ (0)
01280 {
01281 }

ACE_POSIX_Asynch_Connect::~ACE_POSIX_Asynch_Connect void    [virtual]
 

Destructor.

Definition at line 1283 of file POSIX_Asynch_IO.cpp.

References close, and ACE_Event_Handler::reactor.

01284 {
01285   this->close ();
01286   this->reactor(0); // to avoid purge_pending_notifications
01287 }


Member Function Documentation

int ACE_POSIX_Asynch_Connect::cancel void    [virtual]
 

Cancel all pending pseudo-asynchronus requests Behavior as usual AIO request

Reimplemented from ACE_POSIX_Asynch_Operation.

Definition at line 1607 of file POSIX_Asynch_IO.cpp.

References ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_SYNCH_MUTEX, ACE_TRACE, cancel_uncompleted, flg_open_, ACE_POSIX_Proactor::get_asynch_pseudo_task, ACE_POSIX_Asynch_Operation::posix_proactor, ACE_Asynch_Pseudo_Task::remove_io_handler, task_lock_count_, and ACE_Asynch_Pseudo_Task::unlock_finish.

01608 {
01609   ACE_TRACE (ACE_LIB_TEXT("ACE_POSIX_Asynch_Connect::cancel\n"));
01610 
01611   //We are not really ACE_POSIX_Asynch_Operation
01612   //so we could not call ::aiocancel ()
01613   // or just write
01614   //return ACE_POSIX_Asynch_Operation::cancel ();
01615   //We delegate real cancelation to cancel_uncompleted (1)
01616 
01617   int rc = -1 ;  // ERRORS
01618 
01619   ACE_Handle_Set set;
01620 
01621   {
01622     ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1));
01623 
01624     int num_cancelled = cancel_uncompleted (flg_open_, set);
01625 
01626     if (num_cancelled == 0)
01627        rc = 1 ;        // AIO_ALLDONE
01628     else if (num_cancelled > 0)
01629        rc = 0 ;        // AIO_CANCELED
01630 
01631     if (this->flg_open_ == 0)
01632        return rc ;
01633 
01634     this->task_lock_count_++;
01635   }
01636 
01637   ACE_Asynch_Pseudo_Task & task =
01638     this->posix_proactor ()->get_asynch_pseudo_task ();
01639 
01640   int rc_task = task.remove_io_handler (set);
01641 
01642   {
01643     ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1));
01644 
01645     this->task_lock_count_--;
01646 
01647     if (rc_task == -2 && task_lock_count_ == 0)  // task is closing
01648       task.unlock_finish ();
01649   }
01650 
01651   return rc;
01652 }

int ACE_POSIX_Asynch_Connect::cancel_uncompleted int    flg_notify,
ACE_Handle_Set   set
[private]
 

Cancel uncompleted connect operations.

  • flg_notify Indicates whether or not we should send notification about canceled accepts. If this is 0, don't send notifications about canceled connects. If 1, notify user about canceled connects according POSIX standards we should receive notifications on canceled AIO requests.

Definition at line 1577 of file POSIX_Asynch_IO.cpp.

References ACE_LIB_TEXT, ACE_TRACE, ACE_Map_Iterator::advance, ACE_Map_Entry< ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result * >::ext_id_, ACE_Map_Entry< ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result * >::int_id_, ACE_Map_Iterator_Base::next, post_result, ACE_Handle_Set::reset, result_map_, ACE_Handle_Set::set_bit, ACE_POSIX_Asynch_Result::set_bytes_transferred, ACE_POSIX_Asynch_Result::set_error, and ACE_Map_Manager< ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX >::unbind_all.

Referenced by cancel, close, and handle_close.

01579 {
01580   ACE_TRACE (ACE_LIB_TEXT("ACE_POSIX_Asynch_Connect::cancel_uncompleted\n"));
01581 
01582   int retval = 0;
01583 
01584   MAP_ITERATOR  iter (result_map_);
01585   MAP_ENTRY *   me = 0;
01586 
01587   set.reset ();
01588 
01589   for (; iter.next (me) != 0;  retval++ , iter.advance ())
01590     {
01591        ACE_HANDLE handle = me->ext_id_;
01592        ACE_POSIX_Asynch_Connect_Result* result = me->int_id_ ;
01593 
01594        set.set_bit (handle);
01595 
01596        result->set_bytes_transferred (0);
01597        result->set_error (ECANCELED);
01598        this->post_result (result, flg_notify);
01599     }
01600 
01601   result_map_.unbind_all ();
01602 
01603   return retval;
01604 }

int ACE_POSIX_Asynch_Connect::close void   
 

Close performs cancellation of all pending requests.

Definition at line 1655 of file POSIX_Asynch_IO.cpp.

References ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_SYNCH_MUTEX, ACE_TRACE, cancel_uncompleted, flg_open_, ACE_POSIX_Proactor::get_asynch_pseudo_task, ACE_POSIX_Asynch_Operation::posix_proactor, ACE_Asynch_Pseudo_Task::remove_io_handler, task_lock_count_, and ACE_Asynch_Pseudo_Task::unlock_finish.

Referenced by ~ACE_POSIX_Asynch_Connect.

01656 {
01657   ACE_TRACE (ACE_LIB_TEXT("ACE_POSIX_Asynch_Connect::close\n"));
01658 
01659   ACE_Handle_Set set ;
01660 
01661   {
01662     ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1));
01663 
01664     int num_cancelled = cancel_uncompleted (flg_open_, set);
01665 
01666     if (num_cancelled == 0 || this->flg_open_ == 0)
01667       {
01668         this->flg_open_ = 0;
01669         return 0;
01670       }
01671 
01672     this->task_lock_count_++;
01673   }
01674 
01675   ACE_Asynch_Pseudo_Task & task =
01676     this->posix_proactor ()->get_asynch_pseudo_task ();
01677 
01678   int rc_task = task.remove_io_handler (set);
01679 
01680   {
01681     ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1));
01682 
01683     this->task_lock_count_--;
01684 
01685     if (rc_task == -2 && task_lock_count_ == 0)  // task is closing
01686       task.unlock_finish ();
01687 
01688     this->flg_open_ = 0;
01689   }
01690 
01691   return 0;
01692 }

int ACE_POSIX_Asynch_Connect::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
[virtual]
 

This starts off an asynchronous connect.

  • connect_handle will be used for the connect call. If ACE_INVALID_HANDLE is specified, a new handle will be created.

Implements ACE_Asynch_Connect_Impl.

Definition at line 1338 of file POSIX_Asynch_IO.cpp.

References ACE_ERROR, ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_NEW_RETURN, ACE_SYNCH_MUTEX, ACE_TRACE, ACE_Map_Manager< ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX >::bind, ACE_POSIX_Asynch_Connect_Result::connect_handle, connect_i, ACE_Event_Handler::CONNECT_MASK, flg_open_, ACE_POSIX_Proactor::get_asynch_pseudo_task, LM_ERROR, ACE_POSIX_Asynch_Operation::posix_proactor, post_result, ACE_Event_Handler::priority, ACE_Asynch_Pseudo_Task::register_io_handler, result_map_, ACE_POSIX_Asynch_Result::set_error, task_lock_count_, ACE_Map_Manager< ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX >::unbind, and ACE_Asynch_Pseudo_Task::unlock_finish.

01345 {
01346   ACE_TRACE (ACE_LIB_TEXT("ACE_POSIX_Asynch_Connect::connect\n"));
01347 
01348   {
01349     ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1));
01350 
01351     if (this->flg_open_ == 0)
01352       ACE_ERROR_RETURN ((LM_ERROR,
01353                          ACE_LIB_TEXT("%N:%l:ACE_POSIX_Asynch_Connect::connect")
01354                          ACE_LIB_TEXT("connector was not opened before\n")),
01355                         -1);
01356 
01357     // Common code for both WIN and POSIX.
01358     // Create future Asynch_Connect_Result
01359     ACE_POSIX_Asynch_Connect_Result *result = 0;
01360     ACE_NEW_RETURN (result,
01361                     ACE_POSIX_Asynch_Connect_Result (*this->handler_,
01362                                                     connect_handle,
01363                                                     act,
01364                                                     this->posix_proactor ()->get_handle (),
01365                                                     priority,
01366                                                     signal_number),
01367                   -1);
01368 
01369     int rc = connect_i (result,
01370                         remote_sap,
01371                         local_sap,
01372                         reuse_addr);
01373 
01374     // update handle
01375     connect_handle = result->connect_handle ();
01376 
01377     if (rc != 0)
01378       return post_result (result, 1);
01379 
01380     //  Enqueue result we will wait for completion
01381 
01382     if (this->result_map_.bind (connect_handle, result) == -1)
01383       {
01384         ACE_ERROR  ((LM_ERROR,
01385                      ACE_LIB_TEXT("%N:%l:ACE_POSIX_Asynch_Connect::connect:")
01386                      ACE_LIB_TEXT("result map binding failed\n")));
01387 
01388         result->set_error (EFAULT);
01389         return post_result (result, 1);
01390       }
01391 
01392     task_lock_count_ ++;
01393   }
01394 
01395   ACE_Asynch_Pseudo_Task & task =
01396     this->posix_proactor ()->get_asynch_pseudo_task ();
01397 
01398   int rc_task = task.register_io_handler (connect_handle,
01399                                           this,
01400                                           ACE_Event_Handler::CONNECT_MASK,
01401                                           0);  // not to suspend after register
01402   {
01403     ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1));
01404 
01405     this->task_lock_count_ --;
01406 
01407     int post_enable = 1;
01408 
01409     if (rc_task == -2 && task_lock_count_ == 0)  // task is closing
01410       {
01411         post_enable = 0;
01412         task.unlock_finish ();
01413       }
01414 
01415     if (rc_task < 0)
01416       {
01417         ACE_POSIX_Asynch_Connect_Result *result = 0;
01418 
01419         this->result_map_.unbind (connect_handle, result);
01420 
01421         if (result != 0)
01422           {
01423             result->set_error (EFAULT);
01424 
01425             return post_result (result, post_enable);
01426           }
01427       }
01428   }
01429 
01430   return 0;
01431 }

int ACE_POSIX_Asynch_Connect::connect_i ACE_POSIX_Asynch_Connect_Result   result,
const ACE_Addr   remote_sap,
const ACE_Addr   local_sap,
int    reuse_addr
[private]
 

Definition at line 1464 of file POSIX_Asynch_IO.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NONBLOCK, ACE_OS::bind, ACE_OS::connect, ACE_POSIX_Asynch_Connect_Result::connect_handle, EINPROGRESS, EWOULDBLOCK, ACE_Addr::get_addr, ACE_Addr::get_size, ACE_Addr::get_type, LM_ERROR, ACE_Addr::sap_any, ACE_POSIX_Asynch_Result::set_bytes_transferred, ACE_POSIX_Asynch_Result::set_error, ACE_Flag_Manip::set_flags, ACE_OS::setsockopt, and ACE_OS::socket.

Referenced by connect.

01468 {
01469   result->set_bytes_transferred (0);
01470 
01471   ACE_HANDLE handle = result->connect_handle ();
01472 
01473   if (handle == ACE_INVALID_HANDLE)
01474     {
01475       int protocol_family = remote_sap.get_type ();
01476 
01477       handle = ACE_OS::socket (protocol_family,
01478                                SOCK_STREAM,
01479                                0);
01480       // save it
01481       result->connect_handle (handle);
01482 
01483       if (handle == ACE_INVALID_HANDLE)
01484         {
01485           result->set_error (errno);
01486 
01487           ACE_ERROR_RETURN ((LM_ERROR,
01488                        ACE_LIB_TEXT("%N:%l:ACE_POSIX_Asynch_Connect::connect_i: ")
01489                        ACE_LIB_TEXT(" ACE_OS::socket failed\n")),
01490                       -1);
01491         }
01492 
01493       // Reuse the address
01494       int one = 1;
01495       if (protocol_family != PF_UNIX  &&
01496            reuse_addr != 0 &&
01497            ACE_OS::setsockopt (handle,
01498                                SOL_SOCKET,
01499                                SO_REUSEADDR,
01500                                (const char*) &one,
01501                                sizeof one) == -1 )
01502         {
01503           result->set_error (errno);
01504 
01505           ACE_ERROR_RETURN ((LM_ERROR,
01506                        ACE_LIB_TEXT("%N:%l:ACE_POSIX_Asynch_Connect::connect_i: ")
01507                        ACE_LIB_TEXT(" ACE_OS::setsockopt failed\n")),
01508                       -1);
01509         }
01510     }
01511 
01512   if (local_sap != ACE_Addr::sap_any)
01513     {
01514       sockaddr * laddr = ACE_reinterpret_cast (sockaddr *,
01515                                                local_sap.get_addr ());
01516       size_t size = local_sap.get_size ();
01517 
01518       if (ACE_OS::bind (handle, laddr, size) == -1)
01519         {
01520            result->set_error (errno);
01521 
01522            ACE_ERROR_RETURN ((LM_ERROR,
01523                        ACE_LIB_TEXT("%N:%l:ACE_POSIX_Asynch_Connect::connect_i: ")
01524                        ACE_LIB_TEXT(" ACE_OS::bind failed\n")),
01525                       -1);
01526         }
01527     }
01528 
01529   // set non blocking mode
01530   if (ACE::set_flags (handle, ACE_NONBLOCK) != 0)
01531     {
01532       result->set_error (errno);
01533 
01534       ACE_ERROR_RETURN ((LM_ERROR,
01535                          ACE_LIB_TEXT("%N:%l:ACE_POSIX_Asynch_Connect::connect_i: ")
01536                          ACE_LIB_TEXT(" ACE::set_flags failed\n")),
01537                         -1);
01538     }
01539 
01540   for (;;)
01541     {
01542       int rc = ACE_OS::connect (handle,
01543                                 ACE_reinterpret_cast (sockaddr *,
01544                                                       remote_sap.get_addr ()),
01545                                 remote_sap.get_size ());
01546       if (rc < 0)  // failure
01547         {
01548           if (errno == EWOULDBLOCK || errno == EINPROGRESS)
01549             return 0; // connect started
01550 
01551           if (errno == EINTR)
01552              continue;
01553 
01554           result->set_error (errno);
01555         }
01556 
01557       return 1 ;  // connect finished
01558     }
01559 
01560   ACE_NOTREACHED (return 0);
01561 }

ACE_HANDLE ACE_POSIX_Asynch_Connect::get_handle void    const [virtual]
 

virtual from ACE_Event_Handler.

Reimplemented from ACE_Event_Handler.

Definition at line 1290 of file POSIX_Asynch_IO.cpp.

References ACE_ASSERT.

01291 {
01292 
01293   ACE_ASSERT (0);
01294   return  ACE_INVALID_HANDLE;
01295 }

int ACE_POSIX_Asynch_Connect::handle_close ACE_HANDLE    handle,
ACE_Reactor_Mask    close_mask
[virtual]
 

virtual from ACE_Event_Handler.

Reimplemented from ACE_Event_Handler.

Definition at line 1746 of file POSIX_Asynch_IO.cpp.

References ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_Reactor_Mask, ACE_SYNCH_MUTEX, ACE_TRACE, cancel_uncompleted, flg_open_, ACE_POSIX_Proactor::get_asynch_pseudo_task, ACE_Asynch_Pseudo_Task::is_active, ACE_Asynch_Pseudo_Task::lock_finish, ACE_POSIX_Asynch_Operation::posix_proactor, post_result, ACE_Asynch_Pseudo_Task::remove_io_handler, result_map_, ACE_POSIX_Asynch_Result::set_bytes_transferred, ACE_POSIX_Asynch_Result::set_error, task_lock_count_, and ACE_Map_Manager< ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX >::unbind.

01747 {
01748   ACE_TRACE (ACE_LIB_TEXT ("ACE_POSIX_Asynch_Connect::handle_close\n"));
01749 
01750   ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0));
01751 
01752   ACE_Asynch_Pseudo_Task &task =
01753          this->posix_proactor ()->get_asynch_pseudo_task ();
01754 
01755   if (task.is_active() == 0)  // task is closing
01756     {
01757       if (this->flg_open_ !=0)  // we are open
01758         {
01759           this->flg_open_ = 0;
01760 
01761           // it means other thread is waiting for reactor token_
01762           if (task_lock_count_ > 0)
01763             task.lock_finish ();
01764         }
01765 
01766       ACE_Handle_Set set;
01767       this->cancel_uncompleted (0, set);
01768 
01769       return 0;
01770     }
01771 
01772   // remove_io_handler() contains flag DONT_CALL
01773   // so it is save
01774   task.remove_io_handler (fd);
01775 
01776   ACE_POSIX_Asynch_Connect_Result* result = 0;
01777 
01778   if (this->result_map_.unbind (fd, result) != 0 ) // not found
01779     return -1;
01780 
01781   result->set_bytes_transferred (0);
01782   result->set_error (ECANCELED);
01783   this->post_result (result, this->flg_open_);
01784 
01785   return 0;
01786 }

int ACE_POSIX_Asynch_Connect::handle_exception ACE_HANDLE    handle [virtual]
 

Called when an exceptional events occur (e.g., SIGURG).

Reimplemented from ACE_Event_Handler.

Definition at line 1695 of file POSIX_Asynch_IO.cpp.

References ACE_LIB_TEXT, ACE_TRACE, and handle_input.

01696 {
01697   ACE_TRACE (ACE_LIB_TEXT("ACE_POSIX_Asynch_Connect::handle_exception\n"));
01698   return handle_input (fd);
01699 }

int ACE_POSIX_Asynch_Connect::handle_input ACE_HANDLE    handle [virtual]
 

virtual from ACE_Event_Handler Called when accept event comes up on <listen_hanlde>.

Reimplemented from ACE_Event_Handler.

Definition at line 1702 of file POSIX_Asynch_IO.cpp.

References ACE_LIB_TEXT, and ACE_TRACE.

Referenced by handle_exception.

01703 {
01704   ACE_TRACE (ACE_LIB_TEXT("ACE_POSIX_Asynch_Connect::handle_input\n"));
01705 
01706   return handle_input (fd);
01707 }

int ACE_POSIX_Asynch_Connect::handle_output ACE_HANDLE    handle [virtual]
 

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 1710 of file POSIX_Asynch_IO.cpp.

References ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_SYNCH_MUTEX, ACE_TRACE, ACE_OS::getsockopt, post_result, result_map_, ACE_POSIX_Asynch_Result::set_bytes_transferred, ACE_POSIX_Asynch_Result::set_error, and ACE_Map_Manager< ACE_HANDLE, ACE_POSIX_Asynch_Connect_Result *, ACE_SYNCH_NULL_MUTEX >::unbind.

01711 {
01712   ACE_TRACE (ACE_LIB_TEXT("ACE_POSIX_Asynch_Connect::handle_output\n"));
01713 
01714   ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, 0));
01715 
01716   ACE_POSIX_Asynch_Connect_Result* result = 0;
01717 
01718   if (this->result_map_.unbind (fd, result) != 0) // not found
01719     return -1;
01720 
01721   int sockerror  = 0 ;
01722   int lsockerror = sizeof sockerror;
01723 
01724   ACE_OS::getsockopt (fd,
01725                       SOL_SOCKET,
01726                       SO_ERROR,
01727                       (char*) &sockerror,
01728                       &lsockerror);
01729 
01730   result->set_bytes_transferred (0);
01731   result->set_error (sockerror);
01732   this->post_result (result, this->flg_open_);
01733 
01734   return -1;
01735 
01736   //ACE_Asynch_Pseudo_Task & task =
01737   //       this->posix_proactor()->get_asynch_pseudo_task();
01738 
01739   //task.remove_io_handler ( fd );
01740 
01741   //return 0;
01742 }

int ACE_POSIX_Asynch_Connect::open ACE_Handler   handler,
ACE_HANDLE    handle,
const void *    completion_key,
ACE_Proactor   proactor = 0
[virtual]
 

This belongs to ACE_POSIX_Asynch_Operation. We forward this call to that method. We have put this here to avoid the compiler warnings.

Reimplemented from ACE_POSIX_Asynch_Operation.

Definition at line 1304 of file POSIX_Asynch_IO.cpp.

References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_SYNCH_MUTEX, ACE_TRACE, flg_open_, LM_ERROR, and ACE_POSIX_Asynch_Operation::open.

01308 {
01309   ACE_TRACE (ACE_LIB_TEXT("ACE_POSIX_Asynch_Connect::open\n"));
01310 
01311   ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1));
01312 
01313   // if we are already opened,
01314   // we could not create a new handler without closing the previous
01315 
01316   if (this->flg_open_ != 0)
01317     ACE_ERROR_RETURN ((LM_ERROR,
01318                        ACE_LIB_TEXT("%N:%l:ACE_POSIX_Asynch_Connect::open:")
01319                        ACE_LIB_TEXT("connector already open \n")),
01320                       -1);
01321 
01322   //int result =
01323   ACE_POSIX_Asynch_Operation::open (handler,
01324                                     handle,
01325                                     completion_key,
01326                                     proactor);
01327 
01328   // Ignore result as we pass ACE_INVALID_HANDLE
01329   //if (result == -1)
01330   //  return result;
01331 
01332   this->flg_open_ = 1;
01333 
01334   return 0;
01335 }

int ACE_POSIX_Asynch_Connect::post_result ACE_POSIX_Asynch_Connect_Result   result,
int    flg_post
[private]
 

Definition at line 1433 of file POSIX_Asynch_IO.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_OS::closesocket, ACE_POSIX_Asynch_Connect_Result::connect_handle, flg_open_, LM_ERROR, ACE_POSIX_Asynch_Operation::posix_proactor, and ACE_POSIX_Proactor::post_completion.

Referenced by cancel_uncompleted, connect, handle_close, and handle_output.

01435 {
01436   if (this->flg_open_ != 0 && post_enable != 0)
01437     {
01438       if (this->posix_proactor ()->post_completion (result) == 0)
01439         return 0 ;
01440 
01441       ACE_ERROR ((LM_ERROR,
01442                   ACE_LIB_TEXT("Error:(%P | %t):%p\n"),
01443                   ACE_LIB_TEXT("ACE_POSIX_Asynch_Connect::post_result: ")
01444                   ACE_LIB_TEXT(" <post_completion> failed")));
01445     }
01446 
01447   ACE_HANDLE handle = result->connect_handle ();
01448 
01449   if (handle != ACE_INVALID_HANDLE)
01450     ACE_OS::closesocket (handle);
01451 
01452    delete result;
01453 
01454    return -1;
01455 }

void ACE_POSIX_Asynch_Connect::set_handle ACE_HANDLE    handle [virtual]
 

virtual from ACE_Event_Handler.

Reimplemented from ACE_Event_Handler.

Definition at line 1298 of file POSIX_Asynch_IO.cpp.

References ACE_ASSERT.

01299 {
01300   ACE_ASSERT (0) ;
01301 }


Member Data Documentation

int ACE_POSIX_Asynch_Connect::flg_open_ [private]
 

Definition at line 890 of file POSIX_Asynch_IO.h.

Referenced by cancel, close, connect, handle_close, open, and post_result.

ACE_SYNCH_MUTEX ACE_POSIX_Asynch_Connect::lock_ [private]
 

The lock to protect the result queue which is shared. The queue is updated by main thread in the register function call and through the auxillary thread in the deregister fun. So let us mutex it.

Definition at line 918 of file POSIX_Asynch_IO.h.

MAP_MANAGER ACE_POSIX_Asynch_Connect::result_map_ [private]
 

Map of Result pointers that correspond to all the <accept>'s pending.

Definition at line 912 of file POSIX_Asynch_IO.h.

Referenced by cancel_uncompleted, connect, handle_close, and handle_output.

int ACE_POSIX_Asynch_Connect::task_lock_count_ [private]
 

1 - Connect is registered in ACE_Asynch_Pseudo_Task 0 - Aceept is deregisted in ACE_Asynch_Pseudo_Task to prevent ACE_Asynch_Pseudo_Task from deletion while we make a call to the ACE_Asynch_Pseudo_Task This is extra cost !!! we could avoid them if all applications will follow the rule: Proactor should be deleted only after deletion all AsynchOperation objects connected with it.

Definition at line 901 of file POSIX_Asynch_IO.h.

Referenced by cancel, close, connect, and handle_close.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:52:28 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002