*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
This commit is contained in:
@@ -1,68 +1,89 @@
|
||||
// $Id: Remote_Tokens.cpp 80826 2008-03-04 14:51:23Z wotte $
|
||||
|
||||
#include "ace/Remote_Tokens.h"
|
||||
|
||||
#if defined (ACE_HAS_TOKENS_LIBRARY)
|
||||
|
||||
#include "ace/Singleton.h"
|
||||
|
||||
#if !defined (__ACE_INLINE__)
|
||||
#include "ace/Remote_Tokens.inl"
|
||||
#endif /* __ACE_INLINE__ */
|
||||
|
||||
|
||||
ACE_RCSID (ace,
|
||||
Remote_Tokens,
|
||||
"$Id: Remote_Tokens.cpp 80826 2008-03-04 14:51:23Z wotte $")
|
||||
|
||||
|
||||
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
|
||||
#define ACE_TSS_CONNECTION_MUTEX ACE_Thread_Mutex
|
||||
#else
|
||||
#define ACE_TSS_CONNECTION_MUTEX ACE_Null_Mutex
|
||||
#endif /* ACE_MT_SAFE */
|
||||
|
||||
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
// Make a typedef to simplify access to the Singleton below.
|
||||
typedef ACE_Singleton<ACE_TSS_Connection, ACE_TSS_CONNECTION_MUTEX> ACE_Token_Connections;
|
||||
|
||||
// Initialize the statics from ACE_TSS_Connection;
|
||||
ACE_INET_Addr ACE_TSS_Connection::server_address_;
|
||||
|
||||
// ************************************************************
|
||||
|
||||
void
|
||||
ACE_TSS_Connection::set_server_address (const ACE_INET_Addr &server_address)
|
||||
{
|
||||
ACE_TRACE ("ACE_TSS_Connection::set_server_address");
|
||||
server_address_ = server_address;
|
||||
}
|
||||
|
||||
// Necessary to make some compilers work...
|
||||
ACE_TSS_Connection::ACE_TSS_Connection (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_TSS_Connection::ACE_TSS_Connection");
|
||||
}
|
||||
|
||||
ACE_TSS_Connection::~ACE_TSS_Connection (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_TSS_Connection::~ACE_TSS_Connection");
|
||||
}
|
||||
|
||||
ACE_SOCK_Stream *
|
||||
ACE_TSS_Connection::get_connection (void)
|
||||
{
|
||||
return ACE_TSS<ACE_SOCK_Stream>::operator-> ();
|
||||
}
|
||||
|
||||
ACE_SOCK_Stream *
|
||||
ACE_TSS_Connection::make_TSS_TYPE (void) const
|
||||
{
|
||||
ACE_TRACE ("ACE_TSS_Connection::make_TSS_TYPE");
|
||||
|
||||
ACE_SOCK_Connector connector;
|
||||
ACE_SOCK_Stream *stream = 0;
|
||||
|
||||
ACE_NEW_RETURN (stream,
|
||||
ACE_SOCK_Stream,
|
||||
0);
|
||||
|
||||
if (connector.connect (*stream, server_address_) == -1)
|
||||
{
|
||||
delete stream;
|
||||
errno = ECONNREFUSED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE_TSS_Connection new connection\n")));
|
||||
return stream;
|
||||
}
|
||||
|
||||
ACE_TSS_Connection::operator ACE_SOCK_Stream *(void)
|
||||
{
|
||||
return this->get_connection ();
|
||||
}
|
||||
|
||||
void
|
||||
ACE_TSS_Connection::dump (void) const
|
||||
{
|
||||
@@ -77,14 +98,17 @@ ACE_TSS_Connection::dump (void) const
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
|
||||
#endif /* ACE_HAS_DUMP */
|
||||
}
|
||||
|
||||
ACE_Remote_Token_Proxy::ACE_Remote_Token_Proxy (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_Remote_Token_Proxy::ACE_Remote_Token_Proxy");
|
||||
}
|
||||
|
||||
ACE_Remote_Token_Proxy::~ACE_Remote_Token_Proxy (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_Remote_Token_Proxy::~ACE_Remote_Token_Proxy");
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Remote_Token_Proxy::open (const ACE_TCHAR *name,
|
||||
int ignore_deadlock,
|
||||
@@ -94,12 +118,14 @@ ACE_Remote_Token_Proxy::open (const ACE_TCHAR *name,
|
||||
ignore_shadow_deadlock_ = ignore_deadlock;
|
||||
return ACE_Token_Proxy::open (name, 0, debug);
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Remote_Token_Proxy::set_server_address (const ACE_INET_Addr &server_address)
|
||||
{
|
||||
ACE_TRACE ("ACE_Remote_Token_Proxy::set_server_address");
|
||||
ACE_Token_Connections::instance ()->set_server_address (server_address);
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Remote_Token_Proxy::initiate_connection (void)
|
||||
{
|
||||
@@ -110,10 +136,13 @@ ACE_Remote_Token_Proxy::initiate_connection (void)
|
||||
ACE_ERROR_RETURN ((LM_ERROR,
|
||||
ACE_TEXT ("ACE_Remote_Token_Proxy not open.\n")), -1);
|
||||
}
|
||||
|
||||
ACE_SOCK_Stream *peer = ACE_Token_Connections::instance ()->get_connection ();
|
||||
return peer == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
// Do the work of sending a request and getting a reply.
|
||||
|
||||
int
|
||||
ACE_Remote_Token_Proxy::request_reply (ACE_Token_Request &request,
|
||||
ACE_Synch_Options &)
|
||||
@@ -121,22 +150,31 @@ ACE_Remote_Token_Proxy::request_reply (ACE_Token_Request &request,
|
||||
ACE_TRACE ("ACE_Remote_Token_Proxy::request_reply");
|
||||
void *buffer;
|
||||
ssize_t length;
|
||||
|
||||
if ((length = request.encode (buffer)) == -1)
|
||||
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("encode failed")), -1);
|
||||
|
||||
ACE_SOCK_Stream *peer = ACE_Token_Connections::instance ()->get_connection ();
|
||||
|
||||
if (peer == 0)
|
||||
ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "BIG PROBLEMS with get_connection"), -1);
|
||||
|
||||
// Transmit request via a blocking send.
|
||||
|
||||
if (peer->send_n (buffer, length) != length)
|
||||
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send_n failed")), -1);
|
||||
else
|
||||
{
|
||||
ACE_Token_Reply reply;
|
||||
|
||||
// Receive reply via blocking read.
|
||||
|
||||
if (peer->recv (&reply, sizeof reply) != sizeof reply)
|
||||
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("recv failed")), -1);
|
||||
|
||||
if (reply.decode () == -1)
|
||||
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("decode failed")), -1);
|
||||
|
||||
errno = int (reply.errnum ());
|
||||
if (errno != 0)
|
||||
return -1;
|
||||
@@ -144,12 +182,14 @@ ACE_Remote_Token_Proxy::request_reply (ACE_Token_Request &request,
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Remote_Token_Proxy::acquire (int notify,
|
||||
void (*sleep_hook)(void *),
|
||||
ACE_Synch_Options &options)
|
||||
{
|
||||
ACE_TRACE ("ACE_Remote_Token_Proxy::acquire");
|
||||
|
||||
// First grab the local shadow mutex.
|
||||
if (ACE_Token_Proxy::acquire (notify,
|
||||
sleep_hook,
|
||||
@@ -165,9 +205,11 @@ ACE_Remote_Token_Proxy::acquire (int notify,
|
||||
this->token_->owner_id ()));
|
||||
// No error, but would block,
|
||||
break;
|
||||
|
||||
case EDEADLK :
|
||||
if (debug_)
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) shadow: deadlock detected\n")));
|
||||
|
||||
if (ignore_shadow_deadlock_)
|
||||
break;
|
||||
else
|
||||
@@ -175,6 +217,7 @@ ACE_Remote_Token_Proxy::acquire (int notify,
|
||||
errno = EDEADLK;
|
||||
ACE_RETURN (-1);
|
||||
}
|
||||
|
||||
default :
|
||||
ACE_ERROR_RETURN ((LM_ERROR,
|
||||
ACE_TEXT ("(%t) %p shadow acquire failed\n"),
|
||||
@@ -182,14 +225,18 @@ ACE_Remote_Token_Proxy::acquire (int notify,
|
||||
-1);
|
||||
}
|
||||
}
|
||||
|
||||
ACE_Token_Request request (token_->type (),
|
||||
this->type (),
|
||||
ACE_Token_Request::ACQUIRE,
|
||||
this->name (),
|
||||
this->client_id (),
|
||||
options);
|
||||
|
||||
request.notify (notify);
|
||||
|
||||
int result = this->request_reply (request, options);
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
// Update the local shadow copy.
|
||||
@@ -206,12 +253,15 @@ ACE_Remote_Token_Proxy::acquire (int notify,
|
||||
// is moved to the front of the waiter list.
|
||||
token_->make_owner (waiter_);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Remote_Token_Proxy::tryacquire (void (*sleep_hook)(void *))
|
||||
{
|
||||
ACE_TRACE ("ACE_Remote_Token_Proxy::tryacquire");
|
||||
|
||||
// If we can detect locally that the tryacquire will fail, there is
|
||||
// no need to go remote.
|
||||
if (ACE_Token_Proxy::tryacquire (sleep_hook) == -1)
|
||||
@@ -223,22 +273,27 @@ ACE_Remote_Token_Proxy::tryacquire (void (*sleep_hook)(void *))
|
||||
ACE_DEBUG ((LM_DEBUG,
|
||||
ACE_TEXT ("shadow try acquire failed\n")));
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
ACE_Token_Request request (token_->type (),
|
||||
this->type (),
|
||||
ACE_Token_Request::TRY_ACQUIRE,
|
||||
this->name (),
|
||||
this->client_id (),
|
||||
ACE_Synch_Options::synch);
|
||||
|
||||
return this->request_reply (request,
|
||||
ACE_Synch_Options::synch);
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Remote_Token_Proxy::renew (int requeue_position,
|
||||
ACE_Synch_Options &options)
|
||||
{
|
||||
ACE_TRACE ("ACE_Remote_Token_Proxy::renew");
|
||||
|
||||
if (ACE_Token_Proxy::renew (requeue_position,
|
||||
ACE_Synch_Options::asynch) == -1)
|
||||
{
|
||||
@@ -250,14 +305,18 @@ ACE_Remote_Token_Proxy::renew (int requeue_position,
|
||||
ACE_TEXT ("(%t) shadow: renew would block. owner %s.\n"),
|
||||
this->token_->owner_id ()));
|
||||
}
|
||||
|
||||
ACE_Token_Request request (token_->type (),
|
||||
this->type (),
|
||||
ACE_Token_Request::RENEW,
|
||||
this->name (),
|
||||
this->client_id (),
|
||||
options);
|
||||
|
||||
request.requeue_position (requeue_position);
|
||||
|
||||
int result = this->request_reply (request, options);
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
{
|
||||
@@ -278,32 +337,39 @@ ACE_Remote_Token_Proxy::renew (int requeue_position,
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Remote_Token_Proxy::release (ACE_Synch_Options &options)
|
||||
{
|
||||
ACE_TRACE ("ACE_Remote_Token_Proxy::release");
|
||||
|
||||
ACE_Token_Request request (token_->type (),
|
||||
this->type (),
|
||||
ACE_Token_Request::RELEASE,
|
||||
this->name (),
|
||||
this->client_id (),
|
||||
options);
|
||||
|
||||
int result = this->request_reply (request, options);
|
||||
if (result == 0)
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) released %s remotely.\n"), this->name ()));
|
||||
|
||||
// whether success or failure, we're going to release the shadow.
|
||||
// If race conditions exist such that we are no longer the owner,
|
||||
// this release will perform a remove.
|
||||
if (ACE_Token_Proxy::release () == -1)
|
||||
ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) shadow: release failed\n")));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Remote_Token_Proxy::remove (ACE_Synch_Options &)
|
||||
{
|
||||
ACE_TRACE ("ACE_Remote_Token_Proxy::remove");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Remote_Token_Proxy::token_acquired (ACE_TPQ_Entry *)
|
||||
{
|
||||
@@ -313,6 +379,7 @@ ACE_Remote_Token_Proxy::token_acquired (ACE_TPQ_Entry *)
|
||||
this->name ()));
|
||||
// ACE_Token_Proxy::token_acquired (vp);
|
||||
}
|
||||
|
||||
const ACE_TCHAR*
|
||||
ACE_Remote_Token_Proxy::owner_id (void)
|
||||
{
|
||||
@@ -321,6 +388,7 @@ ACE_Remote_Token_Proxy::owner_id (void)
|
||||
// @@ special operation
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Remote_Token_Proxy::dump (void) const
|
||||
{
|
||||
@@ -335,6 +403,7 @@ ACE_Remote_Token_Proxy::dump (void) const
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
|
||||
#endif /* ACE_HAS_DUMP */
|
||||
}
|
||||
|
||||
ACE_Token_Proxy *
|
||||
ACE_Remote_Mutex::clone (void) const
|
||||
{
|
||||
@@ -346,6 +415,7 @@ ACE_Remote_Mutex::clone (void) const
|
||||
0);
|
||||
return temp;
|
||||
}
|
||||
|
||||
ACE_Tokens *
|
||||
ACE_Remote_Mutex::create_token (const ACE_TCHAR *name)
|
||||
{
|
||||
@@ -355,6 +425,7 @@ ACE_Remote_Mutex::create_token (const ACE_TCHAR *name)
|
||||
0);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Remote_Mutex::dump (void) const
|
||||
{
|
||||
@@ -367,6 +438,7 @@ ACE_Remote_Mutex::dump (void) const
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
|
||||
#endif /* ACE_HAS_DUMP */
|
||||
}
|
||||
|
||||
ACE_Tokens *
|
||||
ACE_Remote_RLock::create_token (const ACE_TCHAR *name)
|
||||
{
|
||||
@@ -376,11 +448,13 @@ ACE_Remote_RLock::create_token (const ACE_TCHAR *name)
|
||||
0);
|
||||
return temp;
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Remote_RLock::type (void) const
|
||||
{
|
||||
return ACE_RW_Token::READER;
|
||||
}
|
||||
|
||||
ACE_Token_Proxy *
|
||||
ACE_Remote_RLock::clone (void) const
|
||||
{
|
||||
@@ -392,6 +466,7 @@ ACE_Remote_RLock::clone (void) const
|
||||
0);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Remote_RLock::dump (void) const
|
||||
{
|
||||
@@ -405,6 +480,7 @@ ACE_Remote_RLock::dump (void) const
|
||||
#endif /* ACE_HAS_DUMP */
|
||||
}
|
||||
|
||||
|
||||
ACE_Tokens *
|
||||
ACE_Remote_WLock::create_token (const ACE_TCHAR *name)
|
||||
{
|
||||
@@ -414,11 +490,13 @@ ACE_Remote_WLock::create_token (const ACE_TCHAR *name)
|
||||
0);
|
||||
return temp;
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Remote_WLock::type (void) const
|
||||
{
|
||||
return ACE_RW_Token::WRITER;
|
||||
}
|
||||
|
||||
ACE_Token_Proxy *
|
||||
ACE_Remote_WLock::clone (void) const
|
||||
{
|
||||
@@ -430,6 +508,7 @@ ACE_Remote_WLock::clone (void) const
|
||||
0);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Remote_WLock::dump (void) const
|
||||
{
|
||||
@@ -442,6 +521,8 @@ ACE_Remote_WLock::dump (void) const
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
|
||||
#endif /* ACE_HAS_DUMP */
|
||||
}
|
||||
|
||||
ACE_END_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
#endif /* ACE_HAS_TOKENS_LIBRARY */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user