Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / MEM_Connector.cpp
blob33c15be3ca3d8e36ec21da29e6702ffc2773233d
1 // MEM_Connector.cpp
2 // $Id: MEM_Connector.cpp 81517 2008-04-29 07:23:47Z johnnyw $
4 #include "ace/MEM_Connector.h"
6 ACE_RCSID(ace, MEM_Connector, "$Id: MEM_Connector.cpp 81517 2008-04-29 07:23:47Z johnnyw $")
8 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
10 #if !defined (__ACE_INLINE__)
11 #include "ace/MEM_Connector.inl"
12 #endif /* __ACE_INLINE__ */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE(ACE_MEM_Connector)
18 void
19 ACE_MEM_Connector::dump (void) const
21 #if defined (ACE_HAS_DUMP)
22 ACE_TRACE ("ACE_MEM_Connector::dump");
24 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
25 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
26 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
27 #endif /* ACE_HAS_DUMP */
30 ACE_MEM_Connector::ACE_MEM_Connector (void)
31 : malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
32 preferred_strategy_ (ACE_MEM_IO::Reactive)
34 ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector");
37 // Establish a connection.
38 ACE_MEM_Connector::ACE_MEM_Connector (ACE_MEM_Stream &new_stream,
39 const ACE_INET_Addr &remote_sap,
40 ACE_Time_Value *timeout,
41 const ACE_Addr &local_sap,
42 int reuse_addr,
43 int flags,
44 int perms)
45 : malloc_options_ (ACE_DEFAULT_BASE_ADDR, 0),
46 preferred_strategy_ (ACE_MEM_IO::Reactive)
48 ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector");
49 // This is necessary due to the weird inheritance relationships of
50 // ACE_MEM_Stream.
51 this->connect (new_stream,
52 remote_sap,
53 timeout,
54 local_sap,
55 reuse_addr,
56 flags,
57 perms);
60 int
61 ACE_MEM_Connector::connect (ACE_MEM_Stream &new_stream,
62 const ACE_INET_Addr &remote_sap,
63 ACE_Time_Value *timeout,
64 const ACE_Addr &local_sap,
65 int reuse_addr,
66 int flags,
67 int perms)
69 ACE_TRACE ("ACE_MEM_Connector::connect");
71 if (!this->address_.same_host (remote_sap))
72 ACE_ERROR_RETURN ((LM_ERROR,
73 ACE_TEXT ("(%P|%t) MEM_Connector can't connect ")
74 ACE_TEXT ("to %s:%d which is not a local endpoint ")
75 ACE_TEXT ("(local address is %s:%d)\n"),
76 ACE_TEXT_CHAR_TO_TCHAR (remote_sap.get_host_name ()),
77 remote_sap.get_port_number (),
78 ACE_TEXT_CHAR_TO_TCHAR (this->address_.get_host_name ()),
79 this->address_.get_port_number ()),
80 -1);
81 else
82 this->address_.set_port_number (remote_sap.get_port_number ());
85 ACE_SOCK_Stream temp_stream;
87 if (ACE_SOCK_Connector::connect (temp_stream,
88 this->address_.get_local_addr (),
89 timeout, local_sap,
90 reuse_addr, flags, perms) == -1)
91 ACE_ERROR_RETURN ((LM_DEBUG,
92 ACE_TEXT ("%p\n"),
93 ACE_TEXT ("ACE_MEM_Connector::connect")),
94 -1);
97 ACE_HANDLE new_handle = temp_stream.get_handle ();
98 new_stream.set_handle (new_handle);
99 new_stream.disable (ACE_NONBLOCK);
100 // Do not close the handle.
102 // now we should setup the mmap malloc.
103 ACE_TCHAR buf[MAXPATHLEN];
105 // @@ Need to handle timeout here.
106 ACE_INT16 server_strategy = ACE_MEM_IO::Reactive;
107 // Receive the signaling strategy theserver support.
108 if (ACE::recv (new_handle, &server_strategy,
109 sizeof (ACE_INT16)) == -1)
110 ACE_ERROR_RETURN ((LM_DEBUG,
111 ACE_TEXT ("ACE_MEM_Connector::connect error receiving strategy\n")),
112 -1);
114 // If either side don't support MT, we will not use it.
115 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
116 if (! (this->preferred_strategy_ == ACE_MEM_IO::MT &&
117 server_strategy == ACE_MEM_IO::MT))
118 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
119 server_strategy = ACE_MEM_IO::Reactive;
121 if (ACE::send (new_handle, &server_strategy,
122 sizeof (ACE_INT16)) == -1)
123 ACE_ERROR_RETURN ((LM_DEBUG,
124 ACE_TEXT ("ACE_MEM_Connector::connect error sending strategy\n")),
125 -1);
127 ACE_INT16 buf_len;
128 // Byte-order is not a problem for this read.
129 if (ACE::recv (new_handle, &buf_len, sizeof (buf_len)) == -1)
130 ACE_ERROR_RETURN ((LM_DEBUG,
131 ACE_TEXT ("ACE_MEM_Connector::connect error receiving shm filename length\n")),
132 -1);
134 if (ACE::recv (new_handle, buf, buf_len) == -1)
135 ACE_ERROR_RETURN ((LM_DEBUG,
136 ACE_TEXT ("ACE_MEM_Connector::connect error receiving shm filename.\n")),
137 -1);
139 if (new_stream.init (buf,
140 static_cast<ACE_MEM_IO::Signal_Strategy> (server_strategy),
141 &this->malloc_options_) == -1)
142 return -1;
144 return 0;
147 ACE_END_VERSIONED_NAMESPACE_DECL
149 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */