transactd 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/BUILD_UNIX-JA +6 -6
  3. data/README +16 -16
  4. data/README-JA +16 -16
  5. data/bin/common/tdclc_32_2_1.dll +0 -0
  6. data/bin/common/tdclc_64_2_1.dll +0 -0
  7. data/build/common/transactd_cl_common.cmake +0 -1
  8. data/build/common/transactd_common.cmake +28 -38
  9. data/build/swig/ruby/ruby.swg +36 -30
  10. data/build/swig/ruby/tdclrb_wrap.cpp +35016 -0
  11. data/build/swig/tdcl.i +217 -62
  12. data/build/tdclc/CMakeLists.txt +14 -26
  13. data/build/tdclc/libtdclcm.map +4 -0
  14. data/build/tdclc/tdclc.cbproj +1 -1
  15. data/build/tdclc/tdclc.rc +0 -0
  16. data/build/tdclcpp/CMakeLists.txt +7 -22
  17. data/build/tdclcpp/tdclcpp.rc +0 -0
  18. data/build/tdclcpp/tdclcpp_bc.cbproj +1 -1
  19. data/build/tdclrb/CMakeLists.txt +7 -49
  20. data/build/tdclrb/tdclrb.rc +62 -0
  21. data/source/bzs/db/blobBuffer.h +5 -0
  22. data/source/bzs/db/blobStructs.h +2 -0
  23. data/source/bzs/db/engine/mysql/IReadRecords.h +9 -0
  24. data/source/bzs/db/engine/mysql/database.cpp +391 -169
  25. data/source/bzs/db/engine/mysql/database.h +178 -40
  26. data/source/bzs/db/engine/mysql/dbManager.cpp +45 -3
  27. data/source/bzs/db/engine/mysql/dbManager.h +3 -39
  28. data/source/bzs/db/engine/mysql/errorMessage.cpp +11 -7
  29. data/source/bzs/db/engine/mysql/errorMessage.h +1 -1
  30. data/source/bzs/db/engine/mysql/mydebuglog.cpp +1 -2
  31. data/source/bzs/db/engine/mysql/mysqlInternal.h +8 -8
  32. data/source/bzs/db/engine/mysql/mysqlThd.cpp +11 -0
  33. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +1 -1
  34. data/source/bzs/db/protocol/tdap/client/activeTable.cpp +41 -6
  35. data/source/bzs/db/protocol/tdap/client/activeTable.h +177 -8
  36. data/source/bzs/db/protocol/tdap/client/activeTableImple.h +141 -62
  37. data/source/bzs/db/protocol/tdap/client/client.cpp +39 -35
  38. data/source/bzs/db/protocol/tdap/client/client.h +52 -25
  39. data/source/bzs/db/protocol/tdap/client/connectionPool.cpp +17 -0
  40. data/source/bzs/db/protocol/tdap/client/connectionPool.h +1 -0
  41. data/source/bzs/db/protocol/tdap/client/database.cpp +5 -1
  42. data/source/bzs/db/protocol/tdap/client/database.h +1 -1
  43. data/source/bzs/db/protocol/tdap/client/databaseFactory.cpp +49 -12
  44. data/source/bzs/db/protocol/tdap/client/databaseManager.h +42 -5
  45. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +4 -2
  46. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +71 -41
  47. data/source/bzs/db/protocol/tdap/client/errorMessage_ja.cpp +49 -49
  48. data/source/bzs/db/protocol/tdap/client/field.cpp +22 -13
  49. data/source/bzs/db/protocol/tdap/client/field.h +7 -3
  50. data/source/bzs/db/protocol/tdap/client/fieldDDF.cpp +1 -1
  51. data/source/bzs/db/protocol/tdap/client/fieldNameAlias.cpp +0 -1
  52. data/source/bzs/db/protocol/tdap/client/fieldNameAlias.h +1 -0
  53. data/source/bzs/db/protocol/tdap/client/fields.h +111 -24
  54. data/source/bzs/db/protocol/tdap/client/fileDDF.cpp +1 -1
  55. data/source/bzs/db/protocol/tdap/client/filter.h +687 -310
  56. data/source/bzs/db/protocol/tdap/client/groupQuery.cpp +12 -4
  57. data/source/bzs/db/protocol/tdap/client/indexDDF.cpp +1 -1
  58. data/source/bzs/db/protocol/tdap/client/memRecord.cpp +190 -32
  59. data/source/bzs/db/protocol/tdap/client/memRecord.h +64 -22
  60. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +4 -4
  61. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +4 -2
  62. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +6 -3
  63. data/source/bzs/db/protocol/tdap/client/nsTable.h +1 -1
  64. data/source/bzs/db/protocol/tdap/client/pooledDatabaseManager.h +19 -8
  65. data/source/bzs/db/protocol/tdap/client/recordsetImple.h +194 -87
  66. data/source/bzs/db/protocol/tdap/client/request.h +84 -26
  67. data/source/bzs/db/protocol/tdap/client/stringConverter.h +22 -12
  68. data/source/bzs/db/protocol/tdap/client/table.cpp +494 -286
  69. data/source/bzs/db/protocol/tdap/client/table.h +48 -5
  70. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +133 -87
  71. data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +22 -22
  72. data/source/bzs/db/protocol/tdap/client/trdormapi.h +43 -18
  73. data/source/bzs/db/protocol/tdap/client/trnsctcl.def +3 -3
  74. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +1 -0
  75. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +268 -74
  76. data/source/bzs/db/protocol/tdap/mysql/request.h +4 -4
  77. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +179 -43
  78. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +4 -4
  79. data/source/bzs/db/protocol/tdap/tdapRequest.h +15 -14
  80. data/source/bzs/db/protocol/tdap/tdapSchema.h +125 -90
  81. data/source/bzs/db/protocol/tdap/tdapcapi.h +46 -5
  82. data/source/bzs/db/transactd/appModule.h +1 -1
  83. data/source/bzs/db/transactd/connManager.cpp +2 -0
  84. data/source/bzs/db/transactd/transactd.cpp +1 -0
  85. data/source/bzs/env/compiler.h +10 -0
  86. data/source/bzs/env/mbcswchrLinux.cpp +42 -6
  87. data/source/bzs/env/mbcswchrLinux.h +40 -12
  88. data/source/bzs/example/queryData.cpp +33 -4
  89. data/source/bzs/netsvc/client/iconnection.h +107 -0
  90. data/source/bzs/netsvc/client/tcpClient.cpp +15 -1
  91. data/source/bzs/netsvc/client/tcpClient.h +96 -87
  92. data/source/bzs/netsvc/server/serverCpt.cpp +5 -6
  93. data/source/bzs/rtl/benchmark.cpp +2 -2
  94. data/source/bzs/rtl/stringBuffers.cpp +3 -3
  95. data/source/bzs/rtl/stringBuffers.h +2 -2
  96. data/source/bzs/test/tdclatl/bench_query_atl.js +92 -99
  97. data/source/bzs/test/tdclatl/test_query_atl.js +224 -115
  98. data/source/bzs/test/tdclphp/bench.php +126 -101
  99. data/source/bzs/test/tdclphp/transactd_Test.php +1122 -158
  100. data/source/bzs/test/tdclrb/bench_tdclcpp.rb +12 -14
  101. data/source/bzs/test/tdclrb/transactd_spec.rb +1127 -142
  102. data/source/bzs/test/transactdBench/query_bench.cpp +32 -15
  103. data/source/bzs/test/transactdBench/scaling_bench.cpp +32 -7
  104. data/source/bzs/test/transactdBench/transactdBench.cpp +1 -1
  105. data/source/bzs/test/transactdBench/workerBase.h +46 -0
  106. data/source/bzs/test/transactdBench/workerMySQLImple.h +15 -7
  107. data/source/bzs/test/transactdBench/workerTransactdImple.h +10 -18
  108. data/source/bzs/test/trdclengn/test_trdclengn.cpp +1487 -174
  109. data/source/global/ormsrcgen/main.cpp +2 -0
  110. data/source/global/tdclatl/Database.cpp +2 -2
  111. data/source/global/tdclatl/Database.h +1 -1
  112. data/source/global/tdclatl/FieldDefs.cpp +0 -3
  113. data/source/global/tdclatl/PooledDbManager.cpp +2 -2
  114. data/source/global/tdclatl/PooledDbManager.h +1 -1
  115. data/source/global/tdclatl/PreparedQuery.cpp +53 -0
  116. data/source/global/tdclatl/PreparedQuery.h +61 -0
  117. data/source/global/tdclatl/QueryBase.cpp +2 -1
  118. data/source/global/tdclatl/QueryBase.h +1 -1
  119. data/source/global/tdclatl/Record.cpp +3 -15
  120. data/source/global/tdclatl/Recordset.cpp +15 -10
  121. data/source/global/tdclatl/Recordset.h +3 -0
  122. data/source/global/tdclatl/Table.cpp +42 -7
  123. data/source/global/tdclatl/Table.h +3 -1
  124. data/source/global/tdclatl/activeTable.cpp +264 -76
  125. data/source/global/tdclatl/activeTable.h +12 -3
  126. data/source/global/tdclatl/tdclatl.idl +92 -10
  127. data/source/linux/charsetConvert.h +7 -7
  128. data/transactd.gemspec +14 -27
  129. metadata +18 -27
  130. data/bin/common/tdclc_32_2_0.dll +0 -0
  131. data/bin/common/tdclc_64_2_0.dll +0 -0
  132. data/build/swig/php/generate.cmake.in +0 -56
  133. data/build/swig/php/generate.cmd.in +0 -47
  134. data/build/swig/php/php.swg +0 -197
  135. data/build/swig/php/transactd.no_yield.php +0 -4494
  136. data/build/swig/php/transactd.no_yield.php.git.patch +0 -685
  137. data/build/swig/php/transactd.no_yield.php.patch +0 -685
  138. data/build/swig/php/transactd.yield.php +0 -4461
  139. data/build/swig/php/transactd.yield.php.git.patch +0 -652
  140. data/build/swig/php/transactd.yield.php.patch +0 -652
  141. data/build/swig/ruby/generate.cmake.in +0 -35
  142. data/build/swig/ruby/generate.cmd.in +0 -19
  143. data/build/tdclc/BUILDNUMBER.txt +0 -1
  144. data/build/tdclcpp/BUILDNUMBER.txt +0 -1
  145. data/build/tdclrb/BUILDNUMBER.txt +0 -1
  146. data/build/tdclrb/GEM_RELEASE_VERSION +0 -1
