Last change
on this file since 2697 was
885,
checked in by rlacroix, 9 years ago
|
Ensure the server buffers are large enough so that the corresponding client buffers can always fit.
This helps fixing the issue described in ticket #91.
|
-
Property copyright set to
Software name : XIOS (Xml I/O Server) http://forge.ipsl.jussieu.fr/ioserver Creation date : January 2009 Licence : CeCCIL version2 see license file in root directory : Licence_CeCILL_V2-en.txt or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement) CNRS/IPSL (Institut Pierre Simon Laplace) Project Manager : Yann Meurdesoif yann.meurdesoif@cea.fr
-
Property svn:eol-style set to
native
|
File size:
2.8 KB
|
Line | |
---|
1 | #include "xios_spl.hpp" |
---|
2 | #include "exception.hpp" |
---|
3 | #include "buffer_server.hpp" |
---|
4 | |
---|
5 | |
---|
6 | namespace xios |
---|
7 | { |
---|
8 | |
---|
9 | CServerBuffer::CServerBuffer(StdSize buffSize) |
---|
10 | { |
---|
11 | size = 3 * buffSize; |
---|
12 | first = 0; |
---|
13 | current = 1; |
---|
14 | end = size; |
---|
15 | buffer = new char[size]; // use MPI_ALLOC_MEM later? |
---|
16 | } |
---|
17 | |
---|
18 | CServerBuffer::~CServerBuffer() |
---|
19 | { |
---|
20 | delete [] buffer ; |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | bool CServerBuffer::isBufferFree(size_t count) |
---|
25 | { |
---|
26 | bool ret ; |
---|
27 | |
---|
28 | if (count==0) return true ; |
---|
29 | |
---|
30 | if (current>first) |
---|
31 | { |
---|
32 | if (current+count<size) |
---|
33 | { |
---|
34 | ret=true ; |
---|
35 | } |
---|
36 | else if (current+count==size) |
---|
37 | { |
---|
38 | if (first>0) |
---|
39 | { |
---|
40 | ret=true ; |
---|
41 | } |
---|
42 | else |
---|
43 | { |
---|
44 | ret=false ; |
---|
45 | } |
---|
46 | } |
---|
47 | else |
---|
48 | { |
---|
49 | if (count<first) |
---|
50 | { |
---|
51 | ret=true ; |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | ret=false ; |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | if (current+count<first) |
---|
62 | { |
---|
63 | ret=true ; |
---|
64 | } |
---|
65 | else |
---|
66 | { |
---|
67 | ret=false ; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | return ret ; |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | void* CServerBuffer::getBuffer(size_t count) |
---|
76 | { |
---|
77 | char* ret ; |
---|
78 | |
---|
79 | if (count==0) return buffer+current ; |
---|
80 | |
---|
81 | if (current>first) |
---|
82 | { |
---|
83 | if (current+count<size) |
---|
84 | { |
---|
85 | ret=buffer+current ; |
---|
86 | current+=count ; |
---|
87 | } |
---|
88 | else if (current+count==size) |
---|
89 | { |
---|
90 | if (first>0) |
---|
91 | { |
---|
92 | ret=buffer+current ; |
---|
93 | current=0 ; |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | ERROR("void* CServerBuffer::getBuffer(size_t count)", |
---|
98 | <<"cannot allocate required size in buffer") ; |
---|
99 | } |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | end=current ; |
---|
104 | if (count<first) |
---|
105 | { |
---|
106 | ret=buffer ; |
---|
107 | current=count ; |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | ERROR("void* CServerBuffer::getBuffer(size_t count)", |
---|
112 | <<"cannot allocate required size in buffer") ; |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | else |
---|
117 | { |
---|
118 | if (current+count<first) |
---|
119 | { |
---|
120 | ret=buffer+current ; |
---|
121 | current+=count ; |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | ERROR("void* CServerBuffer::getBuffer(size_t count)", |
---|
126 | <<"cannot allocate required size in buffer") ; |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | return ret ; |
---|
131 | } |
---|
132 | |
---|
133 | void CServerBuffer::freeBuffer(size_t count) |
---|
134 | { |
---|
135 | if (count==0) return ; |
---|
136 | |
---|
137 | if (first==end-1) |
---|
138 | { |
---|
139 | first=0 ; |
---|
140 | count-- ; |
---|
141 | end=size ; |
---|
142 | } |
---|
143 | |
---|
144 | if (first<=current) |
---|
145 | { |
---|
146 | if (first+count <current) |
---|
147 | { |
---|
148 | first+=count ; |
---|
149 | } |
---|
150 | else |
---|
151 | { |
---|
152 | ERROR("void CServerBuffer::freeBuffer(size_t count)", |
---|
153 | <<"cannot free required size in buffer") ; |
---|
154 | } |
---|
155 | |
---|
156 | } |
---|
157 | else |
---|
158 | { |
---|
159 | if (first+count<end) |
---|
160 | { |
---|
161 | first+=count ; |
---|
162 | } |
---|
163 | else |
---|
164 | { |
---|
165 | ERROR("void CServerBuffer::freeBuffer(size_t count)", |
---|
166 | <<"cannot free required size in buffer") ; |
---|
167 | } |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.