3 //=============================================================================
7 * $Id: MEM_SAP.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 // MEM_SAP requries position independent pointers to work
25 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
27 #include "ace/PI_Malloc.h"
28 #include "ace/Malloc_T.h"
29 #include "ace/MMAP_Memory_Pool.h"
30 #include "ace/Process_Mutex.h"
32 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
35 class ACE_Reactive_MEM_IO
;
39 // Internal data structure
40 // MEM_SAP uses to queue up
42 class ACE_MEM_SAP_Node
45 // friend class ACE_MEM_SAP;
46 // friend class ACE_Reactive_MEM_IO;
47 // friend class ACE_MT_MEM_IO;
48 // friend class ACE_MEM_IO;
50 typedef ACE_Based_Pointer
<ACE_MEM_SAP_Node
> ACE_MEM_SAP_NODE_PTR
;
52 /// Initialize the node with its capacity.
53 ACE_MEM_SAP_Node (size_t cap
);
55 /// Get the size of the data we hold.
56 size_t size (void) const;
58 /// Get the capacity of this block of data.
59 size_t capacity (void) const;
61 /// Get the pointer to the block of data we hold.
64 /// The maximum size of this memory block.
67 /// The actualy size used.
70 ACE_MEM_SAP_NODE_PTR next_
;
76 * @brief Defines the methods of shared memory management for
77 * shared memory transport.
79 class ACE_Export ACE_MEM_SAP
82 // = Initialization and termination methods.
84 typedef ACE_Malloc_T
<ACE_MMAP_MEMORY_POOL
, ACE_Process_Mutex
, ACE_PI_Control_Block
> MALLOC_TYPE
;
85 typedef ACE_MMAP_Memory_Pool_Options MALLOC_OPTIONS
;
88 virtual ~ACE_MEM_SAP (void);
91 * Initialize the MEM_SAP object.
93 virtual int init (ACE_HANDLE handle
,
94 const ACE_TCHAR
*name
,
95 MALLOC_OPTIONS
*options
) = 0;
98 * Finalizing the MEM_SAP object. This method doesn't invoke
99 * the <remove> method.
104 * Fetch location of next available data into <recv_buffer_>.
105 * As this operation read the address of the data off the socket
106 * using ACE::recv, @a timeout only applies to ACE::recv.
108 virtual ssize_t
recv_buf (ACE_MEM_SAP_Node
*&buf
,
110 const ACE_Time_Value
*timeout
) = 0;
113 * Wait to to @a timeout amount of time to send @a buf. If <send>
114 * times out a -1 is returned with @c errno == ETIME. If it succeeds
115 * the number of bytes sent is returned. */
116 virtual ssize_t
send_buf (ACE_MEM_SAP_Node
*buf
,
118 const ACE_Time_Value
*timeout
) = 0;
120 /// request a buffer of size @a size. Return 0 if the <shm_malloc_> is
122 ACE_MEM_SAP_Node
*acquire_buffer (const ssize_t size
);
124 /// release a buffer pointed by @a buf. Return -1 if the <shm_malloc_>
125 /// is not initialized.
126 int release_buffer (ACE_MEM_SAP_Node
*buf
);
128 /// Dump the state of an object.
129 void dump (void) const;
131 /// Declare the dynamic allocation hooks.
132 ACE_ALLOC_HOOK_DECLARE
;
135 // = Class initializing methods to create/connect to a shared memory pool.
138 * Create a new shm_malloc object. Return 0 if succeed and -1
139 * otherwise. This method should only be called from an acceptor
140 * class that wants to create a new memory pool for inter process
143 int create_shm_malloc (const ACE_TCHAR
*name
,
144 MALLOC_OPTIONS
*options
);
146 /// Close down the share memory pool. Clean up the
147 /// mmap file if we are the last one using it.
148 int close_shm_malloc (void);
152 /// Data exchange channel.
153 MALLOC_TYPE
*shm_malloc_
;
155 /// Constructor. Prevent this class from being instantiated.
159 ACE_END_VERSIONED_NAMESPACE_DECL
161 #if defined (__ACE_INLINE__)
162 #include "ace/MEM_SAP.inl"
163 #endif /* __ACE_INLINE__ */
165 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
167 #include /**/ "ace/post.h"
169 #endif /* ACE_SOCK_IO_H */