transactd 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/{BUILD_UNIX-JA → BUILD_UNIX-JA.md} +6 -6
  3. data/CMakeLists.txt +20 -15
  4. data/{README-JA → README-JA.md} +23 -23
  5. data/{README → README.md} +22 -24
  6. data/RELEASE_NOTE +120 -0
  7. data/RELEASE_NOTE-JA +110 -0
  8. data/bin/common/tdclc_32_2_4.dll +0 -0
  9. data/bin/common/tdclc_64_2_4.dll +0 -0
  10. data/build/common/get_ruby_path.cmake +1 -1
  11. data/build/swig/ruby/tdclrb_wrap.cpp +1319 -830
  12. data/build/swig/tdcl.i +22 -2
  13. data/build/tdclc/tdclc.cbproj +1 -1
  14. data/build/tdclc/tdclc.rc +4 -4
  15. data/build/tdclcpp/tdclcpp.rc +4 -4
  16. data/build/tdclcpp/tdclcpp_bc.cbproj +2 -1
  17. data/build/tdclrb/CMakeLists.txt +6 -1
  18. data/build/tdclrb/bldgem/extconf.rb +5 -1
  19. data/build/tdclrb/tdclrb.rc +4 -4
  20. data/source/bzs/db/engine/mysql/database.cpp +44 -40
  21. data/source/bzs/db/engine/mysql/database.h +28 -8
  22. data/source/bzs/db/engine/mysql/dbManager.cpp +2 -0
  23. data/source/bzs/db/engine/mysql/dbManager.h +2 -7
  24. data/source/bzs/db/engine/mysql/mysqlInternal.h +79 -7
  25. data/source/bzs/db/protocol/hs/hsCommandExecuter.h +5 -1
  26. data/source/bzs/db/protocol/tdap/client/activeTable.cpp +32 -8
  27. data/source/bzs/db/protocol/tdap/client/activeTable.h +17 -4
  28. data/source/bzs/db/protocol/tdap/client/activeTableImple.h +10 -4
  29. data/source/bzs/db/protocol/tdap/client/client.cpp +51 -6
  30. data/source/bzs/db/protocol/tdap/client/client.h +41 -11
  31. data/source/bzs/db/protocol/tdap/client/connMgr.cpp +51 -15
  32. data/source/bzs/db/protocol/tdap/client/connMgr.h +6 -1
  33. data/source/bzs/db/protocol/tdap/client/database.cpp +26 -5
  34. data/source/bzs/db/protocol/tdap/client/database.h +3 -2
  35. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +38 -28
  36. data/source/bzs/db/protocol/tdap/client/dbDef.h +1 -1
  37. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +2 -32
  38. data/source/bzs/db/protocol/tdap/client/field.cpp +0 -1
  39. data/source/bzs/db/protocol/tdap/client/filter.h +60 -33
  40. data/source/bzs/db/protocol/tdap/client/groupQuery.cpp +2 -5
  41. data/source/bzs/db/protocol/tdap/client/memRecord.cpp +9 -0
  42. data/source/bzs/db/protocol/tdap/client/memRecord.h +1 -0
  43. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +99 -48
  44. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +5 -2
  45. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +76 -26
  46. data/source/bzs/db/protocol/tdap/client/nsTable.h +6 -4
  47. data/source/bzs/db/protocol/tdap/client/request.h +28 -11
  48. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +19 -11
  49. data/source/bzs/db/protocol/tdap/client/table.cpp +157 -70
  50. data/source/bzs/db/protocol/tdap/client/table.h +20 -5
  51. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +57 -4
  52. data/source/bzs/db/protocol/tdap/client/trdormapi.h +55 -20
  53. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +65 -31
  54. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.h +2 -0
  55. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +24 -36
  56. data/source/bzs/db/protocol/tdap/mysql/request.h +1 -1
  57. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +98 -18
  58. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +12 -7
  59. data/source/bzs/db/protocol/tdap/tdapRequest.h +3 -8
  60. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +1 -9
  61. data/source/bzs/db/protocol/tdap/tdapSchema.h +31 -1
  62. data/source/bzs/db/protocol/tdap/tdapcapi.h +49 -6
  63. data/source/bzs/db/protocol/tdap/uri.h +41 -6
  64. data/source/bzs/db/transactd/appModule.cpp +0 -1
  65. data/source/bzs/db/transactd/appModule.h +0 -2
  66. data/source/bzs/db/transactd/connManager.cpp +202 -33
  67. data/source/bzs/db/transactd/connManager.h +11 -4
  68. data/source/bzs/db/transactd/connectionRecord.h +19 -5
  69. data/source/bzs/db/transactd/transactd.cpp +39 -8
  70. data/source/bzs/env/crosscompile.cpp +1 -1
  71. data/source/bzs/example/queryData.cpp +1 -1
  72. data/source/bzs/netsvc/client/iconnection.h +2 -0
  73. data/source/bzs/netsvc/client/tcpClient.cpp +48 -26
  74. data/source/bzs/netsvc/client/tcpClient.h +171 -106
  75. data/source/bzs/netsvc/server/IAppModule.h +0 -1
  76. data/source/bzs/netsvc/server/serverPipe.cpp +5 -1
  77. data/source/bzs/netsvc/server/serverPipe.h +2 -1
  78. data/source/bzs/test/tdclatl/test_query_atl.js +105 -0
  79. data/source/bzs/test/tdclphp/transactd_Test.php +129 -11
  80. data/source/bzs/test/tdclrb/transactd_spec.rb +74 -2
  81. data/source/bzs/test/transactdBench/scaling_bench.cpp +1 -1
  82. data/source/bzs/test/trdclengn/test_trdclengn.cpp +45 -20
  83. data/source/global/tdclatl/Bookmark.cpp +28 -0
  84. data/source/global/tdclatl/Bookmark.h +65 -0
  85. data/source/global/tdclatl/Database.cpp +2 -2
  86. data/source/global/tdclatl/Database.h +1 -3
  87. data/source/global/tdclatl/DbDef.cpp +6 -0
  88. data/source/global/tdclatl/DbDef.h +1 -0
  89. data/source/global/tdclatl/QueryBase.cpp +29 -0
  90. data/source/global/tdclatl/QueryBase.h +4 -0
  91. data/source/global/tdclatl/Record.cpp +14 -2
  92. data/source/global/tdclatl/Record.h +1 -1
  93. data/source/global/tdclatl/Table.cpp +80 -16
  94. data/source/global/tdclatl/Table.h +23 -8
  95. data/source/global/tdclatl/_IDatabaseEvents_CP.h +39 -0
  96. data/source/global/tdclatl/activeTable.cpp +2 -2
  97. data/source/global/tdclatl/activeTable.h +1 -1
  98. data/source/global/tdclatl/tdclatl.idl +64 -14
  99. metadata +12 -12
  100. data/bin/common/tdclc_32_2_3.dll +0 -0
  101. data/bin/common/tdclc_64_2_3.dll +0 -0
  102. data/build/tdclcpp/BUILDNUMBER.txt +0 -1
  103. data/build/tdclrb/BUILDNUMBER.txt +0 -1
  104. /data/{BUILD_WIN-JA → BUILD_WIN-JA.md} +0 -0
  105. /data/{README_ORMSRCGEN-JA → README_ORMSRCGEN-JA.md} +0 -0
  106. /data/{README_ORMSRCGEN → README_ORMSRCGEN.md} +0 -0
