20 #include <ndb_global.h>
22 #include "SHM_Transporter.hpp"
23 #include "TransporterInternalDefinitions.hpp"
24 #include <TransporterCallback.hpp>
31 void SHM_Transporter::make_error_info(
char info[],
int sz)
33 snprintf(info,sz,
"Shm key=%d sz=%d",
38 SHM_Transporter::connectServer(Uint32 timeOutMillis){
42 sprintf(szName,
"ndb%lu", shmKey);
43 hFileMapping = CreateFileMapping(INVALID_HANDLE_VALUE,
52 reportThreadError(remoteNodeId, TE_SHM_UNABLE_TO_CREATE_SEGMENT);
53 NdbSleep_MilliSleep(timeOutMillis);
56 _shmSegCreated =
true;
60 shmBuf = (
char*)MapViewOfFile(hFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
62 reportThreadError(remoteNodeId, TE_SHM_UNABLE_TO_ATTACH_SEGMENT);
63 NdbSleep_MilliSleep(timeOutMillis);
66 volatile Uint32 * sharedCountAttached =
67 (
volatile Uint32*)(shmBuf + 6*
sizeof(Uint32*));
68 ++*sharedCountAttached;
72 volatile Uint32 * sharedCountAttached =
73 (
volatile Uint32*)(shmBuf + 6*
sizeof(Uint32*));
75 if(*sharedCountAttached == 2 && !setupBuffersDone) {
77 setupBuffersDone=
true;
79 if(*sharedCountAttached > 2) {
80 reportThreadError(remoteNodeId, TE_SHM_DISCONNECT);
84 if(setupBuffersDone) {
85 NdbSleep_MilliSleep(timeOutMillis);
86 if(*serverStatusFlag==1 && *clientStatusFlag==1)
90 NdbSleep_MilliSleep(timeOutMillis);
95 SHM_Transporter::connectClient(Uint32 timeOutMillis){
99 sprintf(szName,
"ndb%lu", shmKey);
100 hFileMapping = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, szName);
104 NdbSleep_MilliSleep(timeOutMillis);
107 _shmSegCreated =
true;
111 shmBuf = (
char*)MapViewOfFile(hFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);
113 reportThreadError(remoteNodeId, TE_SHM_UNABLE_TO_ATTACH_SEGMENT);
114 NdbSleep_MilliSleep(timeOutMillis);
117 volatile Uint32 * sharedCountAttached =
118 (
volatile Uint32*)(shmBuf + 6*
sizeof(Uint32*));
119 ++*sharedCountAttached;
123 volatile Uint32 * sharedCountAttached =
124 (
volatile Uint32*)(shmBuf + 6*
sizeof(Uint32*));
126 if(*sharedCountAttached == 2 && !setupBuffersDone) {
128 setupBuffersDone=
true;
131 if(setupBuffersDone) {
132 if(*serverStatusFlag==1 && *clientStatusFlag==1)
135 NdbSleep_MilliSleep(timeOutMillis);
143 volatile Uint32 * sharedCountAttached =
144 (
volatile Uint32*)(shmBuf + 6*
sizeof(Uint32*));
145 if(*sharedCountAttached != 2) {
146 report_error(TE_SHM_DISCONNECT);
155 volatile Uint32 * sharedCountAttached =
156 (
volatile Uint32*)(shmBuf + 6*
sizeof(Uint32*));
158 --*sharedCountAttached;
160 if(!UnmapViewOfFile(shmBuf)) {
161 report_error(TE_SHM_UNABLE_TO_REMOVE_SEGMENT);
166 if(!isServer && _shmSegCreated)
167 _shmSegCreated =
false;
171 if(!CloseHandle(hFileMapping)) {
172 report_error(TE_SHM_UNABLE_TO_REMOVE_SEGMENT);
175 _shmSegCreated =
false;
177 setupBuffersDone=
false;