diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-08-05 22:25:13 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-08-05 22:25:13 +0000 |
commit | da2fb068cb90ee2eba19fda95684bdb7ce9fef77 (patch) | |
tree | 62b7acfa099c34e48e5e2189aad1b46ca4b18cc8 /ace | |
parent | afd59c7afbdcc76a3caae53cb47094102cbe49cc (diff) | |
download | ATCD-da2fb068cb90ee2eba19fda95684bdb7ce9fef77.tar.gz |
*** empty log message ***
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Acceptor.cpp | 2 | ||||
-rw-r--r-- | ace/Strategies_T.cpp | 148 | ||||
-rw-r--r-- | ace/Svc_Handler.cpp | 7 | ||||
-rw-r--r-- | ace/Svc_Handler.h | 3 |
4 files changed, 94 insertions, 66 deletions
diff --git a/ace/Acceptor.cpp b/ace/Acceptor.cpp index 667926c3e3f..b999e160e9e 100644 --- a/ace/Acceptor.cpp +++ b/ace/Acceptor.cpp @@ -802,7 +802,7 @@ ACE_Oneshot_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::handle_timeout if (this->svc_handler_->handle_timeout (tv, arg) == -1) this->svc_handler_->handle_close (this->svc_handler_->get_handle (), - ACE_Event_Handler::TIMER_MASK);; + ACE_Event_Handler::TIMER_MASK); // Since we aren't necessarily registered with the Reactor, don't // bother to check the return value here... diff --git a/ace/Strategies_T.cpp b/ace/Strategies_T.cpp index 44b4df0eee2..43ae7cbf64d 100644 --- a/ace/Strategies_T.cpp +++ b/ace/Strategies_T.cpp @@ -1028,92 +1028,110 @@ ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX>::connect_s int flags, int perms) { - // User must not pass us svc_handlers. We will either find them a - // non-busy one, or will create them a new one. - if (sh != 0) - { - errno = EINVAL; - return -1; - } - - // Create the search key - ADDRESS search_addr (remote_addr); - CONNECTION_MAP_ENTRY *entry = 0; int found = 0; // This artificial scope is required since we need to let go of the // lock *before* registering the newly created handler with the // Reactor. { + // Create the search key + ADDRESS search_addr (remote_addr); + + CONNECTION_MAP_ENTRY *entry = 0; + // Synchronization is required here as the setting of the // recyclable bit must be done atomically with the finding and // binding of the service handler in the cache. ACE_GUARD_RETURN (MUTEX, ace_mon, this->lock_, -1); - // Try to find the address in the cache. Only if we don't find it - // do we create a new <SVC_HANDLER> and connect it with the - // server. - if (this->connection_cache_.find (search_addr, entry) == -1) + // Check if the user passed a hint svc_handler + if (sh != 0) { - // Set the flag - found = 0; - - // Create a new svc_handler - if (this->make_svc_handler (sh) == -1) - return -1; - - // Actively establish the connection. This is a timed - // blocking connect. - if (CONNECT_STRATEGY::connect_svc_handler (sh, - remote_addr, - timeout, - local_addr, - reuse_addr, - flags, - perms) == -1) + // If so, see if it is connected to the correct address and is + // recyclable + entry = (CONNECTION_MAP_ENTRY *) sh->recycling_act (); + if (entry->ext_id_ == search_addr) { - // If connect() failed because of timeouts, we have to - // reject the connection entirely. This is necessary since - // currently there is no way for the non-blocking connects - // to complete and for the <Connector> to notify the cache - // of the completion of connect(). - if (errno == EWOULDBLOCK) - errno = ENOTSUP; - return -1; + // Set the flag + found = 1; + + // Tell the <svc_handler> that it should prepare itself for + // being recycled. + this->prepare_for_recycling (sh); } - // Insert the new SVC_HANDLER instance into the cache. - else + } + + // If not found + if (!found) + { + // Try to find the address in the cache. Only if we don't + // find it do we create a new <SVC_HANDLER> and connect it + // with the server. + if (this->connection_cache_.find (search_addr, entry) == -1) { - // Create the key - ADDRESS server_addr (remote_addr); - if (this->connection_cache_.bind (server_addr, - sh, - entry) == -1) + // Set the flag + found = 0; + + // Create a new svc_handler + if (this->make_svc_handler (sh) == -1) return -1; - // Set the recycler and the recycling act - this->assign_recycler (sh, this, entry); + // Actively establish the connection. This is a timed + // blocking connect. + if (CONNECT_STRATEGY::connect_svc_handler (sh, + remote_addr, + timeout, + local_addr, + reuse_addr, + flags, + perms) == -1) + { + // If connect() failed because of timeouts, we have to + // reject the connection entirely. This is necessary + // since currently there is no way for the + // non-blocking connects to complete and for the + // <Connector> to notify the cache of the completion + // of connect(). + if (errno == EWOULDBLOCK) + errno = ENOTSUP; + return -1; + } + else + { + // + // Insert the new SVC_HANDLER instance into the cache. + // + // Create the key + ADDRESS server_addr (remote_addr); + if (this->connection_cache_.bind (server_addr, + sh, + entry) == -1) + return -1; + + // Set the recycler and the recycling act + this->assign_recycler (sh, this, entry); + } + } + else + // We found a cached svc_handler. + { + // Set the flag + found = 1; + + // Get the cached <svc_handler> + sh = entry->int_id_; + + // Tell the <svc_handler> that it should prepare itself + // for being recycled. + this->prepare_for_recycling (sh); } - } - else - // We found a cached svc_handler. - { - // Set the flag - found = 1; - - // Get the cached <svc_handler> - sh = entry->int_id_; - - // Tell the <svc_handler> that it should prepare itself for - // being recycled. - this->prepare_for_recycling (sh); } - // Mark the <svc_handler> in the cache as being <in_use>. - // Therefore recyclable is 0. - entry->ext_id_.recyclable (0); + // For all successful cases: mark the <svc_handler> in the cache + // as being <in_use>. Therefore recyclable is 0. + entry->ext_id_.recyclable (0); } - + // If it is a new connection, activate it. // // Note: This activation is outside the scope of the lock of the diff --git a/ace/Svc_Handler.cpp b/ace/Svc_Handler.cpp index 5f9e0f414f9..4cd622eeab7 100644 --- a/ace/Svc_Handler.cpp +++ b/ace/Svc_Handler.cpp @@ -258,6 +258,13 @@ ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycler (void) const return this->recycler_; } +template <PR_ST_1, ACE_SYNCH_DECL> const void * +ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycling_act (void) const +{ + ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycling_act"); + return this->recycling_act_; +} + template <PR_ST_1, ACE_SYNCH_DECL> int ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycle (void *) { diff --git a/ace/Svc_Handler.h b/ace/Svc_Handler.h index edc35c01905..02c0a616bb7 100644 --- a/ace/Svc_Handler.h +++ b/ace/Svc_Handler.h @@ -141,6 +141,9 @@ public: virtual ACE_Connection_Recycling_Strategy *recycler (void) const; // Get the recycler. + virtual const void *recycling_act (void) const; + // Get the recycling act. + virtual int recycle (void * = 0); // Upcall made by the recycler when it is about to recycle the // connection. This gives the object a chance to prepare itself for |