3 //=============================================================================
7 * $Id: MEM_IO.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Nanbor Wang <nanbor@cs.wustl.edu>
11 //=============================================================================
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/ACE_export.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
27 #include "ace/MEM_SAP.h"
28 #include "ace/Message_Block.h"
29 #include "ace/Process_Semaphore.h"
30 #include "ace/Process_Mutex.h"
33 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
35 class ACE_Export ACE_Reactive_MEM_IO
: public ACE_MEM_SAP
38 ACE_Reactive_MEM_IO (void);
40 virtual ~ACE_Reactive_MEM_IO (void);
43 * Initialize the MEM_SAP object.
45 * @a options is used to pass in the Malloc_Options to initialize
46 * underlying ACE_MMAP.
48 virtual int init (ACE_HANDLE handle
,
49 const ACE_TCHAR
*name
,
50 MALLOC_OPTIONS
*options
);
53 * Fetch location of next available data into <recv_buffer_>.
54 * As this operation read the address of the data off the socket
55 * using ACE::recv, @a timeout only applies to ACE::recv.
57 virtual ssize_t
recv_buf (ACE_MEM_SAP_Node
*&buf
,
59 const ACE_Time_Value
*timeout
);
62 * Wait to to @a timeout amount of time to send @a buf. If <send>
63 * times out a -1 is returned with @c errno == ETIME. If it succeeds
64 * the number of bytes sent is returned. */
65 virtual ssize_t
send_buf (ACE_MEM_SAP_Node
*buf
,
67 const ACE_Time_Value
*timeout
);
70 * Convert the buffer offset <off> to absolute address to @a buf.
71 * Return the size of valid information containing in the @a buf,
72 * -1 if <shm_malloc_> is not initialized.
74 ssize_t
get_buf_len (const ACE_OFF_T off
, ACE_MEM_SAP_Node
*&buf
);
77 #if defined (ACE_WIN32) || !defined (_ACE_USE_SV_SEM)
78 class ACE_Export ACE_MT_MEM_IO
: public ACE_MEM_SAP
83 ACE_MEM_SAP_Node::ACE_MEM_SAP_NODE_PTR head_
;
84 ACE_MEM_SAP_Node::ACE_MEM_SAP_NODE_PTR tail_
;
85 } MQ_Struct
; // Structure for a simple queue
91 Simple_Queue (MQ_Struct
*mq
);
93 int init (MQ_Struct
*mq
, ACE_MEM_SAP::MALLOC_TYPE
*malloc
);
95 int write (ACE_MEM_SAP_Node
*new_msg
);
97 ACE_MEM_SAP_Node
*read (void);
100 ACE_MEM_SAP::MALLOC_TYPE
*malloc_
;
105 ACE_SYNCH_PROCESS_SEMAPHORE
*sema_
;
106 ACE_SYNCH_PROCESS_MUTEX
*lock_
;
110 ACE_MT_MEM_IO (void);
112 virtual ~ACE_MT_MEM_IO (void);
115 * Initialize the MEM_SAP object.
117 virtual int init (ACE_HANDLE handle
,
118 const ACE_TCHAR
*name
,
119 MALLOC_OPTIONS
*options
);
122 * Fetch location of next available data into <recv_buffer_>.
123 * As this operation read the address of the data off the socket
124 * using ACE::recv, @a timeout only applies to ACE::recv.
126 virtual ssize_t
recv_buf (ACE_MEM_SAP_Node
*&buf
,
128 const ACE_Time_Value
*timeout
);
131 * Wait to to @a timeout amount of time to send @a buf. If <send>
132 * times out a -1 is returned with @c errno == ETIME. If it succeeds
133 * the number of bytes sent is returned. */
134 virtual ssize_t
send_buf (ACE_MEM_SAP_Node
*buf
,
136 const ACE_Time_Value
*timeout
);
139 Channel recv_channel_
;
140 Channel send_channel_
;
142 #endif /* ACE_WIN32 || !_ACE_USE_SV_SEM */
147 * @brief Defines the methods for the ACE shared memeory wrapper I/O
148 * routines (e.g., send/recv).
149 * The shared memory transport uses ACE_SOCK_* class to
150 * implement the signaling mechanism so we can easily use the
151 * new mechanism with the Reactor pattern (which uses select
153 * ACE_MEM_Acceptor and ACE_MEM_Connector are used to establish
154 * connections. When a connection is established,
155 * ACE_MEM_Acceptor creates the MMAP file for data exchange and
156 * sends the location of the file (complete path name) to
157 * ACE_MEM_Connector thru the socket. ACE_MEM_Connector then
158 * reads the location of the file off the socket and opens up
159 * the same MMAP file. ACE_MEM_Stream at each side then
160 * contains a reference to the ACE_Mallo object using the same
162 * When sending information using methods provided in this
163 * class, ACE_MEM_IO requests a chunk of memory from the
164 * MALLOC_TYPE object, copy the data into the shared memory and
165 * send the memory offset (from the start of the ACE_Malloc)
166 * across the socket. This action also servers as a signal to
167 * the other end. The receiving side then reverses the
168 * procedures and copies the information into user buffer.
170 class ACE_Export ACE_MEM_IO
: public ACE_SOCK
173 // = Initialization and termination methods.
187 * Initialize the MEM_SAP object.
189 int init (const ACE_TCHAR
*name
,
190 ACE_MEM_IO::Signal_Strategy type
= ACE_MEM_IO::Reactive
,
191 ACE_MEM_SAP::MALLOC_OPTIONS
*options
= 0);
194 * Finalizing the MEM_IO object. This method doesn't invoke
195 * the <remove> method.
199 /// Send an @a n byte buffer to the other process using shm_malloc_
200 /// connected thru the socket.
201 ssize_t
send (const void *buf
,
205 /// Recv an @a n byte buffer from the shm_malloc_ thru connected socket.
206 ssize_t
recv (void *buf
,
210 /// Send an @a n byte buffer to the other process using shm_malloc_
211 /// connected thru the socket.
212 ssize_t
send (const void *buf
,
215 /// Recv an @a n byte buffer from the shm_malloc_ thru connected socket.
216 ssize_t
recv (void *buf
,
220 * Wait to to @a timeout amount of time to send up to @a n bytes into
221 * @a buf from <handle> (uses the <send> call). If <send> times out
222 * a -1 is returned with @c errno == ETIME. If it succeeds the
223 * number of bytes sent is returned.
225 ssize_t
send (const void *buf
,
227 const ACE_Time_Value
*timeout
);
230 * Wait to to @a timeout amount of time to send up to @a n bytes into
231 * @a buf from <handle> (uses the <send> call). If <send> times out
232 * a -1 is returned with @c errno == ETIME. If it succeeds the
233 * number of bytes sent is returned.
235 ssize_t
send (const void *buf
,
238 const ACE_Time_Value
*timeout
);
241 * Wait to to @a timeout amount of time to send the @a message_block.
242 * If <send> times out a -1 is returned with @c errno == ETIME. If
243 * it succeeds the number of bytes sent is returned.
245 ssize_t
send (const ACE_Message_Block
*message_block
,
246 const ACE_Time_Value
*timeout
);
249 * Wait up to @a timeout amount of time to receive up to @a n bytes
250 * into @a buf from <handle> (uses the <recv> call). If <recv> times
251 * out a -1 is returned with @c errno == ETIME. If it succeeds the
252 * number of bytes received is returned.
254 ssize_t
recv (void *buf
,
256 const ACE_Time_Value
*timeout
);
259 * Wait up to @a timeout amount of time to receive up to @a n bytes
260 * into @a buf from <handle> (uses the <recv> call). If <recv> times
261 * out a -1 is returned with @c errno == ETIME. If it succeeds the
262 * number of bytes received is returned.
264 ssize_t
recv (void *buf
,
267 const ACE_Time_Value
*timeout
);
270 /// Dump the state of an object.
271 void dump (void) const;
273 /// Declare the dynamic allocation hooks.
274 ACE_ALLOC_HOOK_DECLARE
;
276 /// Return the local endpoint port number. Returns 0 if successful,
278 /* int get_local_port (u_short &) const;
280 /// Return the port number of the remotely connected peer (if there
281 /// is one). Returns 0 if successful, else -1.
282 int get_remote_port (u_short &) const;
286 ssize_t
fetch_recv_buf (int flag
, const ACE_Time_Value
*timeout
);
288 /// Actual deliverying mechanism.
289 ACE_MEM_SAP
*deliver_strategy_
;
291 /// Internal pointer for support recv/send.
292 ACE_MEM_SAP_Node
*recv_buffer_
;
294 /// Record the current total buffer size of <recv_buffer_>.
297 /// Record the current read pointer location in <recv_buffer_>.
301 ACE_END_VERSIONED_NAMESPACE_DECL
303 #if defined (__ACE_INLINE__)
304 #include "ace/MEM_IO.inl"
305 #endif /* __ACE_INLINE__ */
307 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
309 #include /**/ "ace/post.h"
310 #endif /* ACE_SOCK_IO_H */