@@ -23,12 +23,18 @@
23
23
 
24
24
  #include <boost/asio/write.hpp>
25
25
  #include <boost/asio/read.hpp>
26
- #include <boost/system/system_error.hpp>
27
26
  #include <boost/bind.hpp>
28
27
  #include <boost/thread/mutex.hpp>
29
28
  #if (BOOST_VERSION > 104900)
30
29
  #include <boost/asio/deadline_timer.hpp>
30
+ #else
31
+ #ifdef __APPLE__
32
+ #include <boost/asio.hpp>
33
+ #include <boost/date_time/posix_time/posix_time.hpp>
31
34
  #endif
35
+ #endif
36
+
37
+
32
38
  #include <stdio.h>
33
39
  #include <vector>
34
40
  #ifdef LINUX
@@ -103,10 +109,12 @@ class connections
103
109
  boost::asio::io_service m_ios;
104
110
  boost::asio::ip::tcp::resolver m_resolver;
105
111
  mutex m_mutex;
112
+ boost::system::error_code m_e;
106
113
  static bool m_usePipedLocal;
107
114
 
108
115
  connection* getConnection(asio::ip::tcp::endpoint& ep);
109
116
  asio::ip::tcp::endpoint endpoint(const std::string& host,
117
+ const char* port,
110
118
  boost::system::error_code& ec);
111
119
  bool isUseNamedPipe(asio::ip::tcp::endpoint& ep);
112
120
  #ifdef USE_PIPE_CLIENT
