1 #include "ace/MEM_Connector.h"
3 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
5 #if !defined (__ACE_INLINE__)
6 #include "ace/MEM_Connector.inl"
7 #endif /* __ACE_INLINE__ */
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 ACE_ALLOC_HOOK_DEFINE(ACE_MEM_Connector
)
14 ACE_MEM_Connector::dump () const
16 #if defined (ACE_HAS_DUMP)
17 ACE_TRACE ("ACE_MEM_Connector::dump");
19 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
20 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
21 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
22 #endif /* ACE_HAS_DUMP */
25 ACE_MEM_Connector::ACE_MEM_Connector ()
26 : malloc_options_ (ACE_DEFAULT_BASE_ADDR
, 0),
27 preferred_strategy_ (ACE_MEM_IO::Reactive
)
29 ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector");
32 // Establish a connection.
33 ACE_MEM_Connector::ACE_MEM_Connector (ACE_MEM_Stream
&new_stream
,
34 const ACE_INET_Addr
&remote_sap
,
35 const ACE_Time_Value
*timeout
,
36 const ACE_Addr
&local_sap
,
40 : malloc_options_ (ACE_DEFAULT_BASE_ADDR
, 0),
41 preferred_strategy_ (ACE_MEM_IO::Reactive
)
43 ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector");
44 // This is necessary due to the weird inheritance relationships of
46 this->connect (new_stream
,
56 ACE_MEM_Connector::connect (ACE_MEM_Stream
&new_stream
,
57 const ACE_INET_Addr
&remote_sap
,
58 const ACE_Time_Value
*timeout
,
59 const ACE_Addr
&local_sap
,
64 ACE_TRACE ("ACE_MEM_Connector::connect");
66 if (!this->address_
.same_host (remote_sap
))
67 ACELIB_ERROR_RETURN ((LM_ERROR
,
68 ACE_TEXT ("(%P|%t) MEM_Connector can't connect ")
69 ACE_TEXT ("to %C:%d which is not a local endpoint ")
70 ACE_TEXT ("(local address is %C:%d)\n"),
71 remote_sap
.get_host_name (),
72 remote_sap
.get_port_number (),
73 this->address_
.get_host_name (),
74 this->address_
.get_port_number ()),
77 this->address_
.set_port_number (remote_sap
.get_port_number ());
80 ACE_SOCK_Stream temp_stream
;
82 if (ACE_SOCK_Connector::connect (temp_stream
,
83 this->address_
.get_local_addr (),
85 reuse_addr
, flags
, perms
) == -1)
86 ACELIB_ERROR_RETURN ((LM_DEBUG
,
88 ACE_TEXT ("ACE_MEM_Connector::connect")),
92 ACE_HANDLE new_handle
= temp_stream
.get_handle ();
93 new_stream
.set_handle (new_handle
);
94 new_stream
.disable (ACE_NONBLOCK
);
95 // Do not close the handle.
97 // now we should setup the mmap malloc.
98 ACE_TCHAR buf
[MAXPATHLEN
];
100 // @@ Need to handle timeout here.
101 ACE_INT16 server_strategy
= ACE_MEM_IO::Reactive
;
102 // Receive the signaling strategy theserver support.
103 if (ACE::recv (new_handle
, &server_strategy
,
104 sizeof (ACE_INT16
)) == -1)
105 ACELIB_ERROR_RETURN ((LM_DEBUG
,
106 ACE_TEXT ("ACE_MEM_Connector::connect error receiving strategy\n")),
109 // If either side don't support MT, we will not use it.
110 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
111 if (! (this->preferred_strategy_
== ACE_MEM_IO::MT
&&
112 server_strategy
== ACE_MEM_IO::MT
))
113 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
114 server_strategy
= ACE_MEM_IO::Reactive
;
116 if (ACE::send (new_handle
, &server_strategy
,
117 sizeof (ACE_INT16
)) == -1)
118 ACELIB_ERROR_RETURN ((LM_DEBUG
,
119 ACE_TEXT ("ACE_MEM_Connector::connect error sending strategy\n")),
123 // Byte-order is not a problem for this read.
124 if (ACE::recv (new_handle
, &buf_len
, sizeof (buf_len
)) == -1)
125 ACELIB_ERROR_RETURN ((LM_DEBUG
,
126 ACE_TEXT ("ACE_MEM_Connector::connect error receiving shm filename length\n")),
129 if (ACE::recv (new_handle
, buf
, buf_len
) == -1)
130 ACELIB_ERROR_RETURN ((LM_DEBUG
,
131 ACE_TEXT ("ACE_MEM_Connector::connect error receiving shm filename.\n")),
134 if (new_stream
.init (buf
,
135 static_cast<ACE_MEM_IO::Signal_Strategy
> (server_strategy
),
136 &this->malloc_options_
) == -1)
142 ACE_END_VERSIONED_NAMESPACE_DECL
144 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */