1 #include "ace/Name_Proxy.h"
2 #include "ace/Log_Category.h"
3 #include "ace/os_include/arpa/os_inet.h"
7 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
10 ACE_Name_Proxy::dump (void) const
12 #if defined (ACE_HAS_DUMP)
13 ACE_TRACE ("ACE_Name_Proxy::dump");
15 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
16 this->connector_
.dump ();
18 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("reactor_ = %x"), this->reactor_
));
19 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
20 #endif /* ACE_HAS_DUMP */
23 // Default constructor.
25 ACE_Name_Proxy::ACE_Name_Proxy (void)
28 ACE_TRACE ("ACE_Name_Proxy::ACE_Name_Proxy");
31 // Establish binding with the ACE_Name Server at remote_addr.
34 ACE_Name_Proxy::open (const ACE_INET_Addr
&remote_addr
,
35 ACE_Synch_Options
& options
)
37 ACE_TRACE ("ACE_Name_Proxy::open");
38 ACE_Time_Value
*timeout
= 0;
40 if (options
[ACE_Synch_Options::USE_TIMEOUT
])
41 timeout
= const_cast<ACE_Time_Value
*> (options
.time_value ());
43 // Initiate the connection.
44 return this->connector_
.connect (this->peer_
,
49 // Establish binding with the ACE_Name Server at remote_addr.
51 ACE_Name_Proxy::ACE_Name_Proxy (
52 const ACE_INET_Addr
&remote_addr
,
53 ACE_Synch_Options
& options
)
56 ACE_TRACE ("ACE_Name_Proxy::ACE_Name_Proxy");
57 if (this->open (remote_addr
, options
) == -1
58 && options
[ACE_Synch_Options::USE_TIMEOUT
] && errno
!= EWOULDBLOCK
)
59 ACELIB_ERROR ((LM_ERROR
,
61 ACE_TEXT ("ACE_Name_Proxy::ACE_Name_Proxy")));
64 // Obtain underlying handle.
66 /* VIRTUAL */ ACE_HANDLE
67 ACE_Name_Proxy::get_handle (void) const
69 ACE_TRACE ("ACE_Name_Proxy::get_handle");
70 return this->peer_
.get_handle ();
74 ACE_Name_Proxy::request_reply (ACE_Name_Request
&request
)
76 ACE_TRACE ("ACE_Name_Proxy::request_reply");
78 ssize_t length
= request
.encode (buffer
);
81 ACELIB_ERROR_RETURN ((LM_ERROR
,
83 ACE_TEXT ("encode failed")),
86 // Transmit request via a blocking send.
88 if (this->peer_
.send_n (buffer
, length
) != length
)
89 ACELIB_ERROR_RETURN ((LM_ERROR
,
91 ACE_TEXT ("send_n failed")),
97 // Receive reply via blocking read.
99 if (this->peer_
.recv_n (&reply
,
101 ACELIB_ERROR_RETURN ((LM_ERROR
,
103 ACE_TEXT ("recv failed")),
105 else if (reply
.decode () == -1)
106 ACELIB_ERROR_RETURN ((LM_ERROR
,
108 ACE_TEXT ("decode failed")),
110 errno
= int (reply
.errnum ());
111 return reply
.status ();
116 ACE_Name_Proxy::send_request (ACE_Name_Request
&request
)
118 ACE_TRACE ("ACE_Name_Proxy::send_request");
120 ssize_t length
= request
.encode (buffer
);
123 ACELIB_ERROR_RETURN ((LM_ERROR
,
125 ACE_TEXT ("encode failed")),
128 // Transmit request via a blocking send.
130 else if (this->peer_
.send_n (buffer
, length
) != length
)
131 ACELIB_ERROR_RETURN ((LM_ERROR
,
133 ACE_TEXT ("send_n failed")),
139 ACE_Name_Proxy::recv_reply (ACE_Name_Request
&reply
)
141 ACE_TRACE ("ACE_Name_Proxy::recv_reply");
142 // Read the first 4 bytes to get the length of the message This
143 // implementation assumes that the first 4 bytes are the length of
145 ssize_t n
= this->peer_
.recv ((void *) &reply
, sizeof (ACE_UINT32
));
150 ACELIB_DEBUG ((LM_DEBUG
,
151 ACE_TEXT ("****************** recv_reply returned -1\n")));
154 ACELIB_ERROR ((LM_ERROR
,
155 ACE_TEXT ("%p got %d bytes, expected %d bytes\n"),
156 ACE_TEXT ("recv failed"),
158 sizeof (ACE_UINT32
)));
161 // We've shutdown unexpectedly
164 case sizeof (ACE_UINT32
):
166 // Transform the length into host byte order.
167 ssize_t length
= ACE_NTOHL (reply
.length ());
169 // Receive the rest of the request message.
170 // @@ beware of blocking read!!!.
171 n
= this->peer_
.recv ((void *) (((char *) &reply
)
172 + sizeof (ACE_UINT32
)),
173 length
- sizeof (ACE_UINT32
));
175 // Subtract off the size of the part we skipped over...
176 if (n
!= ssize_t (length
- sizeof (ACE_UINT32
)))
178 ACELIB_ERROR ((LM_ERROR
,
179 ACE_TEXT ("%p expected %d, got %d\n"),
180 ACE_TEXT ("invalid length"),
186 // Decode the request into host byte order.
187 if (reply
.decode () == -1)
189 ACELIB_ERROR ((LM_ERROR
,
191 ACE_TEXT ("decode failed")));
199 // Close down the connection to the server.
201 ACE_Name_Proxy::~ACE_Name_Proxy (void)
203 ACE_TRACE ("ACE_Name_Proxy::~ACE_Name_Proxy");
204 this->peer_
.close ();
207 ACE_END_VERSIONED_NAMESPACE_DECL