Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / MEM_SAP.h
blob7b19e8da1aec662aab90ab2e34012593adf94e37
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file MEM_SAP.h
7 * @author Nanbor Wang <nanbor@cs.wustl.edu>
8 */
9 //=============================================================================
11 #ifndef ACE_MEM_SAP_H
12 #define ACE_MEM_SAP_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/ACE_export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # 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
32 class ACE_MEM_SAP;
33 class ACE_Reactive_MEM_IO;
34 class ACE_MT_MEM_IO;
35 class ACE_MEM_IO;
37 // Internal data structure
38 // MEM_SAP uses to queue up
39 // data.
40 class ACE_MEM_SAP_Node
42 public:
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.
49 size_t size () const;
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.
55 void *data ();
57 /// The maximum size of this memory block.
58 size_t capacity_;
60 /// The actualy size used.
61 size_t size_;
63 ACE_MEM_SAP_NODE_PTR next_;
66 /**
67 * @class ACE_MEM_SAP
69 * @brief Defines the methods of shared memory management for
70 * shared memory transport.
72 class ACE_Export ACE_MEM_SAP
74 public:
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;
78 /// Destructor.
79 virtual ~ACE_MEM_SAP ();
81 /**
82 * Initialize the MEM_SAP object.
84 virtual int init (ACE_HANDLE handle,
85 const ACE_TCHAR *name,
86 MALLOC_OPTIONS *options) = 0;
88 /**
89 * Finalizing the MEM_SAP object. This method doesn't invoke
90 * the <remove> method.
92 virtual int fini ();
94 /**
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,
100 int flags,
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,
108 int flags,
109 const ACE_Time_Value *timeout) = 0;
111 /// request a buffer of size @a size. Return 0 if the <shm_malloc_> is
112 /// not initialized.
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.
120 void dump () const;
122 /// Declare the dynamic allocation hooks.
123 ACE_ALLOC_HOOK_DECLARE;
125 protected:
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
132 * communication.
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 ();
141 ACE_HANDLE handle_;
143 /// Data exchange channel.
144 MALLOC_TYPE *shm_malloc_;
146 /// Constructor. Prevent this class from being instantiated.
147 ACE_MEM_SAP ();
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 */