@@ -118,15 +126,16 @@ class connections
118
126
  public:
119
127
  connections(const char* pipeName);
120
128
  ~connections();
121
- connection* connect(const std::string& host, handshake f,
129
+ connection* connect(const std::string& host, const char* port, handshake f,
122
130
  void* data, bool newConnection = false);
123
- bool reconnect(connection* c, const std::string& host,
131
+ bool reconnect(connection* c, const std::string& host, const char* port,
124
132
  handshake f, void* data);
125
133
 
126
- connection* getConnection(const std::string& host);
134
+ connection* getConnection(const std::string& host, const char* port);
127
135
  bool disconnect(connection* c);
128
136
  int connectionCount();
129
- static char port[PORTNUMBUF_SIZE];
137
+ const boost::system::error_code& connectError() const { return m_e; };
138
+ static char m_port[PORTNUMBUF_SIZE];
130
139
  static int connectTimeout;
131
140
  static int netTimeout;
132
141
  };
@@ -146,6 +155,7 @@ protected:
146
155
  int m_charsetServer;
147
156
  bool m_connected;
148
157
  bool m_isHandShakable;
158
+ boost::system::error_code m_e;
149
159
 
150
160
  void addref() { ++m_refCount; }
151
161
 
@@ -169,9 +179,10 @@ public:
169
179
  }
170
180
  void setDirectReadHandler(idirectReadHandler* p){ m_reader = p; }
171
181
  bool isHandShakable() const {return m_isHandShakable;};
182
+ const boost::system::error_code& error() const { return m_e; };
172
183
  };
173
184
 
174
-
185
+
175
186
  template <class T>
176
187
  class asio_tcp_io
177
188
  {
@@ -179,37 +190,43 @@ class asio_tcp_io
179
190
  public:
180
191
  asio_tcp_io(T& socket):m_socket(socket){}
181
192
 
182
- size_t readAll(char* buf, size_t size)
193
+ size_t readAll(char* buf, size_t size, system::error_code& e)
183
194
  {
184
195
  return asio::read(m_socket, asio::buffer(buf, size),
185
- asio::transfer_all());
196
+ asio::transfer_all(), e);
186
197
  }
187
198
 
188
- size_t readSome(char* buf, size_t size, size_t minimum)
199
+ size_t readSome(char* buf, size_t size, size_t minimum,
200
+ boost::system::error_code& e)
189
201
  {
190
202
  return asio::read(m_socket, asio::buffer(buf, size),
191
- asio::transfer_at_least(minimum));
203
+ asio::transfer_at_least(minimum), e);
192
204
  }
193
205
 
194
- void write(const char* buf, size_t size, int /*flag*/)
206
+ void write(const char* buf, size_t size, int /*flag*/, boost::system::error_code& e)
195
207
  {
196
208
  asio::write(m_socket, asio::buffer(buf, size),
197
- asio::transfer_all());
209
+ asio::transfer_all(), e);
198
210
  }
199
211
 
200
212
  template <typename MutableBufferSequence>
201
- void writeMultibuffer(const MutableBufferSequence& buffer)
213
+ void writeMultibuffer(const MutableBufferSequence& buffer,
214
+ boost::system::error_code& e)
202
215
  {
203
- asio::write(m_socket, buffer, asio::transfer_all());
216
+ asio::write(m_socket, buffer, asio::transfer_all(), e);
204
217
  }
205
218
 
206
219
  void on_connected() {}
207
220
 
208
221
  };
222
+ #else // __APPLE__ (not __APPLE__)
209
223
 
210
224
  #if (defined(_WIN32))
211
225
  #define MSG_WAITALL 0x8
212
226
  #define MSG_EOR 0
227
+ #endif
228
+
229
+ #ifndef MSG_MORE
213
230
  #define MSG_MORE 0
214
231
  #endif
215
232
 
@@ -223,39 +240,42 @@ public:
223
240
  #define SYSTEM_CATEGORY system_category
224
241
  #endif
225
242
 