@@ -18,7 +18,7 @@
18
18
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
19
  02111-1307, USA.
20
20
  =================================================================*/
21
-
21
+ #include <my_config.h>
22
22
  #include <bzs/netsvc/server/IAppModule.h>
23
23
  #include <bzs/db/protocol/ICommandExecuter.h>
24
24
 
@@ -98,6 +98,7 @@ void connManager::getDatabaseList(const module* mod) const
98
98
  const connManager::records& connManager::getRecords(unsigned __int64 conid,
99
99
  int dbid) const
100
100
  {
101
+ //Lock module count
101
102
  boost::mutex::scoped_lock lck(modulesMutex);
102
103
 
103
104
  if (conid == 0)
@@ -107,6 +108,7 @@ const connManager::records& connManager::getRecords(unsigned __int64 conid,
107
108
  const module* mod = getMod(conid);
108
109
  if (mod)
109
110
  {
111
+ //Lock module execute
110
112
  boost::try_mutex::scoped_try_lock m(mod->mutex(),
111
113
  boost::try_to_lock_t());
112
114
  if (m.owns_lock())
@@ -16,6 +16,7 @@
16
16
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17
17
  02111-1307, USA.
18
18
  =================================================================*/
19
+ #include <my_config.h>
19
20
  #include <bzs/netsvc/server/serverCpt.h>
20
21
  #include <bzs/netsvc/server/serverTpool.h>
21
22
  #include <bzs/rtl/exception.h>
@@ -132,6 +132,16 @@
132
132
  #endif
133
133
  #endif
134
134
 
135
+ //memory leak detector
136
+ #ifdef _MSC_VER
137
+ #ifdef _DEBUG
138
+ #define _CRTDBG_MAP_ALLOC
139
+ #include <stdlib.h>
140
+ #include <crtdbg.h>
141
+ #endif // _DEBUG
142
+ #endif // _MSC_VER
143
+
144
+
135
145
  // compiler name
136
146
  #if (_MSC_VER == 1600)
137
147
  #define COMPILER_VERSTR "vc100"
@@ -19,17 +19,53 @@
19
19
 
20
20
  #include "mbcswchrLinux.h"
21
21
  #include <stdio.h>
22
+ #include <pthread.h>
23
+ #include <bzs/env/crosscompile.h>
24
+ #include <assert.h>
25
+
26
+
27
+ #define CVT_COUNT 6
22
28
 
23
29
  namespace bzs
24
30
  {
25
31
  namespace env
26
32
  {
27
- cvt mbcscvt("UTF-16LE", MBC_CHARSETNAME);
28
- cvt wchrcvt(MBC_CHARSETNAME, "UTF-16LE");
29
- cvt u8mbcvt(MBC_CHARSETNAME, UTF8_CHARSETNAME);
30
- cvt mbu8cvt(UTF8_CHARSETNAME, MBC_CHARSETNAME);
31
- cvt u8wccvt("UTF-16LE", UTF8_CHARSETNAME);
32
- cvt wcu8cvt(UTF8_CHARSETNAME, "UTF-16LE");
33
+
34
+ tls_key g_tls1=0;
35
+
36
+ void cleanupTls(void* p)
37
+ {
38
+ delete [] ((cvt*)p);
39
+ }
40
+
41
+ void initCvtProcess()
42
+ {
43
+ int ret = pthread_key_create(&g_tls1, cleanupTls);
44
+ assert(ret == 0);
45
+ }
46
+
47
+ void deinitCvtProcess()
48
+ {
49
+ pthread_key_delete(g_tls1);
50
+ }
51
+
52
+ cvt& getCvt(int index)
53
+ {
54
+ cvt* p = (cvt*)pthread_getspecific(g_tls1);
55
+ if (p == NULL)
56
+ {
57
+ p = new cvt[CVT_COUNT];
58
+ p[0].setCharset("UTF-16LE", MBC_CHARSETNAME);
59
+ p[1].setCharset(MBC_CHARSETNAME, "UTF-16LE");
60
+ p[2].setCharset(MBC_CHARSETNAME, UTF8_CHARSETNAME);
61
+ p[3].setCharset(UTF8_CHARSETNAME, MBC_CHARSETNAME);
62
+ p[4].setCharset("UTF-16LE", UTF8_CHARSETNAME);
63
+ p[5].setCharset(UTF8_CHARSETNAME, "UTF-16LE");
64
+ pthread_setspecific(g_tls1, p);
65
+ }
66
+ return p[index];
67
+ }
68
+
33
69
 
34
70
  } // namespace env
35
71
  } // namespace bzs
@@ -32,12 +32,40 @@ namespace bzs
32
32
  {
33
33
  namespace env
34
34
  {
35
- extern cvt u8mbcvt; // utf8 to mbc
36
- extern cvt mbu8cvt; // mbc to utf8
37
- extern cvt mbcscvt; // mbc to utf16le
38
- extern cvt wchrcvt; // utf16le to mbc
39
- extern cvt u8wccvt; // utf8 to utf16le
40
- extern cvt wcu8cvt; // utf16le to utf8
35
+
36
+ void initCvtProcess();
37
+ void deinitCvtProcess();
38
+ cvt& getCvt(int index);
39
+
40
+ inline cvt& mbcscvt()
41
+ {
42
+ return getCvt(0);
43
+ }
44
+
45
+ inline cvt& wchrcvt()
46
+ {
47
+ return getCvt(1);
48
+ }
49
+
50
+ inline cvt& u8mbcvt()
51
+ {
52
+ return getCvt(2);
53
+ }
54
+
55
+ inline cvt& mbu8cvt()
56
+ {
57
+ return getCvt(3);
58
+ }
59
+
60
+ inline cvt& u8wccvt()
61
+ {
62
+ return getCvt(4);
63
+ }
64
+
65
+ inline cvt& wcu8cvt()
66
+ {
67
+ return getCvt(5);
68
+ }
41
69
 
42
70
  inline int WideCharToMultiByte(unsigned int codepage, unsigned int dwFlags,
43
71
  const char16_t* lpWideCharStr, int cchWideChar,
@@ -46,9 +74,9 @@ inline int WideCharToMultiByte(unsigned int codepage, unsigned int dwFlags,
46
74
  int* lpUsedDefaultChar)
47
75
  {
48
76
  if (codepage == CP_UTF8)
49
- return wcu8cvt.conv(lpWideCharStr, (size_t)(cchWideChar + cchWideChar),
77
+ return wcu8cvt().conv(lpWideCharStr, (size_t)(cchWideChar + cchWideChar),
50
78
  lpMultiByteStr, (size_t)cchMultiByte);
51
- return wchrcvt.conv(lpWideCharStr, (size_t)(cchWideChar + cchWideChar),
79
+ return wchrcvt().conv(lpWideCharStr, (size_t)(cchWideChar + cchWideChar),
52
80
  lpMultiByteStr, (size_t)cchMultiByte);
53
81
  }
54
82
 
@@ -57,20 +85,20 @@ inline int MultiByteToWideChar(unsigned int codepage, unsigned int dwFlags,
57
85
  char16_t* lpWideCharStr, int cchWideChar)
58
86
  {
59
87
  if (codepage == CP_UTF8)
60
- return u8wccvt.conv(lpMultiByteStr, (size_t)cchMultiByte, lpWideCharStr,
88
+ return u8wccvt().conv(lpMultiByteStr, (size_t)cchMultiByte, lpWideCharStr,
61
89
  (size_t)(cchWideChar + cchWideChar));
62
- return mbcscvt.conv(lpMultiByteStr, (size_t)cchMultiByte, lpWideCharStr,
90
+ return mbcscvt().conv(lpMultiByteStr, (size_t)cchMultiByte, lpWideCharStr,
63
91
  (size_t)(cchWideChar + cchWideChar));
64
92
  }
65
93
 
66
94
  inline int u8tombc(const char* u8, int u8size, char* mbc, int mbcsize)
67
95
  {
68
- return u8mbcvt.conv(u8, (size_t)u8size, mbc, (size_t)mbcsize);
96
+ return u8mbcvt().conv(u8, (size_t)u8size, mbc, (size_t)mbcsize);
69
97
  }
70
98
 
71
99
  inline int mbctou8(const char* mbc, int mbcsize, char* u8, int u8size)
72
100
  {
73
- return mbu8cvt.conv(mbc, (size_t)mbcsize, u8, (size_t)u8size);
101
+ return mbu8cvt().conv(mbc, (size_t)mbcsize, u8, (size_t)u8size);
74
102
  }
75
103
 
76
104
  } // namespace env
@@ -31,12 +31,12 @@ using namespace bzs::db::protocol::tdap;
31
31
 
32
32
  #define USER_STRING_TYPE ft_myvarchar
33
33
  #define GROUP_STRING_TYPE ft_myvarbinary
34
-
34
+ #define BLOB_TYPE ft_myblob
35
35
  #else
36
36
 
37
37
  #define USER_STRING_TYPE ft_zstring
38
38
  #define GROUP_STRING_TYPE ft_zstring
39
-
39
+ #define BLOB_TYPE ft_blob
40
40
  #endif
41
41
 
42
42
  const _TCHAR* name_field_str(_TCHAR* buf)
@@ -206,9 +206,18 @@ bool createUserExtTable(dbdef* def)
206
206
  fd = def->insertField(tableid, filedIndex);
207
207
  fd->setName(_T("comment"));
208
208
  fd->type = USER_STRING_TYPE;
209
-
210
209
  fd->setLenByCharnum(60);
211
210
 
211
+ ++filedIndex;
212
+ fd = def->insertField(tableid, filedIndex);
213
+ fd->setName(_T("blob"));
214
+ fd->type = BLOB_TYPE;
215
+ #ifndef USE_PSQL_DATABASE
216
+ fd->len = 10;
217
+ #else
218
+ fd->len = 16000;
219
+ #endif
220
+
212
221
  char keyNum = 0;
213
222
  keydef* kd = def->insertKey(tableid, keyNum);
214
223
  keySegment* seg1 = &kd->segments[0];
@@ -323,6 +332,8 @@ bool insertData(database_ptr db, int maxId)
323
332
  tbe->setFV((short)0, i);
324
333
  _stprintf_s(tmp, 256, _T("%d comment"), i);
325
334
  tbe->setFV(1, tmp);
335
+ _stprintf_s(tmp, 256, _T("%d blob"), i);
336
+ tbe->setFV(2, tmp);
326
337
  tbe->insert();
327
338
  if (tbe->stat() != 0)
328
339
  return showTableError(tbe, _T("extention insert"));
@@ -335,6 +346,24 @@ bool insertData(database_ptr db, int maxId)
335
346
  return true;
336
347
  }
337
348
 
349
+ bool checkVersion(database_ptr db)
350
+ {
351
+ dbdef* def = db->dbDef();
352
+ if (def)
353
+ {
354
+ tabledef* td = def->tableDefs(3);
355
+ if (td)
356
+ {
357
+ if (td->fieldCount == 3)
358
+ {
359
+ table_ptr tb = openTable(db, _T("extention"));
360
+ return (tb->recordCount(false) == 20000);
361
+ }
362
+ }
363
+ }
364
+ return false;
365
+ }
366
+
338
367
  int prebuiltData(database_ptr db, const connectParams& param, bool foceCreate,
339
368
  int maxId)
340
369
  {
@@ -342,7 +371,7 @@ int prebuiltData(database_ptr db, const connectParams& param, bool foceCreate,
342
371
  {
343
372
  if (db->open(param.uri(), TD_OPEN_NORMAL))
344
373
  {
345
- if (foceCreate)
374
+ if (foceCreate || !checkVersion(db))
346
375
  dropDatabase(db);
347
376
  else
348
377
  return 0;
@@ -0,0 +1,107 @@
1
+ #ifndef BZS_NETSVC_CLINET_ICONNECTION_H
2
+ #define BZS_NETSVC_CLINET_ICONNECTION_H
3
+ /* =================================================================
4
+ Copyright (C) 2014 BizStation Corp All rights reserved.
5
+
6
+ This program is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU General Public License
8
+ as published by the Free Software Foundation; either version 2
9
+ of the License, or (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
+ 02111-1307, USA.
20
+ ================================================================= */
21
+ #ifdef __BCPLUSPLUS__
22
+ #pragma warn -8012
23
+ #endif
24
+
25
+ #include <boost/asio/ip/tcp.hpp>
26
+ #include <boost/asio/buffer.hpp>
27
+ #include <vector>
28
+
29
+ #ifdef __BCPLUSPLUS__
30
+ #pragma warn +8012
31
+ #endif
32
+
33
+ #ifdef _WIN32
34
+ #define USE_PIPE_CLIENT
35
+ #endif
36
+
37
+ #ifdef USE_PIPE_CLIENT
38
+ #include <boost/asio/windows/stream_handle.hpp>
39
+ using boost::asio::windows::stream_handle;
40
+ typedef stream_handle platform_stream;
41
+ typedef HANDLE platform_descriptor;
42
+ #define PIPE_EOF_ERROR_CODE boost::system::windows_error::broken_pipe
43
+ typedef DWORD thread_id;
44
+ #define threadid GetCurrentThreadId
45
+ #else // NOT USE_PIPE_CLIENT
46
+ typedef pthread_t thread_id;
47
+ #define threadid pthread_self
48
+ #endif // NOT USE_PIPE_CLIENT
49
+
50
+ namespace bzs
51
+ {
52
+ namespace netsvc
53
+ {
54
+ namespace client
55
+ {
56
+
57
+ typedef std::vector<boost::asio::const_buffer> buffers;
58
+
59
+ class connection;
60
+
61
+ class idirectReadHandler
62
+ {
63
+
64
+ public:
65
+ /* Call by connection at first 4byte readed.
66
+ size : The rest of the data size. = TotalSize - 4
67
+ */
68
+ virtual unsigned int onRead(unsigned int size, connection* c) = 0;
69
+ };
70
+
71
+ /** The connection interface
72
+ *
73
+ */
74
+ class connection
75
+ {
76
+ public:
77
+ virtual ~connection(){};
78
+ virtual void connect() = 0;
79
+ virtual void addref() = 0;
80
+ virtual void release() = 0;
81
+ virtual int refCount() const = 0;
82
+ virtual bool isConnected() const = 0;
83
+ virtual const boost::asio::ip::tcp::endpoint& endpoint() const = 0;
84
+ virtual thread_id tid() const = 0;
85
+ virtual char* sendBuffer(size_t size) = 0;
86
+ virtual unsigned int sendBufferSize() = 0;
87
+ virtual buffers* optionalBuffers() = 0;
88
+ virtual char* asyncWriteRead(unsigned int writeSize) = 0;
89
+ //virtual unsigned int datalen() const = 0; // additinal info at segment read
90
+ //virtual unsigned short rows() const = 0; // additinal info at segment read
91
+ virtual void setReadBufferSizeIf(size_t size) = 0;
92
+ virtual void setDirectReadHandler(idirectReadHandler* p) = 0;
93
+ virtual unsigned int directRead(void* buf, unsigned int size) = 0;
94
+ virtual void* directReadRemain(unsigned int size) = 0;
95
+ virtual bool queryFunction(unsigned int v) = 0;
96
+ virtual int charsetServer() const = 0;
97
+ virtual void setCharsetServer(int v) = 0;
98
+ };
99
+
100
+ #define CONNECTION_FUNCTION_DIRECT_READ 1
101
+
102
+
103
+ } // namespace client
104
+ } // namespace netsvc
105
+ } // namespace bzs
106
+
107
+ #endif // BZS_NETSVC_CLINET_ICONNECTION_H
@@ -16,7 +16,6 @@
16
16
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17
17
  02111-1307, USA.
18
18
  ================================================================= */
19
-
20
19
  #include "tcpClient.h"
21
20
  #include <bzs/env/crosscompile.h>
22
21
  #if (!defined(_WIN32))
@@ -26,6 +25,7 @@
26
25
  #include <boost/property_tree/ini_parser.hpp>
27
26
  #endif
28
27
  #endif
28
+
29
29
  #pragma package(smart_init)
30
30
 
31
31
  using namespace boost;
@@ -41,6 +41,12 @@ namespace client
41
41
 
42
42
  char connections::port[PORTNUMBUF_SIZE] = { "8610" };
43
43
  bool connections::m_usePipedLocal = true;
44
+ #ifdef _WIN32
45
+ short connections::timeout = 3000;
46
+ #else
47
+ short connections::timeout = 3;
48
+ #endif
49
+
44
50
 
45
51
  connections::connections(const char* pipeName) : m_pipeName(pipeName)
46
52
  {
@@ -57,6 +63,9 @@ connections::connections(const char* pipeName) : m_pipeName(pipeName)
57
63
  GetPrivateProfileString("transctd_client", "port", "8610", tmp, 30,
58
64
  buf);
59
65
  strcpy_s(port, PORTNUMBUF_SIZE, tmp);
66
+ GetPrivateProfileString("transctd_client", "timeout", "3000", tmp, 30,
67
+ buf);
68
+ timeout = atol(tmp);
60
69
  }
61
70
  #else // NOT _WIN32
62
71
  #if (BOOST_VERSION > 104900)
@@ -77,6 +86,11 @@ connections::connections(const char* pipeName) : m_pipeName(pipeName)
77
86
  if (p == "")
78
87
  p = "8610";
79
88
  strcpy_s(port, PORTNUMBUF_SIZE, p.c_str());
89
+
90
+ p = pt.get<std::string>("transctd_client.timeout");
91
+ timeout = atol(p.c_str())/1000;
92
+ if (timeout == 0)
93
+ timeout = 3;
80
94
  }
81
95
  catch (...)
82
96
  {
@@ -19,45 +19,18 @@
19
19
  02111-1307, USA.
20
20
  ================================================================= */
21
21
 
22
- #ifdef __BCPLUSPLUS__
23
- #pragma warn -8012
24
- #endif
25
- #include <boost/asio/buffer.hpp>
26
- #include <boost/asio/windows/stream_handle.hpp>
27
- #include <boost/asio/io_service.hpp>
28
- #include <boost/asio/windows/basic_handle.hpp>
29
- #include <boost/asio/ip/tcp.hpp>
30
- #include <boost/asio/read.hpp>
22
+ #include <bzs/netsvc/client/iconnection.h>
31
23
  #include <boost/asio/write.hpp>
32
- #include <boost/bind.hpp>
33
- #include <boost/asio/placeholders.hpp>
34
-
24
+ #include <boost/asio/read.hpp>
35
25
  #include <boost/system/system_error.hpp>
36
26
  #include <boost/thread/mutex.hpp>
37
27
  #include <stdio.h>
38
-
39
- #ifdef __BCPLUSPLUS__
40
- #pragma warn +8012
41
- #endif
42
28
  #include <vector>
43
- using namespace boost;
44
- using namespace boost::system;
45
29
 
46
- #ifdef _WIN32
47
- #define USE_PIPE_CLIENT
48
- #endif
49
30
 
50
- #ifdef USE_PIPE_CLIENT
51
- using boost::asio::windows::stream_handle;
52
- typedef stream_handle platform_stream;
53
- typedef HANDLE platform_descriptor;
54
- #define PIPE_EOF_ERROR_CODE boost::system::windows_error::broken_pipe
55
- typedef DWORD thread_id;
56
- #define threadid GetCurrentThreadId
57
- #else // NOT USE_PIPE_CLIENT
58
- typedef pthread_t thread_id;
59
- #define threadid pthread_self
60
- #endif // NOT USE_PIPE_CLIENT
31
+
32
+ using namespace boost;
33
+ using namespace boost::system;
61
34
 
62
35
  #define READBUF_SIZE 66000
63
36
  #define WRITEBUF_SIZE 66000
@@ -65,6 +38,9 @@ typedef pthread_t thread_id;
65
38
  #define PORTNUMBUF_SIZE 10
66
39
  #define CLIENT_ERROR_CANT_CREATEPIPE 3106
67
40
  #define CLIENT_ERROR_SHAREMEM_DENIED 3104
41
+ #define CLIENT_ERROR_CONNECTION_FAILURE 3106
42
+ #define TIMEOUT_MILLISEC 3000
43
+
68
44
 
69
45
  namespace bzs
70
46
  {
@@ -73,10 +49,6 @@ namespace netsvc
73
49
  namespace client
74
50
  {
75
51
 
76
- typedef std::vector<boost::asio::const_buffer> buffers;
77
-
78
- class connection;
79
-
80
52
  class connections
81
53
  {
82
54
  std::vector<connection*> m_conns;
@@ -106,33 +78,11 @@ public:
106
78
  bool disconnect(connection* c);
107
79
 
108
80
  static char port[PORTNUMBUF_SIZE];
81
+ static short timeout;
109
82
 
110
83
  int connectionCount();
111
84
  };
112
85
 
113
- /** The connection interface
114
- *
115
- */
116
- class connection
117
- {
118
- public:
119
- virtual ~connection(){};
120
- virtual void connect() = 0;
121
- virtual void addref() = 0;
122
- virtual void release() = 0;
123
- virtual int refCount() const = 0;
124
- virtual bool isConnected() const = 0;
125
- virtual const asio::ip::tcp::endpoint& endpoint() const = 0;
126
- virtual thread_id tid() const = 0;
127
- virtual char* sendBuffer(size_t size) = 0;
128
- virtual unsigned int sendBufferSize() = 0;
129
- virtual buffers* optionalBuffers() = 0;
130
- virtual char* asyncWriteRead(unsigned int writeSize) = 0;
131
- virtual unsigned int datalen() const = 0; // additinal info at segment read
132
- virtual unsigned short rows() const = 0; // additinal info at segment read
133
- virtual void setReadBufferSizeIf(size_t size) = 0;
134
- };
135
-
136
86
  /** Implementation of Part of the connection interface
137
87
  */
138
88
  class connectionBase : public connection
@@ -142,16 +92,16 @@ protected:
142
92
 
143
93
  asio::io_service m_ios;
144
94
  asio::ip::tcp::endpoint m_ep;
145
-
146
- int m_refCount;
147
- thread_id m_tid;
148
-
149
95
  std::vector<char> m_readbuf;
150
96
  std::vector<char> m_sendbuf;
151
-
97
+ idirectReadHandler* m_reader;
152
98
  size_t m_readLen;
99
+ int m_refCount;
100
+ thread_id m_tid;
101
+ int m_charsetServer;
153
102
  bool m_connected;
154
103
 
104
+
155
105
  void addref() { ++m_refCount; }
156
106
 
157
107
  void release() { --m_refCount; }
@@ -164,12 +114,19 @@ protected:
164
114
 
165
115
  thread_id tid() const { return m_tid; };
166
116
 
117
+ int charsetServer() const { return m_charsetServer; };
118
+
119
+ void setCharsetServer(int v) { m_charsetServer = v; }
120
+
167
121
  public:
168
122
  connectionBase(asio::ip::tcp::endpoint& ep)
169
- : m_ep(ep), m_refCount(0), m_tid(threadid()), m_connected(false)
123
+ : m_ep(ep), m_reader(NULL), m_refCount(0), m_tid(threadid()),
124
+ m_charsetServer(-1), m_connected(false)
170
125
  {
171
126
  }
172
127
 
128
+ void setDirectReadHandler(idirectReadHandler* p){ m_reader = p; }
129
+
173
130
  char* sendBuffer(size_t size)
174
131
  {
175
132
  if (size > m_sendbuf.size())
@@ -191,18 +148,18 @@ public:
191
148
  template <class T> class connectionImple : public connectionBase
192
149
  {
193
150
  protected:
194
- unsigned int m_datalen;
195
- unsigned short m_rows;
151
+ //unsigned int m_datalen;
152
+ //unsigned short m_rows;
196
153
  T m_socket;
197
154
  buffers m_optionalBuffes;
198
155
 
199
- unsigned int datalen() const { return m_datalen; }
156
+ //unsigned int datalen() const { return m_datalen; }
200
157
 
201
- unsigned short rows() const { return m_rows; }
158
+ //unsigned short rows() const { return m_rows; }
202
159
 
203
160
  // server send any segment of lower than 0xFFFF data by asyncWrite
204
161
  // last 4byte is 0xFFFFFFFF, that is specify end of data
205
- void segmentRead()
162
+ /*void segmentRead()
206
163
  {
207
164
  bool end = false;
208
165
  unsigned short n;
@@ -226,6 +183,31 @@ protected:
226
183
  boost::asio::transfer_all());
227
184
  boost::asio::read(m_socket, boost::asio::buffer(&m_rows, 2),
228
185
  boost::asio::transfer_all());
186
+ }*/
187
+ bool queryFunction(unsigned int v)
188
+ {
189
+ if (v == CONNECTION_FUNCTION_DIRECT_READ)
190
+ return true;
191
+ return false;
192
+ }
193
+
194
+ unsigned int directRead(void* buf, unsigned int size)
195
+ {
196
+ return (unsigned int)boost::asio::read(m_socket,
197
+ boost::asio::buffer(buf, size),
198
+ boost::asio::transfer_all());
199
+ }
200
+
201
+ void* directReadRemain(unsigned int size)
202
+ {
203
+ if (size > m_readbuf.size())
204
+ m_readbuf.resize(size);
205
+
206
+ m_readLen += boost::asio::read(
207
+ m_socket,
208
+ boost::asio::buffer(&m_readbuf[0], size),
209
+ boost::asio::transfer_all());
210
+ return &m_readbuf[0];
229
211
  }
230
212
 
231
213
  void read()
@@ -234,24 +216,40 @@ protected:
234
216
  throw system_error(asio::error::not_connected);
235
217
  boost::system::error_code e;
236
218
  m_readLen = 0;
237
- m_datalen = 0;
238
- m_rows = 0;
219
+ //m_datalen = 0;
220
+ //m_rows = 0;
239
221
  unsigned int n;
240
- m_readLen += boost::asio::read(m_socket, boost::asio::buffer(&n, 4),
241
- boost::asio::transfer_all());
242
- if (n == 0xFFFFFFFF)
222
+
223
+ //m_readLen += boost::asio::read(m_socket, boost::asio::buffer(&n, 4),
224
+ // boost::asio::transfer_all());
225
+ /*if (n == 0xFFFFFFFF)
243
226
  {
244
227
  segmentRead();
245
228
  m_readLen += boost::asio::read(m_socket, boost::asio::buffer(&n, 4),
246
229
  boost::asio::transfer_all());
230
+ }*/
231
+ if (m_reader)
232
+ {
233
+ m_readLen = boost::asio::read(m_socket, boost::asio::buffer(&n, 4),
234
+ boost::asio::transfer_all());
235
+ m_readLen += m_reader->onRead(n - 4, this);
236
+ }else
237
+ {
238
+ m_readLen = boost::asio::read(m_socket,
239
+ boost::asio::buffer(&m_readbuf[0],m_readbuf.size()),
240
+ boost::asio::transfer_at_least(4));
241
+ n = *((unsigned int*)(&m_readbuf[0]));
247
242
  }
248
- if (n > m_readbuf.size())
249
- m_readbuf.resize(n);
250
- if (m_readLen != n)
243
+ if (m_readLen < n)
244
+ {
245
+ if (n > m_readbuf.size())
246
+ m_readbuf.resize(n);
247
+
251
248
  m_readLen += boost::asio::read(
252
249
  m_socket,
253
250
  boost::asio::buffer(&m_readbuf[m_readLen], n - m_readLen),
254
251
  boost::asio::transfer_all());
252
+ }
255
253
  }
256
254
 
257
255
  void write(unsigned int writeSize)
@@ -273,15 +271,16 @@ protected:
273
271
 
274
272
  public:
275
273
  connectionImple(asio::ip::tcp::endpoint& ep)
276
- : connectionBase(ep), m_datalen(0), m_socket(m_ios)
274
+ : connectionBase(ep)/*, m_datalen(0)*/, m_socket(m_ios)
277
275
  {
278
276
  }
279
277
 
280
278
  ~connectionImple()
281
279
  {
282
- m_ios.stop();
280
+
283
281
  try
284
282
  {
283
+ m_ios.stop();
285
284
  m_socket.close();
286
285
  }
287
286
  catch (...)
@@ -299,7 +298,6 @@ public:
299
298
  buffers* optionalBuffers() { return &m_optionalBuffes; }
300
299
  };
301
300
 
302
- #define TIMEOUT_SEC 3
303
301
 
304
302
  /** Implementation of The TCP connection.
305
303
  */
@@ -317,7 +315,7 @@ public:
317
315
  void setupTimeouts()
318
316
  {
319
317
  #if defined _WIN32
320
- int32_t timeout = TIMEOUT_SEC * 1000;
318
+ int32_t timeout = connections::timeout;
321
319
  setsockopt(m_socket.native(), SOL_SOCKET, SO_RCVTIMEO,
322
320
  (const char*)&timeout, sizeof(timeout));
323
321
  setsockopt(m_socket.native(), SOL_SOCKET, SO_SNDTIMEO,
@@ -325,7 +323,7 @@ public:
325
323
  #else
326
324
  struct timeval timeout;
327
325
  timeout.tv_usec = 0;
328
- timeout.tv_sec = TIMEOUT_SEC;
326
+ timeout.tv_sec = connections::timeout;
329
327
  setsockopt(m_socket.native(), SOL_SOCKET, SO_RCVTIMEO, &timeout,
330
328
  sizeof(timeout));
331
329
  setsockopt(m_socket.native(), SOL_SOCKET, SO_SNDTIMEO, &timeout,
@@ -379,6 +377,13 @@ class pipeConnection : public connectionImple<platform_stream>
379
377
  HANDLE m_sendEvent;
380
378
  HANDLE m_mapFile;
381
379
 
380
+ bool queryFunction(unsigned int v)
381
+ {
382
+ if (v == CONNECTION_FUNCTION_DIRECT_READ)
383
+ return false;
384
+ return false;
385
+ }
386
+
382
387
  char* GetErrorMessage(DWORD ErrorCode)
383
388
  {
384
389
  LPVOID lpMsgBuf;
@@ -517,10 +522,14 @@ public:
517
522
 
518
523
  char* asyncWriteRead(unsigned int writeSize)
519
524
  {
520
- m_datalen = 0;
521
- m_rows = 0;
522
- SetEvent(m_sendEvent);
523
- WaitForSingleObject(m_recvEvent, INFINITE);
525
+ //m_datalen = 0;
526
+ //m_rows = 0;
527
+ BOOL ret = SetEvent(m_sendEvent);
528
+ if (ret == FALSE)
529
+ throwException("SetEvent", CLIENT_ERROR_CONNECTION_FAILURE);
530
+ DWORD r = WaitForSingleObject(m_recvEvent, connections::timeout);
531
+ if (r == WAIT_TIMEOUT)
532
+ throwException("SetEvent", CLIENT_ERROR_CONNECTION_FAILURE);
524
533
  return m_readbuf_p;
525
534
  }
526
535