passenger 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (98) hide show
  1. data/Rakefile +7 -4
  2. data/bin/passenger-install-apache2-module +3 -1
  3. data/doc/Users guide.html +1 -1
  4. data/doc/cxxapi/ApplicationPoolClientServer_8h-source.html +1 -1
  5. data/doc/cxxapi/ApplicationPoolServer_8h-source.html +497 -496
  6. data/doc/cxxapi/ApplicationPool_8h-source.html +1 -1
  7. data/doc/cxxapi/Application_8h-source.html +1 -1
  8. data/doc/cxxapi/Configuration_8h-source.html +2 -2
  9. data/doc/cxxapi/DummySpawnManager_8h-source.html +1 -1
  10. data/doc/cxxapi/Exceptions_8h-source.html +1 -1
  11. data/doc/cxxapi/Hooks_8h-source.html +1 -1
  12. data/doc/cxxapi/Logging_8h-source.html +1 -1
  13. data/doc/cxxapi/MessageChannel_8h-source.html +224 -198
  14. data/doc/cxxapi/SpawnManager_8h-source.html +1 -1
  15. data/doc/cxxapi/StandardApplicationPool_8h-source.html +1 -1
  16. data/doc/cxxapi/Utils_8h-source.html +1 -1
  17. data/doc/cxxapi/annotated.html +1 -1
  18. data/doc/cxxapi/classClient-members.html +1 -1
  19. data/doc/cxxapi/classClient.html +1 -1
  20. data/doc/cxxapi/classPassenger_1_1Application-members.html +1 -1
  21. data/doc/cxxapi/classPassenger_1_1Application.html +1 -1
  22. data/doc/cxxapi/classPassenger_1_1ApplicationPool-members.html +1 -1
  23. data/doc/cxxapi/classPassenger_1_1ApplicationPool.html +1 -1
  24. data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer-members.html +1 -1
  25. data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer.html +1 -1
  26. data/doc/cxxapi/classPassenger_1_1Application_1_1Session-members.html +1 -1
  27. data/doc/cxxapi/classPassenger_1_1Application_1_1Session.html +1 -1
  28. data/doc/cxxapi/classPassenger_1_1ConfigurationException-members.html +1 -1
  29. data/doc/cxxapi/classPassenger_1_1ConfigurationException.html +1 -1
  30. data/doc/cxxapi/classPassenger_1_1DummySpawnManager-members.html +1 -1
  31. data/doc/cxxapi/classPassenger_1_1DummySpawnManager.html +1 -1
  32. data/doc/cxxapi/classPassenger_1_1FileNotFoundException-members.html +1 -1
  33. data/doc/cxxapi/classPassenger_1_1FileNotFoundException.html +1 -1
  34. data/doc/cxxapi/classPassenger_1_1IOException-members.html +1 -1
  35. data/doc/cxxapi/classPassenger_1_1IOException.html +1 -1
  36. data/doc/cxxapi/classPassenger_1_1MessageChannel-members.html +1 -1
  37. data/doc/cxxapi/classPassenger_1_1MessageChannel.html +1 -1
  38. data/doc/cxxapi/classPassenger_1_1SpawnException-members.html +1 -1
  39. data/doc/cxxapi/classPassenger_1_1SpawnException.html +1 -1
  40. data/doc/cxxapi/classPassenger_1_1SpawnManager-members.html +1 -1
  41. data/doc/cxxapi/classPassenger_1_1SpawnManager.html +1 -1
  42. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool-members.html +1 -1
  43. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool.html +1 -1
  44. data/doc/cxxapi/classPassenger_1_1SystemException-members.html +1 -1
  45. data/doc/cxxapi/classPassenger_1_1SystemException.html +1 -1
  46. data/doc/cxxapi/definitions_8h-source.html +1 -1
  47. data/doc/cxxapi/files.html +1 -1
  48. data/doc/cxxapi/functions.html +1 -1
  49. data/doc/cxxapi/functions_func.html +1 -1
  50. data/doc/cxxapi/functions_type.html +1 -1
  51. data/doc/cxxapi/graph_legend.html +1 -1
  52. data/doc/cxxapi/graph_legend.png +0 -0
  53. data/doc/cxxapi/group__Configuration.html +3 -3
  54. data/doc/cxxapi/group__Configuration.png +0 -0
  55. data/doc/cxxapi/group__Core.html +1 -1
  56. data/doc/cxxapi/group__Core.png +0 -0
  57. data/doc/cxxapi/group__Exceptions.html +1 -1
  58. data/doc/cxxapi/group__Hooks.html +1 -1
  59. data/doc/cxxapi/group__Hooks.png +0 -0
  60. data/doc/cxxapi/group__Support.html +1 -1
  61. data/doc/cxxapi/hierarchy.html +1 -1
  62. data/doc/cxxapi/inherit__graph__0.png +0 -0
  63. data/doc/cxxapi/inherit__graph__1.png +0 -0
  64. data/doc/cxxapi/inherit__graph__2.png +0 -0
  65. data/doc/cxxapi/inherit__graph__3.png +0 -0
  66. data/doc/cxxapi/inherit__graph__4.png +0 -0
  67. data/doc/cxxapi/inherit__graph__5.png +0 -0
  68. data/doc/cxxapi/inherit__graph__6.png +0 -0
  69. data/doc/cxxapi/inherit__graph__7.png +0 -0
  70. data/doc/cxxapi/inherit__graph__8.png +0 -0
  71. data/doc/cxxapi/inherit__graph__9.png +0 -0
  72. data/doc/cxxapi/inherits.html +1 -1
  73. data/doc/cxxapi/main.html +1 -1
  74. data/doc/cxxapi/modules.html +1 -1
  75. data/doc/cxxapi/structPassenger_1_1AnythingToString-members.html +1 -1
  76. data/doc/cxxapi/structPassenger_1_1AnythingToString.html +1 -1
  77. data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4-members.html +1 -1
  78. data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4.html +1 -1
  79. data/doc/rdoc/created.rid +1 -1
  80. data/doc/rdoc/files/DEVELOPERS_TXT.html +1 -1
  81. data/doc/rdoc/files/ext/passenger/native_support_c.html +1 -1
  82. data/doc/rdoc/files/lib/passenger/abstract_server_rb.html +1 -1
  83. data/doc/rdoc/files/lib/passenger/application_spawner_rb.html +1 -1
  84. data/doc/rdoc/files/lib/passenger/dependencies_rb.html +1 -1
  85. data/doc/rdoc/files/lib/passenger/framework_spawner_rb.html +1 -1
  86. data/doc/rdoc/files/lib/passenger/request_handler_rb.html +1 -1
  87. data/doc/rdoc/files/lib/passenger/spawn_manager_rb.html +1 -1
  88. data/doc/rdoc/files/lib/passenger/utils_rb.html +1 -1
  89. data/ext/apache2/Configuration.h +1 -1
  90. data/ext/apache2/MessageChannel.h +37 -11
  91. data/ext/passenger/native_support.c +36 -10
  92. data/lib/passenger/templates/app_exited_during_initialization.html.erb +3 -2
  93. data/lib/passenger/templates/welcome.txt.erb +1 -1
  94. data/misc/render_error_pages.rb +3 -0
  95. data/test/stub/{mycook → rails_apps/mycook}/config/environments/test.rb +0 -0
  96. metadata +12 -14
  97. data/test/stub/apache2/httpd.conf +0 -75
  98. data/test/stub/railsapp-without-version-spec/config/environments/test.rb +0 -22
