3 //=============================================================================
7 * @author Nanbor Wang <nanbor@cs.wustl.edu>
9 //=============================================================================
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/ACE_export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 // MEM_SAP requries position independent pointers to work
23 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
25 #include "ace/PI_Malloc.h"
26 #include "ace/Malloc_T.h"
27 #include "ace/MMAP_Memory_Pool.h"
28 #include "ace/Process_Mutex.h"
30 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
33 class ACE_Reactive_MEM_IO
;
37 // Internal data structure
38 // MEM_SAP uses to queue up
40 class ACE_MEM_SAP_Node
43 typedef ACE_Based_Pointer
<ACE_MEM_SAP_Node
> ACE_MEM_SAP_NODE_PTR
;
45 /// Initialize the node with its capacity.
46 ACE_MEM_SAP_Node (size_t cap
);
48 /// Get the size of the data we hold.
51 /// Get the capacity of this block of data.
52 size_t capacity () const;
54 /// Get the pointer to the block of data we hold.
57 /// The maximum size of this memory block.
60 /// The actualy size used.
63 ACE_MEM_SAP_NODE_PTR next_
;
69 * @brief Defines the methods of shared memory management for
70 * shared memory transport.
72 class ACE_Export ACE_MEM_SAP
75 typedef ACE_Malloc_T
<ACE_MMAP_MEMORY_POOL
, ACE_Process_Mutex
, ACE_PI_Control_Block
> MALLOC_TYPE
;
76 typedef ACE_MMAP_Memory_Pool_Options MALLOC_OPTIONS
;
79 virtual ~ACE_MEM_SAP ();
82 * Initialize the MEM_SAP object.
84 virtual int init (ACE_HANDLE handle
,
85 const ACE_TCHAR
*name
,
86 MALLOC_OPTIONS
*options
) = 0;
89 * Finalizing the MEM_SAP object. This method doesn't invoke
90 * the <remove> method.
95 * Fetch location of next available data into <recv_buffer_>.
96 * As this operation read the address of the data off the socket
97 * using ACE::recv, @a timeout only applies to ACE::recv.
99 virtual ssize_t
recv_buf (ACE_MEM_SAP_Node
*&buf
,
101 const ACE_Time_Value
*timeout
) = 0;
104 * Wait to to @a timeout amount of time to send @a buf. If <send>
105 * times out a -1 is returned with @c errno == ETIME. If it succeeds
106 * the number of bytes sent is returned. */
107 virtual ssize_t
send_buf (ACE_MEM_SAP_Node
*buf
,
109 const ACE_Time_Value
*timeout
) = 0;
111 /// request a buffer of size @a size. Return 0 if the <shm_malloc_> is
113 ACE_MEM_SAP_Node
*acquire_buffer (const ssize_t size
);
115 /// release a buffer pointed by @a buf. Return -1 if the <shm_malloc_>
116 /// is not initialized.
117 int release_buffer (ACE_MEM_SAP_Node
*buf
);
119 /// Dump the state of an object.
122 /// Declare the dynamic allocation hooks.
123 ACE_ALLOC_HOOK_DECLARE
;
126 // = Class initializing methods to create/connect to a shared memory pool.
129 * Create a new shm_malloc object. Return 0 if succeed and -1
130 * otherwise. This method should only be called from an acceptor
131 * class that wants to create a new memory pool for inter process
134 int create_shm_malloc (const ACE_TCHAR
*name
,
135 MALLOC_OPTIONS
*options
);
137 /// Close down the share memory pool. Clean up the
138 /// mmap file if we are the last one using it.
139 int close_shm_malloc ();
143 /// Data exchange channel.
144 MALLOC_TYPE
*shm_malloc_
;
146 /// Constructor. Prevent this class from being instantiated.
150 ACE_END_VERSIONED_NAMESPACE_DECL
152 #if defined (__ACE_INLINE__)
153 #include "ace/MEM_SAP.inl"
154 #endif /* __ACE_INLINE__ */
156 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
158 #include /**/ "ace/post.h"
160 #endif /* ACE_SOCK_IO_H */