int ACE_Name_Proxy::recv_reply (ACE_Name_Request &reply) { ACE_TRACE ("ACE_Name_Proxy::recv_reply"); // Read the first 4 bytes to get the length of the message This // implementation assumes that the first 4 bytes are the length of // the message. ssize_t n = this->peer_.recv ((void *) &reply, sizeof (ACE_UINT32)); switch (n) { case -1: // FALLTHROUGH ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("****************** recv_reply returned -1\n"))); default: ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p got %d bytes, expected %d bytes\n"), ACE_TEXT ("recv failed"), n, sizeof (ACE_UINT32))); // FALLTHROUGH case 0: // We've shutdown unexpectedly return -1; // NOTREACHED case sizeof (ACE_UINT32): { // Transform the length into host byte order. ssize_t length = ACE_NTOHL (reply.length ()); // Receive the rest of the request message. // @@ beware of blocking read!!!. n = this->peer_.recv ((void *) (((char *) &reply) + sizeof (ACE_UINT32)), length - sizeof (ACE_UINT32)); // Subtract off the size of the part we skipped over... if (n != ssize_t (length - sizeof (ACE_UINT32))) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p expected %d, got %d\n"), ACE_TEXT ("invalid length"), length, n)); return -1; } // Decode the request into host byte order. if (reply.decode () == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("decode failed"))); return -1; } } } return 0; }
int ACE_Remote_Name_Space::resolve (const ACE_NS_WString &name, ACE_NS_WString &value, char *&type) { ACE_TRACE ("ACE_Remote_Name_Space::resolve"); ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> name_urep (name.rep ()); ACE_UINT32 name_len = static_cast<ACE_UINT32> (name.length () * sizeof (ACE_WCHAR_T)); ACE_Name_Request request (ACE_Name_Request::RESOLVE, name_urep.get (), name_len, 0, 0, 0, 0); if (this->ns_proxy_.send_request (request) == -1) return -1; ACE_Name_Request reply; if (this->ns_proxy_.recv_reply (reply) == -1) return -1; ACE_NS_WString temp (reply.value (), reply.value_len () / sizeof (ACE_WCHAR_T)); value = temp; ACE_NEW_RETURN (type, char[reply.type_len () + 1], -1); ACE_OS::strcpy (type, reply.type ()); return 0; }
int ACE_Remote_Name_Space::list_types (ACE_WSTRING_SET &set, const ACE_NS_WString &pattern) { ACE_TRACE ("ACE_Remote_Name_Space::list_types"); ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> pattern_urep (pattern.rep ()); ACE_UINT32 pattern_len = static_cast<ACE_UINT32> (pattern.length () * sizeof (ACE_WCHAR_T)); ACE_Name_Request request (ACE_Name_Request::LIST_TYPES, pattern_urep.get (), pattern_len, 0, 0, 0, 0); if (this->ns_proxy_.send_request (request) == -1) return -1; ACE_Name_Request reply (0, 0, 0, 0, 0, 0, 0, 0); while (reply.msg_type () != ACE_Name_Request::MAX_ENUM) { if (this->ns_proxy_.recv_reply (reply) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Remote_Name_Space::list_values")), -1); if (reply.msg_type () != ACE_Name_Request::MAX_ENUM) { ACE_NS_WString type (reply.type ()); set.insert (type); } } return 0; }
int ACE_Remote_Name_Space::list_name_entries (ACE_BINDING_SET &set, const ACE_NS_WString &pattern) { ACE_TRACE ("ACE_Remote_Name_Space::list_name_entries"); ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> pattern_urep (pattern.rep ()); ACE_UINT32 pattern_len = static_cast<ACE_UINT32> (pattern.length () * sizeof (ACE_WCHAR_T)); ACE_Name_Request request (ACE_Name_Request::LIST_NAME_ENTRIES, pattern_urep.get (), pattern_len, 0, 0, 0, 0); if (this->ns_proxy_.send_request (request) == -1) return -1; ACE_Name_Request reply (0, 0, 0, 0, 0, 0, 0, 0); while (reply.msg_type () != ACE_Name_Request::MAX_ENUM) { if (this->ns_proxy_.recv_reply (reply) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_LIB_TEXT ("%p\n"), ACE_LIB_TEXT ("ACE_Remote_Name_Space::list_names")), -1); if (reply.msg_type () != ACE_Name_Request::MAX_ENUM) { ACE_NS_WString name (reply.name (), reply.name_len () / sizeof (ACE_WCHAR_T)); ACE_NS_WString value (reply.value (), reply.value_len () / sizeof (ACE_WCHAR_T)); ACE_Name_Binding entry (name, value, reply.type ()); if (set.insert (entry) == -1) return -1; } } return 0; }
int ACE_Name_Proxy::request_reply (ACE_Name_Request &request) { ACE_TRACE ("ACE_Name_Proxy::request_reply"); void *buffer; ssize_t length = request.encode (buffer); if (length == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("encode failed")), -1); // Transmit request via a blocking send. if (this->peer_.send_n (buffer, length) != length) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send_n failed")), -1); else { ACE_Name_Reply reply; // Receive reply via blocking read. if (this->peer_.recv_n (&reply, sizeof reply) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("recv failed")), -1); else if (reply.decode () == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("decode failed")), -1); errno = int (reply.errnum ()); return reply.status (); } }
/* VIRTUAL */ int ACE_Name_Handler::send_request (ACE_Name_Request &request) { ACE_TRACE (ACE_TEXT ("ACE_Name_Handler::send_request")); void *buffer; ssize_t length = request.encode (buffer); if (length == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("encode failed")), -1); // Transmit request via a blocking send. if (this->peer ().send_n (buffer, length) != length) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send_n failed")), -1); return 0; }
int ACE_Name_Proxy::send_request (ACE_Name_Request &request) { ACE_TRACE ("ACE_Name_Proxy::send_request"); void *buffer; ssize_t length = request.encode (buffer); if (length == -1) ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("encode failed")), -1); // Transmit request via a blocking send. else if (this->peer_.send_n (buffer, length) != length) ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send_n failed")), -1); return 0; }