226
- #ifndef __APPLE__
227
- template <class T>
228
- class native_tcp_io
243
+ inline int getErrorCode()
229
244
  {
230
- T& m_socket;
231
- int getErrorCode()
232
- {
233
245
  #ifndef _WIN32
234
- return errno;
246
+ return errno;
235
247
  #else
236
- return WSAGetLastError();
248
+ return WSAGetLastError();
237
249
  #endif
238
- }
250
+ }
251
+
252
+ template <class T>
253
+ class native_tcp_io
254
+ {
255
+ T& m_socket;
239
256
 
240
257
  public:
241
258
  native_tcp_io(T& socket):m_socket(socket){}
242
259
 
243
260
  #ifdef _WIN32
244
- size_t readAll2(char* buf, size_t size)
261
+ size_t readAll2(char* buf, size_t size, system::error_code& e)
245
262
  {
246
263
  int n = 0;
247
- do
264
+ do
248
265
  {
249
266
  int nn = recv(m_socket.native(), buf + n, (int)size - n, 0);
250
267
  if (n == SOCKET_ERROR)
251
- throw system_error(error_code(getErrorCode(), SYSTEM_CATEGORY));
268
+ {
269
+ e = error_code(getErrorCode(), SYSTEM_CATEGORY);
270
+ break;
271
+ }
252
272
  n += nn;
253
273
  }while (n != size);
254
274
  return (size_t)n;
255
275
  }
256
276
  #endif
257
277
 
258
- size_t readAll(char* buf, size_t size)
278
+ size_t readAll(char* buf, size_t size, system::error_code& e)
259
279
  {
260
280
  errno = 0;
261
281
  int n = recv(m_socket.native(), buf, (int)size, MSG_WAITALL);
@@ -263,33 +283,34 @@ public:
263
283
  {
264
284
  #ifdef _WIN32
265
285
  if (WSAEOPNOTSUPP == getErrorCode())
266
- return readAll2(buf, size);
286
+ return readAll2(buf, size, e);
267
287
  else
268
288
  #endif
269
- throw system_error(error_code(getErrorCode(), SYSTEM_CATEGORY));
289
+ e = error_code(getErrorCode(), SYSTEM_CATEGORY);
270
290
  }
271
291
  return (size_t)n;
272
292
  }
273
293
 
274
- size_t readSome(char* buf, size_t size, size_t minimum)
294
+ size_t readSome(char* buf, size_t size, size_t minimum,
295
+ boost::system::error_code& e)
275
296
  {
276
297
  errno = 0;
277
298
  int n = recv(m_socket.native(), buf, (int)size, 0);
278
299
  if (n == SOCKET_ERROR)
279
- throw system_error(error_code(getErrorCode(), SYSTEM_CATEGORY));
300
+ e = error_code(getErrorCode(), SYSTEM_CATEGORY);
280
301
  return (size_t)n;
281
302
  }
282
303
 
283
- void write(const char* buf, size_t size, int flag)
304
+ void write(const char* buf, size_t size, int flag, boost::system::error_code& e)
284
305
  {
285
306
  errno = 0;
286
307
  int n = send(m_socket.native(), buf, (int)size, flag);
287
308
  if (n == SOCKET_ERROR)
288
- throw system_error(error_code(getErrorCode(), SYSTEM_CATEGORY));
309
+ e = error_code(getErrorCode(), SYSTEM_CATEGORY);
289
310
  }
290
311
 
291
312
  template <typename MutableBufferSequence>
292
- void writeMultibuffer(const MutableBufferSequence& buffer)
313
+ void writeMultibuffer(const MutableBufferSequence& buffer, boost::system::error_code& e)
293
314
  {
294
315
  buffers::const_iterator it = buffer.begin();
295
316
  buffers::const_iterator ite = buffer.end();
@@ -297,12 +318,13 @@ public:
297
318
  {
298
319
  std::size_t s = asio::buffer_size(*it);
299
320
  const char* p = asio::buffer_cast<const char*>(*it);
300
- write(p, s, (it == (ite - 1)) ? MSG_EOR : MSG_MORE);
321
+ write(p, s, (it == (ite - 1)) ? MSG_EOR : MSG_MORE, e);
322
+ if (e) break;
301
323
  ++it;
302
324
  }
303
325
  }
304
326
 
305
- void on_connected()
327
+ void on_connected()
306
328
  {
307
329
  #ifndef _WIN32
308
330
  int val = 0;
@@ -313,7 +335,7 @@ public:
313
335
  #endif
314
336
  }
315
337
  };
316
- #endif
338
+ #endif // __APPLE__
317
339
 
318
340
  template <class T> class connectionImple : public connectionBase