@@ -182,7 +182,7 @@
182
182
  <a name="l00167"></a>00167 }; <span class="comment">// namespace Passenger</span>
183
183
  <a name="l00168"></a>00168
184
184
  <a name="l00169"></a>00169 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_APPLICATION_POOL_H_ */</span>
185
- </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu May 1 20:23:46 2008 for Passenger by&nbsp;
185
+ </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed May 7 20:28:18 2008 for Passenger by&nbsp;
186
186
  <a href="http://www.doxygen.org/index.html">
187
187
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
188
188
  </body>
@@ -395,7 +395,7 @@
395
395
  <a name="l00380"></a>00380 } <span class="comment">// namespace Passenger</span>
396
396
  <a name="l00381"></a>00381
397
397
  <a name="l00382"></a>00382 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_APPLICATION_H_ */</span>
398
- </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu May 1 20:23:46 2008 for Passenger by&nbsp;
398
+ </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed May 7 20:28:18 2008 for Passenger by&nbsp;
399
399
  <a href="http://www.doxygen.org/index.html">
400
400
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
401
401
  </body>
@@ -44,7 +44,7 @@
44
44
  <a name="l00029"></a>00029 <span class="comment"> */</span>
45
45
  <a name="l00030"></a>00030 <span class="comment"></span>
46
46
  <a name="l00031"></a>00031 <span class="comment">/** Module version number. */</span>
47
- <a name="l00032"></a><a class="code" href="group__Configuration.html#ga19398896775408d6ab7fd8ce2acd992">00032</a> <span class="preprocessor">#define PASSENGER_VERSION "1.0.4"</span>
47
+ <a name="l00032"></a><a class="code" href="group__Configuration.html#ga19398896775408d6ab7fd8ce2acd992">00032</a> <span class="preprocessor">#define PASSENGER_VERSION "1.0.5"</span>
48
48
  <a name="l00033"></a>00033 <span class="preprocessor"></span>
49
49
  <a name="l00034"></a>00034 <span class="preprocessor">#ifdef __cplusplus</span>
50
50
  <a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor"> #include &lt;set&gt;</span>
@@ -138,7 +138,7 @@
138
138
  <a name="l00123"></a>00123 <span class="comment"> */</span>
139
139
  <a name="l00124"></a>00124
140
140
  <a name="l00125"></a>00125 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_CONFIGURATION_H_ */</span>
141
- </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu May 1 20:23:46 2008 for Passenger by&nbsp;
141
+ </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed May 7 20:28:18 2008 for Passenger by&nbsp;
142
142
  <a href="http://www.doxygen.org/index.html">
143
143
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
144
144
  </body>
@@ -114,7 +114,7 @@
114
114
  <a name="l00099"></a>00099 } <span class="comment">// namespace Passenger</span>
115
115
  <a name="l00100"></a>00100
116
116
  <a name="l00101"></a>00101 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_DUMMY_SPAWN_MANAGER_H_ */</span>
117
- </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu May 1 20:23:46 2008 for Passenger by&nbsp;
117
+ </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed May 7 20:28:18 2008 for Passenger by&nbsp;
118
118
  <a href="http://www.doxygen.org/index.html">
119
119
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
120
120
  </body>
@@ -181,7 +181,7 @@
181
181
  <a name="l00166"></a>00166 } <span class="comment">// namespace Passenger</span>
182
182
  <a name="l00167"></a>00167
183
183
  <a name="l00168"></a>00168 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_EXCEPTIONS_H_ */</span>
184
- </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu May 1 20:23:46 2008 for Passenger by&nbsp;
184
+ </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed May 7 20:28:18 2008 for Passenger by&nbsp;
185
185
  <a href="http://www.doxygen.org/index.html">
186
186
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
187
187
  </body>
@@ -51,7 +51,7 @@
51
51
  <a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
52
52
  <a name="l00037"></a>00037 <span class="preprocessor"></span>
53
53
  <a name="l00038"></a>00038 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_HOOKS_H_ */</span>
54
- </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu May 1 20:23:46 2008 for Passenger by&nbsp;
54
+ </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed May 7 20:28:18 2008 for Passenger by&nbsp;
55
55
  <a href="http://www.doxygen.org/index.html">
56
56
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
57
57
  </body>
@@ -96,7 +96,7 @@
96
96
  <a name="l00081"></a>00081
97
97
  <a name="l00082"></a>00082 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_LOGGING_H_ */</span>
98
98
  <a name="l00083"></a>00083
99
- </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu May 1 20:23:46 2008 for Passenger by&nbsp;
99
+ </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed May 7 20:28:18 2008 for Passenger by&nbsp;
100
100
  <a href="http://www.doxygen.org/index.html">
101
101
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
102
102
  </body>
@@ -274,205 +274,231 @@
274
274
  <a name="l00259"></a>00259 <span class="keyword">struct </span>msghdr msg;
275
275
  <a name="l00260"></a>00260 <span class="keyword">struct </span>iovec vec;
276
276
  <a name="l00261"></a>00261 <span class="keywordtype">char</span> dummy[1];
277
- <a name="l00262"></a>00262 <span class="keywordtype">char</span> control_data[CMSG_SPACE(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>))];
278
- <a name="l00263"></a>00263 <span class="keyword">struct </span>cmsghdr *control_header;
279
- <a name="l00264"></a>00264
280
- <a name="l00265"></a>00265 msg.msg_name = NULL;
281
- <a name="l00266"></a>00266 msg.msg_namelen = 0;
282
- <a name="l00267"></a>00267
283
- <a name="l00268"></a>00268 <span class="comment">/* Linux and Solaris require msg_iov to be non-NULL. */</span>
284
- <a name="l00269"></a>00269 dummy[0] = <span class="charliteral">'\0'</span>;
285
- <a name="l00270"></a>00270 vec.iov_base = dummy;
286
- <a name="l00271"></a>00271 vec.iov_len = <span class="keyword">sizeof</span>(dummy);
287
- <a name="l00272"></a>00272 msg.msg_iov = &amp;vec;
288
- <a name="l00273"></a>00273 msg.msg_iovlen = 1;
277
+ <a name="l00262"></a>00262 <span class="preprocessor"> #ifdef __APPLE__</span>
278
+ <a name="l00263"></a>00263 <span class="preprocessor"></span> <span class="keyword">struct </span>{
279
+ <a name="l00264"></a>00264 <span class="keyword">struct </span>cmsghdr header;
280
+ <a name="l00265"></a>00265 <span class="keywordtype">int</span> fd;
281
+ <a name="l00266"></a>00266 } control_data;
282
+ <a name="l00267"></a>00267 <span class="preprocessor"> #else</span>
283
+ <a name="l00268"></a>00268 <span class="preprocessor"></span> <span class="keywordtype">char</span> control_data[CMSG_SPACE(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>))];
284
+ <a name="l00269"></a>00269 <span class="preprocessor"> #endif</span>
285
+ <a name="l00270"></a>00270 <span class="preprocessor"></span> <span class="keyword">struct </span>cmsghdr *control_header;
286
+ <a name="l00271"></a>00271
287
+ <a name="l00272"></a>00272 msg.msg_name = NULL;
288
+ <a name="l00273"></a>00273 msg.msg_namelen = 0;
289
289
  <a name="l00274"></a>00274
290
- <a name="l00275"></a>00275 msg.msg_control = (caddr_t) control_data;
291
- <a name="l00276"></a>00276 msg.msg_controllen = <span class="keyword">sizeof</span>(control_data);
292
- <a name="l00277"></a>00277 msg.msg_flags = 0;
293
- <a name="l00278"></a>00278
294
- <a name="l00279"></a>00279 control_header = CMSG_FIRSTHDR(&amp;msg);
295
- <a name="l00280"></a>00280 control_header-&gt;cmsg_len = CMSG_LEN(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
296
- <a name="l00281"></a>00281 control_header-&gt;cmsg_level = SOL_SOCKET;
297
- <a name="l00282"></a>00282 control_header-&gt;cmsg_type = SCM_RIGHTS;
298
- <a name="l00283"></a>00283 memcpy(CMSG_DATA(control_header), &amp;fileDescriptor, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
299
- <a name="l00284"></a>00284
300
- <a name="l00285"></a>00285 <span class="keywordflow">if</span> (sendmsg(fd, &amp;msg, 0) == -1) {
301
- <a name="l00286"></a>00286 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"Cannot send file descriptor with sendmsg()"</span>, errno);
302
- <a name="l00287"></a>00287 }
303
- <a name="l00288"></a>00288 }
304
- <a name="l00289"></a>00289 <span class="comment"></span>
305
- <a name="l00290"></a>00290 <span class="comment"> /**</span>
306
- <a name="l00291"></a>00291 <span class="comment"> * Read an array message from the underlying file descriptor.</span>
307
- <a name="l00292"></a>00292 <span class="comment"> *</span>
308
- <a name="l00293"></a>00293 <span class="comment"> * @param args The message will be put in this variable.</span>
309
- <a name="l00294"></a>00294 <span class="comment"> * @return Whether end-of-file has been reached. If so, then the contents</span>
310
- <a name="l00295"></a>00295 <span class="comment"> * of &lt;tt&gt;args&lt;/tt&gt; will be undefined.</span>
311
- <a name="l00296"></a>00296 <span class="comment"> * @throws SystemException If an error occured while receiving the message.</span>
312
- <a name="l00297"></a>00297 <span class="comment"> * @see write()</span>
313
- <a name="l00298"></a>00298 <span class="comment"> */</span>
314
- <a name="l00299"></a><a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e">00299</a> <span class="keywordtype">bool</span> <a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e" title="Read an array message from the underlying file descriptor.">read</a>(vector&lt;string&gt; &amp;args) {
315
- <a name="l00300"></a>00300 uint16_t size;
316
- <a name="l00301"></a>00301 <span class="keywordtype">int</span> ret;
317
- <a name="l00302"></a>00302 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> alreadyRead = 0;
318
- <a name="l00303"></a>00303
319
- <a name="l00304"></a>00304 <span class="keywordflow">do</span> {
320
- <a name="l00305"></a>00305 <span class="keywordflow">do</span> {
321
- <a name="l00306"></a>00306 ret =<a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e" title="Read an array message from the underlying file descriptor."> ::read</a>(fd, (<span class="keywordtype">char</span> *) &amp;size + alreadyRead, <span class="keyword">sizeof</span>(size) - alreadyRead);
322
- <a name="l00307"></a>00307 } <span class="keywordflow">while</span> (ret == -1 &amp;&amp; errno == EINTR);
323
- <a name="l00308"></a>00308 <span class="keywordflow">if</span> (ret == -1) {
324
- <a name="l00309"></a>00309 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"read() failed"</span>, errno);
325
- <a name="l00310"></a>00310 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ret == 0) {
326
- <a name="l00311"></a>00311 <span class="keywordflow">return</span> <span class="keyword">false</span>;
327
- <a name="l00312"></a>00312 }
328
- <a name="l00313"></a>00313 alreadyRead += ret;
329
- <a name="l00314"></a>00314 } <span class="keywordflow">while</span> (alreadyRead &lt; <span class="keyword">sizeof</span>(size));
330
- <a name="l00315"></a>00315 size = ntohs(size);
331
- <a name="l00316"></a>00316
332
- <a name="l00317"></a>00317 <span class="keywordtype">string</span> buffer;
333
- <a name="l00318"></a>00318 args.clear();
334
- <a name="l00319"></a>00319 buffer.reserve(size);
335
- <a name="l00320"></a>00320 <span class="keywordflow">while</span> (buffer.size() &lt; size) {
336
- <a name="l00321"></a>00321 <span class="keywordtype">char</span> tmp[1024 * 8];
337
- <a name="l00322"></a>00322 <span class="keywordflow">do</span> {
338
- <a name="l00323"></a>00323 ret =<a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e" title="Read an array message from the underlying file descriptor."> ::read</a>(fd, tmp, min(size - buffer.size(), <span class="keyword">sizeof</span>(tmp)));
339
- <a name="l00324"></a>00324 } <span class="keywordflow">while</span> (ret == -1 &amp;&amp; errno == EINTR);
340
- <a name="l00325"></a>00325 <span class="keywordflow">if</span> (ret == -1) {
341
- <a name="l00326"></a>00326 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"read() failed"</span>, errno);
342
- <a name="l00327"></a>00327 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ret == 0) {
343
- <a name="l00328"></a>00328 <span class="keywordflow">return</span> <span class="keyword">false</span>;
344
- <a name="l00329"></a>00329 }
345
- <a name="l00330"></a>00330 buffer.append(tmp, ret);
346
- <a name="l00331"></a>00331 }
347
- <a name="l00332"></a>00332
348
- <a name="l00333"></a>00333 <span class="keywordflow">if</span> (!buffer.empty()) {
349
- <a name="l00334"></a>00334 string::size_type start = 0, pos;
350
- <a name="l00335"></a>00335 <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;const_buffer(buffer);
351
- <a name="l00336"></a>00336 <span class="keywordflow">while</span> ((pos = const_buffer.find(<span class="charliteral">'\0'</span>, start)) != string::npos) {
352
- <a name="l00337"></a>00337 args.push_back(const_buffer.substr(start, pos - start));
353
- <a name="l00338"></a>00338 start = pos + 1;
354
- <a name="l00339"></a>00339 }
355
- <a name="l00340"></a>00340 }
356
- <a name="l00341"></a>00341 <span class="keywordflow">return</span> <span class="keyword">true</span>;
357
- <a name="l00342"></a>00342 }
358
- <a name="l00343"></a>00343 <span class="comment"></span>
359
- <a name="l00344"></a>00344 <span class="comment"> /**</span>
360
- <a name="l00345"></a>00345 <span class="comment"> * Read a scalar message from the underlying file descriptor.</span>
361
- <a name="l00346"></a>00346 <span class="comment"> *</span>
362
- <a name="l00347"></a>00347 <span class="comment"> * @param output The message will be put in here.</span>
363
- <a name="l00348"></a>00348 <span class="comment"> * @returns Whether end-of-file was reached during reading.</span>
364
- <a name="l00349"></a>00349 <span class="comment"> * @throws SystemException An error occured while writing the data to the file descriptor.</span>
365
- <a name="l00350"></a>00350 <span class="comment"> * @see writeScalar()</span>
366
- <a name="l00351"></a>00351 <span class="comment"> */</span>
367
- <a name="l00352"></a><a class="code" href="classPassenger_1_1MessageChannel.html#4ce6a0e751b5e3563bee583c231569bc">00352</a> <span class="keywordtype">bool</span> <a class="code" href="classPassenger_1_1MessageChannel.html#4ce6a0e751b5e3563bee583c231569bc" title="Read a scalar message from the underlying file descriptor.">readScalar</a>(<span class="keywordtype">string</span> &amp;output) {
368
- <a name="l00353"></a>00353 uint32_t size;
369
- <a name="l00354"></a>00354 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> remaining;
370
- <a name="l00355"></a>00355
371
- <a name="l00356"></a>00356 <span class="keywordflow">if</span> (!<a class="code" href="classPassenger_1_1MessageChannel.html#cd1d1bd1cc787784c8b54f5471fff479" title="Read exactly size bytes of data from the underlying file descriptor, and put the...">readRaw</a>(&amp;size, <span class="keyword">sizeof</span>(uint32_t))) {
372
- <a name="l00357"></a>00357 <span class="keywordflow">return</span> <span class="keyword">false</span>;
373
- <a name="l00358"></a>00358 }
374
- <a name="l00359"></a>00359 size = ntohl(size);
375
- <a name="l00360"></a>00360
376
- <a name="l00361"></a>00361 output.clear();
377
- <a name="l00362"></a>00362 output.reserve(size);
378
- <a name="l00363"></a>00363 remaining = size;
379
- <a name="l00364"></a>00364 <span class="keywordflow">while</span> (remaining &gt; 0) {
380
- <a name="l00365"></a>00365 <span class="keywordtype">char</span> buf[1024 * 32];
381
- <a name="l00366"></a>00366 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> blockSize = min((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) <span class="keyword">sizeof</span>(buf), remaining);
382
- <a name="l00367"></a>00367
383
- <a name="l00368"></a>00368 <span class="keywordflow">if</span> (!<a class="code" href="classPassenger_1_1MessageChannel.html#cd1d1bd1cc787784c8b54f5471fff479" title="Read exactly size bytes of data from the underlying file descriptor, and put the...">readRaw</a>(buf, blockSize)) {
384
- <a name="l00369"></a>00369 <span class="keywordflow">return</span> <span class="keyword">false</span>;
385
- <a name="l00370"></a>00370 }
386
- <a name="l00371"></a>00371 output.append(buf, blockSize);
387
- <a name="l00372"></a>00372 remaining -= blockSize;
388
- <a name="l00373"></a>00373 }
389
- <a name="l00374"></a>00374 <span class="keywordflow">return</span> <span class="keyword">true</span>;
390
- <a name="l00375"></a>00375 }
391
- <a name="l00376"></a>00376 <span class="comment"></span>
392
- <a name="l00377"></a>00377 <span class="comment"> /**</span>
393
- <a name="l00378"></a>00378 <span class="comment"> * Read exactly &lt;tt&gt;size&lt;/tt&gt; bytes of data from the underlying file descriptor,</span>
394
- <a name="l00379"></a>00379 <span class="comment"> * and put the result in &lt;tt&gt;buf&lt;/tt&gt;. If end-of-file has been reached, or if</span>
395
- <a name="l00380"></a>00380 <span class="comment"> * end-of-file was encountered before &lt;tt&gt;size&lt;/tt&gt; bytes have been read, then</span>
396
- <a name="l00381"></a>00381 <span class="comment"> * &lt;tt&gt;false&lt;/tt&gt; will be returned. Otherwise (i.e. if the read was successful),</span>
397
- <a name="l00382"></a>00382 <span class="comment"> * &lt;tt&gt;true&lt;/tt&gt; will be returned.</span>
398
- <a name="l00383"></a>00383 <span class="comment"> *</span>
399
- <a name="l00384"></a>00384 <span class="comment"> * @param buf The buffer to place the read data in. This buffer must be at least</span>
400
- <a name="l00385"></a>00385 <span class="comment"> * &lt;tt&gt;size&lt;/tt&gt; bytes long.</span>
401
- <a name="l00386"></a>00386 <span class="comment"> * @param size The number of bytes to read.</span>
402
- <a name="l00387"></a>00387 <span class="comment"> * @return Whether reading was successful or whether EOF was reached.</span>
403
- <a name="l00388"></a>00388 <span class="comment"> * @pre buf != NULL</span>
404
- <a name="l00389"></a>00389 <span class="comment"> * @throws SystemException Something went wrong during reading.</span>
405
- <a name="l00390"></a>00390 <span class="comment"> * @see writeRaw()</span>
406
- <a name="l00391"></a>00391 <span class="comment"> */</span>
407
- <a name="l00392"></a><a class="code" href="classPassenger_1_1MessageChannel.html#cd1d1bd1cc787784c8b54f5471fff479">00392</a> <span class="keywordtype">bool</span> <a class="code" href="classPassenger_1_1MessageChannel.html#cd1d1bd1cc787784c8b54f5471fff479" title="Read exactly size bytes of data from the underlying file descriptor, and put the...">readRaw</a>(<span class="keywordtype">void</span> *buf, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size) {
408
- <a name="l00393"></a>00393 ssize_t ret;
409
- <a name="l00394"></a>00394 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> alreadyRead = 0;
410
- <a name="l00395"></a>00395
411
- <a name="l00396"></a>00396 <span class="keywordflow">while</span> (alreadyRead &lt; size) {
412
- <a name="l00397"></a>00397 <span class="keywordflow">do</span> {
413
- <a name="l00398"></a>00398 ret =<a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e" title="Read an array message from the underlying file descriptor."> ::read</a>(fd, (<span class="keywordtype">char</span> *) buf + alreadyRead, size - alreadyRead);
414
- <a name="l00399"></a>00399 } <span class="keywordflow">while</span> (ret == -1 &amp;&amp; errno == EINTR);
415
- <a name="l00400"></a>00400 <span class="keywordflow">if</span> (ret == -1) {
416
- <a name="l00401"></a>00401 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"read() failed"</span>, errno);
417
- <a name="l00402"></a>00402 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ret == 0) {
418
- <a name="l00403"></a>00403 <span class="keywordflow">return</span> <span class="keyword">false</span>;
419
- <a name="l00404"></a>00404 } <span class="keywordflow">else</span> {
420
- <a name="l00405"></a>00405 alreadyRead += ret;
421
- <a name="l00406"></a>00406 }
422
- <a name="l00407"></a>00407 }
423
- <a name="l00408"></a>00408 <span class="keywordflow">return</span> <span class="keyword">true</span>;
424
- <a name="l00409"></a>00409 }
425
- <a name="l00410"></a>00410 <span class="comment"></span>
426
- <a name="l00411"></a>00411 <span class="comment"> /**</span>
427
- <a name="l00412"></a>00412 <span class="comment"> * Receive a file descriptor, which had been passed over the underlying</span>
428
- <a name="l00413"></a>00413 <span class="comment"> * file descriptor.</span>
429
- <a name="l00414"></a>00414 <span class="comment"> *</span>
430
- <a name="l00415"></a>00415 <span class="comment"> * @return The passed file descriptor.</span>
431
- <a name="l00416"></a>00416 <span class="comment"> * @throws SystemException If something went wrong during the</span>
432
- <a name="l00417"></a>00417 <span class="comment"> * receiving of a file descriptor. Perhaps the underlying</span>
433
- <a name="l00418"></a>00418 <span class="comment"> * file descriptor isn't a Unix socket.</span>
434
- <a name="l00419"></a>00419 <span class="comment"> * @throws IOException Whatever was received doesn't seem to be a</span>
435
- <a name="l00420"></a>00420 <span class="comment"> * file descriptor.</span>
436
- <a name="l00421"></a>00421 <span class="comment"> */</span>
437
- <a name="l00422"></a><a class="code" href="classPassenger_1_1MessageChannel.html#1561b7e4a0f4d39ea431f456e5655488">00422</a> <span class="keywordtype">int</span> <a class="code" href="classPassenger_1_1MessageChannel.html#1561b7e4a0f4d39ea431f456e5655488" title="Receive a file descriptor, which had been passed over the underlying file descriptor...">readFileDescriptor</a>() {
438
- <a name="l00423"></a>00423 <span class="keyword">struct </span>msghdr msg;
439
- <a name="l00424"></a>00424 <span class="keyword">struct </span>iovec vec;
440
- <a name="l00425"></a>00425 <span class="keywordtype">char</span> dummy[1];
441
- <a name="l00426"></a>00426 <span class="keywordtype">char</span> control_data[CMSG_SPACE(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>))];
442
- <a name="l00427"></a>00427 <span class="keyword">struct </span>cmsghdr *control_header;
443
- <a name="l00428"></a>00428
444
- <a name="l00429"></a>00429 msg.msg_name = NULL;
445
- <a name="l00430"></a>00430 msg.msg_namelen = 0;
446
- <a name="l00431"></a>00431
447
- <a name="l00432"></a>00432 dummy[0] = <span class="charliteral">'\0'</span>;
448
- <a name="l00433"></a>00433 vec.iov_base = dummy;
449
- <a name="l00434"></a>00434 vec.iov_len = <span class="keyword">sizeof</span>(dummy);
450
- <a name="l00435"></a>00435 msg.msg_iov = &amp;vec;
451
- <a name="l00436"></a>00436 msg.msg_iovlen = 1;
452
- <a name="l00437"></a>00437
453
- <a name="l00438"></a>00438 msg.msg_control = (caddr_t) control_data;
454
- <a name="l00439"></a>00439 msg.msg_controllen = <span class="keyword">sizeof</span>(control_data);
455
- <a name="l00440"></a>00440 msg.msg_flags = 0;
456
- <a name="l00441"></a>00441
457
- <a name="l00442"></a>00442 <span class="keywordflow">if</span> (recvmsg(fd, &amp;msg, 0) == -1) {
458
- <a name="l00443"></a>00443 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"Cannot read file descriptor with recvmsg()"</span>, errno);
459
- <a name="l00444"></a>00444 }
460
- <a name="l00445"></a>00445
461
- <a name="l00446"></a>00446 control_header = CMSG_FIRSTHDR(&amp;msg);
462
- <a name="l00447"></a>00447 <span class="keywordflow">if</span> (msg.msg_controllen != <span class="keyword">sizeof</span>(control_data)
463
- <a name="l00448"></a>00448 || control_header-&gt;cmsg_len != CMSG_LEN(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>))
464
- <a name="l00449"></a>00449 || control_header-&gt;cmsg_level != SOL_SOCKET
465
- <a name="l00450"></a>00450 || control_header-&gt;cmsg_type != SCM_RIGHTS) {
466
- <a name="l00451"></a>00451 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1IOException.html" title="Represents an error that occured during an I/O operation.">IOException</a>(<span class="stringliteral">"No valid file descriptor received."</span>);
467
- <a name="l00452"></a>00452 }
468
- <a name="l00453"></a>00453 <span class="keywordflow">return</span> *((<span class="keywordtype">int</span> *) CMSG_DATA(control_header));
469
- <a name="l00454"></a>00454 }
470
- <a name="l00455"></a>00455 };
471
- <a name="l00456"></a>00456
472
- <a name="l00457"></a>00457 } <span class="comment">// namespace Passenger</span>
473
- <a name="l00458"></a>00458
474
- <a name="l00459"></a>00459 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_MESSAGE_CHANNEL_H_ */</span>
475
- </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu May 1 20:23:46 2008 for Passenger by&nbsp;
290
+ <a name="l00275"></a>00275 <span class="comment">/* Linux and Solaris require msg_iov to be non-NULL. */</span>
291
+ <a name="l00276"></a>00276 dummy[0] = <span class="charliteral">'\0'</span>;
292
+ <a name="l00277"></a>00277 vec.iov_base = dummy;
293
+ <a name="l00278"></a>00278 vec.iov_len = <span class="keyword">sizeof</span>(dummy);
294
+ <a name="l00279"></a>00279 msg.msg_iov = &amp;vec;
295
+ <a name="l00280"></a>00280 msg.msg_iovlen = 1;
296
+ <a name="l00281"></a>00281
297
+ <a name="l00282"></a>00282 msg.msg_control = (caddr_t) &amp;control_data;
298
+ <a name="l00283"></a>00283 msg.msg_controllen = <span class="keyword">sizeof</span>(control_data);
299
+ <a name="l00284"></a>00284 msg.msg_flags = 0;
300
+ <a name="l00285"></a>00285
301
+ <a name="l00286"></a>00286 control_header = CMSG_FIRSTHDR(&amp;msg);
302
+ <a name="l00287"></a>00287 control_header-&gt;cmsg_level = SOL_SOCKET;
303
+ <a name="l00288"></a>00288 control_header-&gt;cmsg_type = SCM_RIGHTS;
304
+ <a name="l00289"></a>00289 <span class="preprocessor"> #ifdef __APPLE__</span>
305
+ <a name="l00290"></a>00290 <span class="preprocessor"></span> control_header-&gt;cmsg_len = <span class="keyword">sizeof</span>(control_data);
306
+ <a name="l00291"></a>00291 control_data.fd = fileDescriptor;
307
+ <a name="l00292"></a>00292 <span class="preprocessor"> #else</span>
308
+ <a name="l00293"></a>00293 <span class="preprocessor"></span> control_header-&gt;cmsg_len = CMSG_LEN(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
309
+ <a name="l00294"></a>00294 memcpy(CMSG_DATA(control_header), &amp;fileDescriptor, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
310
+ <a name="l00295"></a>00295 <span class="preprocessor"> #endif</span>
311
+ <a name="l00296"></a>00296 <span class="preprocessor"></span>
312
+ <a name="l00297"></a>00297 <span class="keywordflow">if</span> (sendmsg(fd, &amp;msg, 0) == -1) {
313
+ <a name="l00298"></a>00298 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"Cannot send file descriptor with sendmsg()"</span>, errno);
314
+ <a name="l00299"></a>00299 }
315
+ <a name="l00300"></a>00300 }
316
+ <a name="l00301"></a>00301 <span class="comment"></span>
317
+ <a name="l00302"></a>00302 <span class="comment"> /**</span>
318
+ <a name="l00303"></a>00303 <span class="comment"> * Read an array message from the underlying file descriptor.</span>
319
+ <a name="l00304"></a>00304 <span class="comment"> *</span>
320
+ <a name="l00305"></a>00305 <span class="comment"> * @param args The message will be put in this variable.</span>
321
+ <a name="l00306"></a>00306 <span class="comment"> * @return Whether end-of-file has been reached. If so, then the contents</span>
322
+ <a name="l00307"></a>00307 <span class="comment"> * of &lt;tt&gt;args&lt;/tt&gt; will be undefined.</span>
323
+ <a name="l00308"></a>00308 <span class="comment"> * @throws SystemException If an error occured while receiving the message.</span>
324
+ <a name="l00309"></a>00309 <span class="comment"> * @see write()</span>
325
+ <a name="l00310"></a>00310 <span class="comment"> */</span>
326
+ <a name="l00311"></a><a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e">00311</a> <span class="keywordtype">bool</span> <a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e" title="Read an array message from the underlying file descriptor.">read</a>(vector&lt;string&gt; &amp;args) {
327
+ <a name="l00312"></a>00312 uint16_t size;
328
+ <a name="l00313"></a>00313 <span class="keywordtype">int</span> ret;
329
+ <a name="l00314"></a>00314 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> alreadyRead = 0;
330
+ <a name="l00315"></a>00315
331
+ <a name="l00316"></a>00316 <span class="keywordflow">do</span> {
332
+ <a name="l00317"></a>00317 <span class="keywordflow">do</span> {
333
+ <a name="l00318"></a>00318 ret =<a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e" title="Read an array message from the underlying file descriptor."> ::read</a>(fd, (<span class="keywordtype">char</span> *) &amp;size + alreadyRead, <span class="keyword">sizeof</span>(size) - alreadyRead);
334
+ <a name="l00319"></a>00319 } <span class="keywordflow">while</span> (ret == -1 &amp;&amp; errno == EINTR);
335
+ <a name="l00320"></a>00320 <span class="keywordflow">if</span> (ret == -1) {
336
+ <a name="l00321"></a>00321 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"read() failed"</span>, errno);
337
+ <a name="l00322"></a>00322 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ret == 0) {
338
+ <a name="l00323"></a>00323 <span class="keywordflow">return</span> <span class="keyword">false</span>;
339
+ <a name="l00324"></a>00324 }
340
+ <a name="l00325"></a>00325 alreadyRead += ret;
341
+ <a name="l00326"></a>00326 } <span class="keywordflow">while</span> (alreadyRead &lt; <span class="keyword">sizeof</span>(size));
342
+ <a name="l00327"></a>00327 size = ntohs(size);
343
+ <a name="l00328"></a>00328
344
+ <a name="l00329"></a>00329 <span class="keywordtype">string</span> buffer;
345
+ <a name="l00330"></a>00330 args.clear();
346
+ <a name="l00331"></a>00331 buffer.reserve(size);
347
+ <a name="l00332"></a>00332 <span class="keywordflow">while</span> (buffer.size() &lt; size) {
348
+ <a name="l00333"></a>00333 <span class="keywordtype">char</span> tmp[1024 * 8];
349
+ <a name="l00334"></a>00334 <span class="keywordflow">do</span> {
350
+ <a name="l00335"></a>00335 ret =<a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e" title="Read an array message from the underlying file descriptor."> ::read</a>(fd, tmp, min(size - buffer.size(), <span class="keyword">sizeof</span>(tmp)));
351
+ <a name="l00336"></a>00336 } <span class="keywordflow">while</span> (ret == -1 &amp;&amp; errno == EINTR);
352
+ <a name="l00337"></a>00337 <span class="keywordflow">if</span> (ret == -1) {
353
+ <a name="l00338"></a>00338 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"read() failed"</span>, errno);
354
+ <a name="l00339"></a>00339 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ret == 0) {
355
+ <a name="l00340"></a>00340 <span class="keywordflow">return</span> <span class="keyword">false</span>;
356
+ <a name="l00341"></a>00341 }
357
+ <a name="l00342"></a>00342 buffer.append(tmp, ret);
358
+ <a name="l00343"></a>00343 }
359
+ <a name="l00344"></a>00344
360
+ <a name="l00345"></a>00345 <span class="keywordflow">if</span> (!buffer.empty()) {
361
+ <a name="l00346"></a>00346 string::size_type start = 0, pos;
362
+ <a name="l00347"></a>00347 <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;const_buffer(buffer);
363
+ <a name="l00348"></a>00348 <span class="keywordflow">while</span> ((pos = const_buffer.find(<span class="charliteral">'\0'</span>, start)) != string::npos) {
364
+ <a name="l00349"></a>00349 args.push_back(const_buffer.substr(start, pos - start));
365
+ <a name="l00350"></a>00350 start = pos + 1;
366
+ <a name="l00351"></a>00351 }
367
+ <a name="l00352"></a>00352 }
368
+ <a name="l00353"></a>00353 <span class="keywordflow">return</span> <span class="keyword">true</span>;
369
+ <a name="l00354"></a>00354 }
370
+ <a name="l00355"></a>00355 <span class="comment"></span>
371
+ <a name="l00356"></a>00356 <span class="comment"> /**</span>
372
+ <a name="l00357"></a>00357 <span class="comment"> * Read a scalar message from the underlying file descriptor.</span>
373
+ <a name="l00358"></a>00358 <span class="comment"> *</span>
374
+ <a name="l00359"></a>00359 <span class="comment"> * @param output The message will be put in here.</span>
375
+ <a name="l00360"></a>00360 <span class="comment"> * @returns Whether end-of-file was reached during reading.</span>
376
+ <a name="l00361"></a>00361 <span class="comment"> * @throws SystemException An error occured while writing the data to the file descriptor.</span>
377
+ <a name="l00362"></a>00362 <span class="comment"> * @see writeScalar()</span>
378
+ <a name="l00363"></a>00363 <span class="comment"> */</span>
379
+ <a name="l00364"></a><a class="code" href="classPassenger_1_1MessageChannel.html#4ce6a0e751b5e3563bee583c231569bc">00364</a> <span class="keywordtype">bool</span> <a class="code" href="classPassenger_1_1MessageChannel.html#4ce6a0e751b5e3563bee583c231569bc" title="Read a scalar message from the underlying file descriptor.">readScalar</a>(<span class="keywordtype">string</span> &amp;output) {
380
+ <a name="l00365"></a>00365 uint32_t size;
381
+ <a name="l00366"></a>00366 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> remaining;
382
+ <a name="l00367"></a>00367
383
+ <a name="l00368"></a>00368 <span class="keywordflow">if</span> (!<a class="code" href="classPassenger_1_1MessageChannel.html#cd1d1bd1cc787784c8b54f5471fff479" title="Read exactly size bytes of data from the underlying file descriptor, and put the...">readRaw</a>(&amp;size, <span class="keyword">sizeof</span>(uint32_t))) {
384
+ <a name="l00369"></a>00369 <span class="keywordflow">return</span> <span class="keyword">false</span>;
385
+ <a name="l00370"></a>00370 }
386
+ <a name="l00371"></a>00371 size = ntohl(size);
387
+ <a name="l00372"></a>00372
388
+ <a name="l00373"></a>00373 output.clear();
389
+ <a name="l00374"></a>00374 output.reserve(size);
390
+ <a name="l00375"></a>00375 remaining = size;
391
+ <a name="l00376"></a>00376 <span class="keywordflow">while</span> (remaining &gt; 0) {
392
+ <a name="l00377"></a>00377 <span class="keywordtype">char</span> buf[1024 * 32];
393
+ <a name="l00378"></a>00378 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> blockSize = min((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) <span class="keyword">sizeof</span>(buf), remaining);
394
+ <a name="l00379"></a>00379
395
+ <a name="l00380"></a>00380 <span class="keywordflow">if</span> (!<a class="code" href="classPassenger_1_1MessageChannel.html#cd1d1bd1cc787784c8b54f5471fff479" title="Read exactly size bytes of data from the underlying file descriptor, and put the...">readRaw</a>(buf, blockSize)) {
396
+ <a name="l00381"></a>00381 <span class="keywordflow">return</span> <span class="keyword">false</span>;
397
+ <a name="l00382"></a>00382 }
398
+ <a name="l00383"></a>00383 output.append(buf, blockSize);
399
+ <a name="l00384"></a>00384 remaining -= blockSize;
400
+ <a name="l00385"></a>00385 }
401
+ <a name="l00386"></a>00386 <span class="keywordflow">return</span> <span class="keyword">true</span>;
402
+ <a name="l00387"></a>00387 }
403
+ <a name="l00388"></a>00388 <span class="comment"></span>
404
+ <a name="l00389"></a>00389 <span class="comment"> /**</span>
405
+ <a name="l00390"></a>00390 <span class="comment"> * Read exactly &lt;tt&gt;size&lt;/tt&gt; bytes of data from the underlying file descriptor,</span>
406
+ <a name="l00391"></a>00391 <span class="comment"> * and put the result in &lt;tt&gt;buf&lt;/tt&gt;. If end-of-file has been reached, or if</span>
407
+ <a name="l00392"></a>00392 <span class="comment"> * end-of-file was encountered before &lt;tt&gt;size&lt;/tt&gt; bytes have been read, then</span>
408
+ <a name="l00393"></a>00393 <span class="comment"> * &lt;tt&gt;false&lt;/tt&gt; will be returned. Otherwise (i.e. if the read was successful),</span>
409
+ <a name="l00394"></a>00394 <span class="comment"> * &lt;tt&gt;true&lt;/tt&gt; will be returned.</span>
410
+ <a name="l00395"></a>00395 <span class="comment"> *</span>
411
+ <a name="l00396"></a>00396 <span class="comment"> * @param buf The buffer to place the read data in. This buffer must be at least</span>
412
+ <a name="l00397"></a>00397 <span class="comment"> * &lt;tt&gt;size&lt;/tt&gt; bytes long.</span>
413
+ <a name="l00398"></a>00398 <span class="comment"> * @param size The number of bytes to read.</span>
414
+ <a name="l00399"></a>00399 <span class="comment"> * @return Whether reading was successful or whether EOF was reached.</span>
415
+ <a name="l00400"></a>00400 <span class="comment"> * @pre buf != NULL</span>
416
+ <a name="l00401"></a>00401 <span class="comment"> * @throws SystemException Something went wrong during reading.</span>
417
+ <a name="l00402"></a>00402 <span class="comment"> * @see writeRaw()</span>
418
+ <a name="l00403"></a>00403 <span class="comment"> */</span>
419
+ <a name="l00404"></a><a class="code" href="classPassenger_1_1MessageChannel.html#cd1d1bd1cc787784c8b54f5471fff479">00404</a> <span class="keywordtype">bool</span> <a class="code" href="classPassenger_1_1MessageChannel.html#cd1d1bd1cc787784c8b54f5471fff479" title="Read exactly size bytes of data from the underlying file descriptor, and put the...">readRaw</a>(<span class="keywordtype">void</span> *buf, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size) {
420
+ <a name="l00405"></a>00405 ssize_t ret;
421
+ <a name="l00406"></a>00406 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> alreadyRead = 0;
422
+ <a name="l00407"></a>00407
423
+ <a name="l00408"></a>00408 <span class="keywordflow">while</span> (alreadyRead &lt; size) {
424
+ <a name="l00409"></a>00409 <span class="keywordflow">do</span> {
425
+ <a name="l00410"></a>00410 ret =<a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e" title="Read an array message from the underlying file descriptor."> ::read</a>(fd, (<span class="keywordtype">char</span> *) buf + alreadyRead, size - alreadyRead);
426
+ <a name="l00411"></a>00411 } <span class="keywordflow">while</span> (ret == -1 &amp;&amp; errno == EINTR);
427
+ <a name="l00412"></a>00412 <span class="keywordflow">if</span> (ret == -1) {
428
+ <a name="l00413"></a>00413 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"read() failed"</span>, errno);
429
+ <a name="l00414"></a>00414 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ret == 0) {
430
+ <a name="l00415"></a>00415 <span class="keywordflow">return</span> <span class="keyword">false</span>;
431
+ <a name="l00416"></a>00416 } <span class="keywordflow">else</span> {
432
+ <a name="l00417"></a>00417 alreadyRead += ret;
433
+ <a name="l00418"></a>00418 }
434
+ <a name="l00419"></a>00419 }
435
+ <a name="l00420"></a>00420 <span class="keywordflow">return</span> <span class="keyword">true</span>;
436
+ <a name="l00421"></a>00421 }
437
+ <a name="l00422"></a>00422 <span class="comment"></span>
438
+ <a name="l00423"></a>00423 <span class="comment"> /**</span>
439
+ <a name="l00424"></a>00424 <span class="comment"> * Receive a file descriptor, which had been passed over the underlying</span>
440
+ <a name="l00425"></a>00425 <span class="comment"> * file descriptor.</span>
441
+ <a name="l00426"></a>00426 <span class="comment"> *</span>
442
+ <a name="l00427"></a>00427 <span class="comment"> * @return The passed file descriptor.</span>
443
+ <a name="l00428"></a>00428 <span class="comment"> * @throws SystemException If something went wrong during the</span>
444
+ <a name="l00429"></a>00429 <span class="comment"> * receiving of a file descriptor. Perhaps the underlying</span>
445
+ <a name="l00430"></a>00430 <span class="comment"> * file descriptor isn't a Unix socket.</span>
446
+ <a name="l00431"></a>00431 <span class="comment"> * @throws IOException Whatever was received doesn't seem to be a</span>
447
+ <a name="l00432"></a>00432 <span class="comment"> * file descriptor.</span>
448
+ <a name="l00433"></a>00433 <span class="comment"> */</span>
449
+ <a name="l00434"></a><a class="code" href="classPassenger_1_1MessageChannel.html#1561b7e4a0f4d39ea431f456e5655488">00434</a> <span class="keywordtype">int</span> <a class="code" href="classPassenger_1_1MessageChannel.html#1561b7e4a0f4d39ea431f456e5655488" title="Receive a file descriptor, which had been passed over the underlying file descriptor...">readFileDescriptor</a>() {
450
+ <a name="l00435"></a>00435 <span class="keyword">struct </span>msghdr msg;
451
+ <a name="l00436"></a>00436 <span class="keyword">struct </span>iovec vec;
452
+ <a name="l00437"></a>00437 <span class="keywordtype">char</span> dummy[1];
453
+ <a name="l00438"></a>00438 <span class="preprocessor"> #ifdef __APPLE__</span>
454
+ <a name="l00439"></a>00439 <span class="preprocessor"></span> <span class="comment">// File descriptor passing macros (CMSG_*) seem to be broken</span>
455
+ <a name="l00440"></a>00440 <span class="comment">// on 64-bit MacOS X. This structure works around the problem.</span>
456
+ <a name="l00441"></a>00441 <span class="keyword">struct </span>{
457
+ <a name="l00442"></a>00442 <span class="keyword">struct </span>cmsghdr header;
458
+ <a name="l00443"></a>00443 <span class="keywordtype">int</span> fd;
459
+ <a name="l00444"></a>00444 } control_data;
460
+ <a name="l00445"></a>00445 <span class="preprocessor"> #define EXPECTED_CMSG_LEN sizeof(control_data)</span>
461
+ <a name="l00446"></a>00446 <span class="preprocessor"></span><span class="preprocessor"> #else</span>
462
+ <a name="l00447"></a>00447 <span class="preprocessor"></span> <span class="keywordtype">char</span> control_data[CMSG_SPACE(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>))];
463
+ <a name="l00448"></a>00448 <span class="preprocessor"> #define EXPECTED_CMSG_LEN CMSG_LEN(sizeof(int))</span>
464
+ <a name="l00449"></a>00449 <span class="preprocessor"></span><span class="preprocessor"> #endif</span>
465
+ <a name="l00450"></a>00450 <span class="preprocessor"></span> <span class="keyword">struct </span>cmsghdr *control_header;
466
+ <a name="l00451"></a>00451
467
+ <a name="l00452"></a>00452 msg.msg_name = NULL;
468
+ <a name="l00453"></a>00453 msg.msg_namelen = 0;
469
+ <a name="l00454"></a>00454
470
+ <a name="l00455"></a>00455 dummy[0] = <span class="charliteral">'\0'</span>;
471
+ <a name="l00456"></a>00456 vec.iov_base = dummy;
472
+ <a name="l00457"></a>00457 vec.iov_len = <span class="keyword">sizeof</span>(dummy);
473
+ <a name="l00458"></a>00458 msg.msg_iov = &amp;vec;
474
+ <a name="l00459"></a>00459 msg.msg_iovlen = 1;
475
+ <a name="l00460"></a>00460
476
+ <a name="l00461"></a>00461 msg.msg_control = (caddr_t) &amp;control_data;
477
+ <a name="l00462"></a>00462 msg.msg_controllen = <span class="keyword">sizeof</span>(control_data);
478
+ <a name="l00463"></a>00463 msg.msg_flags = 0;
479
+ <a name="l00464"></a>00464
480
+ <a name="l00465"></a>00465 <span class="keywordflow">if</span> (recvmsg(fd, &amp;msg, 0) == -1) {
481
+ <a name="l00466"></a>00466 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"Cannot read file descriptor with recvmsg()"</span>, errno);
482
+ <a name="l00467"></a>00467 }
483
+ <a name="l00468"></a>00468
484
+ <a name="l00469"></a>00469 control_header = CMSG_FIRSTHDR(&amp;msg);
485
+ <a name="l00470"></a>00470 <span class="keywordflow">if</span> (control_header-&gt;cmsg_len != EXPECTED_CMSG_LEN
486
+ <a name="l00471"></a>00471 || control_header-&gt;cmsg_level != SOL_SOCKET
487
+ <a name="l00472"></a>00472 || control_header-&gt;cmsg_type != SCM_RIGHTS) {
488
+ <a name="l00473"></a>00473 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1IOException.html" title="Represents an error that occured during an I/O operation.">IOException</a>(<span class="stringliteral">"No valid file descriptor received."</span>);
489
+ <a name="l00474"></a>00474 }
490
+ <a name="l00475"></a>00475 <span class="preprocessor"> #ifdef __APPLE__</span>
491
+ <a name="l00476"></a>00476 <span class="preprocessor"></span> <span class="keywordflow">return</span> control_data.fd;
492
+ <a name="l00477"></a>00477 <span class="preprocessor"> #else</span>
493
+ <a name="l00478"></a>00478 <span class="preprocessor"></span> <span class="keywordflow">return</span> *((<span class="keywordtype">int</span> *) CMSG_DATA(control_header));
494
+ <a name="l00479"></a>00479 <span class="preprocessor"> #endif</span>
495
+ <a name="l00480"></a>00480 <span class="preprocessor"></span> }
496
+ <a name="l00481"></a>00481 };
497
+ <a name="l00482"></a>00482
498
+ <a name="l00483"></a>00483 } <span class="comment">// namespace Passenger</span>
499
+ <a name="l00484"></a>00484
500
+ <a name="l00485"></a>00485 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_MESSAGE_CHANNEL_H_ */</span>
501
+ </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed May 7 20:28:18 2008 for Passenger by&nbsp;
476
502
  <a href="http://www.doxygen.org/index.html">
477
503
  <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
478
504
  </body>