319
341
  {
@@ -321,14 +343,11 @@ protected:
321
343
  T m_socket;
322
344
  buffers m_optionalBuffes;
323
345
 
324
- void checkError(const system::error_code& e)
346
+ bool checkError(const system::error_code& e)
325
347
  {
326
- if (e)
327
- {
328
- if (e == asio::error::operation_aborted)
329
- throw system_error(asio::error::timed_out);
330
- throw system_error(e);
331
- }
348
+ if (e)
349
+ return false;
350
+ return true;
332
351
  }
333
352
 
334
353
  void cleanup()
@@ -355,11 +374,13 @@ protected:
355
374
 
356
375
  char* asyncWriteRead(unsigned int writeSize)
357
376
  {
358
- #ifndef _WIN32
377
+ #ifndef _WIN32
359
378
  signalmask smask;
360
379
  #endif
361
380
  write(writeSize);
362
- return read();
381
+ if (m_e) return NULL;
382
+ char* p = read();
383
+ return p;
363
384
  }
364
385
 
365
386
  buffers* optionalBuffers() { return &m_optionalBuffes; }
@@ -379,12 +400,12 @@ public:
379
400
  }
380
401
  };
381
402
 
382
- #define _size_holder asio::placeholders::bytes_transferred
383
- #define _error_holder asio::placeholders::error
403
+ #define _size_holder asio::placeholders::bytes_transferred
404
+ #define _error_holder asio::placeholders::error
384
405
 
385
406
  /** Implementation of The TCP connection.
386
407
  */
387
- #if (defined(LINUX) && (BOOST_VERSION > 104900))
408
+ #if defined(LINUX)
388
409
  #define USE_CONNECT_TIMER
389
410
  #endif
390
411
 
@@ -452,7 +473,9 @@ class tcpConnection : public connectionImple<asio::ip::tcp::socket>
452
473
  #ifdef USE_CONNECT_TIMER
453
474
  m_timer.cancel();
454
475
  #endif
455
- checkError(e);
476
+ m_e = e;
477
+ if (!checkError(e))
478
+ return ;
456
479
  s_io.on_connected();
457
480
  m_socket.set_option(boost::asio::ip::tcp::no_delay(true));
458
481
  m_connected = true;
@@ -461,7 +484,11 @@ class tcpConnection : public connectionImple<asio::ip::tcp::socket>
461
484
 
462
485
  void on_timer(const boost::system::error_code& e)
463
486
  {
464
- if (e) return;
487
+ if (e)
488
+ {
489
+ m_e = asio::error::timed_out;
490
+ return;
491
+ }
465
492
  #pragma warning(disable : 4996)
466
493
  try{ m_socket.cancel(); } catch (...) {}
467
494
  #pragma warning(default : 4996)
@@ -480,10 +507,10 @@ class tcpConnection : public connectionImple<asio::ip::tcp::socket>
480
507
  #ifdef USE_CONNECT_TIMER
481
508
  void connect()
482
509
  {
510
+ setTimer(connections::connectTimeout);
483
511
  m_socket.async_connect(m_ep,
484
512
  bind(&tcpConnection::on_connect, this, _error_holder));
485
- setTimer(connections::connectTimeout);
486
- m_ios.run();
513
+ m_ios.run();
487
514
  m_ios.reset();
488
515
  }
489
516
 
@@ -491,45 +518,55 @@ class tcpConnection : public connectionImple<asio::ip::tcp::socket>
491
518
  {
492
519
  setTimeouts(connections::connectTimeout);
493
520
  m_socket.connect(m_ep);
494
- boost::system::error_code e;
495
- on_connect(e);
521
+ m_e = error_code(getErrorCode(), SYSTEM_CATEGORY);
522
+ on_connect(m_e);
496
523
  m_ios.reset();
497
524
  }
498
525
  #endif
499
526
 
500
527
  unsigned int directRead(void* buf, unsigned int size)
501
528
  {
502
- return (unsigned int)s_io.readAll((char*)buf, size);
529
+ m_e.clear();
530
+ unsigned int len = (unsigned int)s_io.readAll((char*)buf, size, m_e);
531
+ return len;
503
532
  }
504
-
533
+
505
534
  void* directReadRemain(unsigned int size)
506
535
  {
507
536
  if (size > m_readbuf.size())
508
537
  m_readbuf.resize(size);
509
- m_readLen += s_io.readAll(&m_readbuf[0], size);
538
+ m_e.clear();
539
+ m_readLen += s_io.readAll(&m_readbuf[0], size, m_e);
510
540
  return &m_readbuf[0];
511
541
  }
512
542
 
513
543
  char* read()
514
544
  {
515
- if (!m_connected)
516
- throw system_error(asio::error::not_connected);
517
545
  m_readLen = 0;
518
- unsigned int n;
546
+ if (!m_connected)
547
+ {
548
+ m_e = asio::error::not_connected;
549
+ return &m_readbuf[0];
550
+ }
551
+ unsigned int n;
552
+ m_e.clear();
519
553
  if (m_reader)
520
554
  {
521
- m_readLen = s_io.readAll((char*)&n, 4);
555
+ m_readLen = s_io.readAll((char*)&n, 4, m_e);
522
556
  m_readLen += m_reader->onRead(n - 4, this);
523
557
  }else
524
558
  {
525
- m_readLen = s_io.readSome(&m_readbuf[0], m_readbuf.size(), 4);
559
+ m_readLen = s_io.readSome(&m_readbuf[0], m_readbuf.size(), 4, m_e);
526
560
  n = *((unsigned int*)(&m_readbuf[0]));
527
561
  }
528
-
529
- if (n > m_readLen)
562
+ if (!m_e)
530
563
  {
531
- resizeReadBuffer(n);
532
- m_readLen += s_io.readAll(&m_readbuf[m_readLen], n - m_readLen);
564
+
565
+ if (n > m_readLen)
566
+ {
567
+ resizeReadBuffer(n);
568
+ m_readLen += s_io.readAll(&m_readbuf[m_readLen], n - m_readLen, m_e);
569
+ }
533
570
  }
534
571
  return &m_readbuf[0];
535
572
  }
@@ -537,16 +574,20 @@ class tcpConnection : public connectionImple<asio::ip::tcp::socket>
537
574
  void write(unsigned int writeSize)
538
575
  {
539
576
  if (!m_connected)
540
- throw system_error(asio::error::not_connected);
577
+ {
578
+ m_e = asio::error::not_connected;
579
+ return;
580
+ }
581
+ m_e.clear();
541
582
  if (m_optionalBuffes.size())
542
583
  {
543
584
  m_optionalBuffes.insert(m_optionalBuffes.begin(),
544
585
  asio::buffer(sendBuffer(0), writeSize));
545
- s_io.writeMultibuffer(m_optionalBuffes);
586
+ s_io.writeMultibuffer(m_optionalBuffes, m_e);
546
587
  m_optionalBuffes.clear();
547
588
  }
548
589
  else
549
- s_io.write(sendBuffer(0), writeSize, MSG_EOR);
590
+ s_io.write(sendBuffer(0), writeSize, 0/*MSG_EOR*/, m_e);
550
591
  }
551
592
  public:
552
593
  tcpConnection(asio::ip::tcp::endpoint& ep)
@@ -611,18 +652,6 @@ class pipeConnection : public connectionImple<platform_stream>
611
652
  return (char*)lpMsgBuf;
612
653
  }
613
654
 
614
- void throwException(const char* msg, int errorCode)
615
- {
616
- char buf[4096];
617
- char user[128];
618
- char* p = GetErrorMessage(GetLastError());
619
- DWORD size = 128;
620
- GetUserName(user, &size);
621
- sprintf_s(buf, 4096, "User:%s %s %d %s", user, msg, GetLastError(), p);
622
- LocalFree(p);
623
- throw exception(errorCode, buf);
624
- }
625
-
626
655
  char* getUniqName(const char* name, char* buf)
627
656
  {
628
657
  char* p = buf;
@@ -646,47 +675,66 @@ class pipeConnection : public connectionImple<platform_stream>
646
675
  CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
647
676
  m_sendBufferSize * 2, getUniqName(tmp, buf));
648
677
  if (m_mapFile == NULL)
649
- throwException("CreateFileMapping", CLIENT_ERROR_SHAREMEM_DENIED);
678
+ {
679
+ m_e = boost::system::error_code(CLIENT_ERROR_SHAREMEM_DENIED, get_system_category());
680
+ return;
681
+ }
650
682
 
651
683
  m_writebuf_p = (char*)MapViewOfFile(m_mapFile, FILE_MAP_ALL_ACCESS, 0,
652
684
  0, m_sendBufferSize);
653
685
  if (m_writebuf_p == NULL)
654
- throwException("MapViewOfFile R", CLIENT_ERROR_SHAREMEM_DENIED);
686
+ {
687
+ m_e = boost::system::error_code(CLIENT_ERROR_SHAREMEM_DENIED, get_system_category());
688
+ return;
689
+ }
655
690
 
656
691
  m_readbuf_p = (char*)MapViewOfFile(m_mapFile, FILE_MAP_ALL_ACCESS, 0,
657
692
  m_sendBufferSize, m_sendBufferSize);
658
693
  if (m_readbuf_p == NULL)
659
- throwException("MapViewOfFile W", CLIENT_ERROR_SHAREMEM_DENIED);
694
+ {
695
+ m_e = boost::system::error_code(CLIENT_ERROR_SHAREMEM_DENIED, get_system_category());
696
+ return;
697
+ }
660
698
 
661
699
  sprintf_s(tmp, 50, "Global\\%sToClnt", m_pipeName.c_str());
662
700
  m_recvEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, getUniqName(tmp, buf));
663
701
  if (m_recvEvent == NULL)
664
- throwException("OpenEvent Client", CLIENT_ERROR_SHAREMEM_DENIED);
702
+ {
703
+ m_e = boost::system::error_code(CLIENT_ERROR_SHAREMEM_DENIED, get_system_category());
704
+ return;
705
+ }
665
706
 
666
707
  sprintf_s(tmp, 50, "Global\\%sToSrv", m_pipeName.c_str());
667
708
  m_sendEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, getUniqName(tmp, buf));
668
709
  if (m_sendEvent == NULL)
669
- throwException("OpenEvent Server", CLIENT_ERROR_SHAREMEM_DENIED);
710
+ m_e = boost::system::error_code(CLIENT_ERROR_SHAREMEM_DENIED, get_system_category());
670
711
  }
671
712
 
672
713
  void write(unsigned int writeSize)
673
714
  {
674
715
  //m_datalen = 0;
675
716
  //m_rows = 0;
717
+ m_e.clear();
676
718
  BOOL ret = SetEvent(m_sendEvent);
677
719
  if (ret == FALSE)
678
- throwException("SetEvent", CLIENT_ERROR_CONNECTION_FAILURE);
720
+ m_e = asio::error::connection_aborted;
679
721
  }
680
722
 
681
723
  char* read()
682
724
  {
683
- while (WAIT_TIMEOUT == WaitForSingleObject(m_recvEvent, connections::netTimeout))
725
+ int t = 0;
726
+ m_e.clear();
727
+ while (WAIT_TIMEOUT == WaitForSingleObject(m_recvEvent, 1000))
684
728
  {
729
+ t += 1000;
685
730
  DWORD n = 0;
686
731
  BOOL ret = GetNamedPipeHandleState(m_socket.native(), NULL, &n,
687
732
  NULL, NULL, NULL, 0);
688
- if(ret == FALSE || n == 0)
689
- throwException("PipeConnection", CLIENT_ERROR_CONNECTION_FAILURE);
733
+ if(ret == FALSE || n < 2)
734
+ m_e = boost::system::error_code(CLIENT_ERROR_CONNECTION_FAILURE, get_system_category());
735
+ else if (connections::netTimeout == t)
736
+ m_e = asio::error::timed_out;
737
+ if (m_e) break;
690
738
  }
691
739
  return m_readbuf_p;
692
740
  }
@@ -705,15 +753,15 @@ class pipeConnection : public connectionImple<platform_stream>
705
753
  DWORD n = 0;
706
754
  BOOL ret = GetNamedPipeHandleState(m_socket.native(), NULL, &n,
707
755
  NULL, NULL, NULL, 0);
708
- if(m_sendEvent && ret && n)
756
+ if(m_sendEvent && ret && n > 1)
709
757
  {
710
758
  SetEvent(m_sendEvent);
711
- //Wait for server side close connection
712
- while (WAIT_TIMEOUT ==
713
- WaitForSingleObject(m_recvEvent, connections::connectTimeout))
714
- ;
759
+ while (WAIT_TIMEOUT ==
760
+ WaitForSingleObject(m_recvEvent, 1000))
761
+ ;
715
762
  }
716
763
  }
764
+
717
765
  if (m_recvEvent)
718
766
  CloseHandle(m_recvEvent);
719
767
  if (m_sendEvent)
@@ -736,8 +784,12 @@ class pipeConnection : public connectionImple<platform_stream>
736
784
  {
737
785
  platform_descriptor fd;
738
786
  #ifdef WIN32
787
+ m_e.clear();
739
788
  char pipeName[100];
740
- sprintf_s(pipeName, 100, "\\\\.\\pipe\\%s", m_pipeName.c_str());
789
+ if (m_ep.port() != 8610)
790
+ sprintf_s(pipeName, 100, "\\\\.\\pipe\\%s%u", m_pipeName.c_str(), m_ep.port());
791
+ else
792
+ sprintf_s(pipeName, 100, "\\\\.\\pipe\\%s", m_pipeName.c_str());
741
793
  int i = 1000;
742
794
  while (--i)
743
795
  {
@@ -750,11 +802,14 @@ class pipeConnection : public connectionImple<platform_stream>
750
802
  Sleep(1);
751
803
  }
752
804
  if (fd == INVALID_HANDLE_VALUE)
753
- throwException("CreateFile", CLIENT_ERROR_CANT_CREATEPIPE);
805
+ {
806
+ m_e = boost::system::error_code(CLIENT_ERROR_CANT_CREATEPIPE, get_system_category());
807
+ return;
808
+ }
754
809
  #endif // NOT WIN32
755
- m_socket.assign(fd);
756
- m_connected = true;
757
810
 
811
+ m_socket.assign(fd);
812
+
758
813
  // send processId and clientid;
759
814
  DWORD processId = GetCurrentProcessId();
760
815
  int size = 16;
@@ -764,12 +819,22 @@ class pipeConnection : public connectionImple<platform_stream>
764
819
  memcpy(p + 4, &processId, sizeof(DWORD));
765
820
  __int64 clientid = (__int64) this;
766
821
  memcpy(p + 8, &clientid, sizeof(__int64));
767
- boost::asio::write(m_socket, boost::asio::buffer(p, size));
768
-
769
- boost::asio::read(m_socket, boost::asio::buffer(p, 7));
770
- unsigned int* shareMemSize = (unsigned int*)(p+3);
771
- m_isHandShakable = (p[0] == 0x00);
772
- createKernelObjects(*shareMemSize);
822
+ try
823
+ {
824
+ boost::asio::write(m_socket, boost::asio::buffer(p, size));
825
+ boost::asio::read(m_socket, boost::asio::buffer(p, 7));
826
+ }
827
+ catch (boost::system::system_error& e)
828
+ {
829
+ m_e = e.code();
830
+ }
831
+ if (!m_e)
832
+ {
833
+ unsigned int* shareMemSize = (unsigned int*)(p+3);
834
+ m_isHandShakable = (p[0] == 0x00);
835
+ m_connected = true;
836
+ createKernelObjects(*shareMemSize);
837
+ }
773
838
  }
774
839
 
775
840
  char* sendBuffer(size_t size) { return m_writebuf_p; }
@@ -82,7 +82,6 @@ public:
82
82
  virtual bool isShutDown() = 0;
83
83
  virtual bool checkHost(const char* hostCheckname, /*out*/char* hostName, int size) = 0;
84
84
  virtual void cleanup() = 0;
85
- virtual boost::mutex& mutex() const = 0;
86
85
  };
87
86
 
88
87
  // Defines at Implementing of IAppModule , two variables below.
@@ -448,6 +448,7 @@ public:
448
448
  m_comm->send();
449
449
  asio::write(m_socket, buffer(tmp, 7), e);
450
450
  run();
451
+ DisconnectNamedPipe(m_socket.native());
451
452
  }
452
453
 
453
454
  void cancel()
@@ -628,6 +629,7 @@ inotifyHandler* server::erh = NULL;
628
629
  * and will go into an infinite loop.
629
630
  */
630
631
  server::server(shared_ptr<IAppModuleBuilder> app, const std::string& name,
632
+ const char* port,
631
633
  std::size_t max_connections, unsigned int shareMemSize,
632
634
  const char* hostCheckName)
633
635
  : m_app(app), m_maxConnections(max_connections), m_stopped(false)
@@ -637,7 +639,9 @@ server::server(shared_ptr<IAppModuleBuilder> app, const std::string& name,
637
639
  m_newConnection.reset(new connection());
638
640
  connection::m_pipeName = name;
639
641
  connection::m_shareMemSize = shareMemSize;
640
- m_acceptor.open(name);
642
+ std::string tmp = name;
643
+ tmp += port;
644
+ m_acceptor.open(tmp);
641
645
  }
642
646
 
643
647
  /** Start the server
@@ -80,7 +80,8 @@ class server : public iserver, private boost::noncopyable
80
80
 
81
81
  public:
82
82
  server(boost::shared_ptr<IAppModuleBuilder>, const std::string& name,
83
- std::size_t max_connections, unsigned int shareMemSize,
83
+ const char* port,
84
+ std::size_t max_connections, unsigned int shareMemSize,
84
85
  const char* hostCheckName);
85
86
  void start();
86
87
  void stop();