1 /* Copyright (c) 2003-2005 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
17 #include <ndb_global.h>
19 #include "SHM_Transporter.hpp"
20 #include "TransporterInternalDefinitions.hpp"
21 #include <TransporterCallback.hpp>
28 void SHM_Transporter::make_error_info(char info
[], int sz
)
30 snprintf(info
,sz
,"Shm key=%d sz=%d id=%d",
31 shmKey
, shmSize
, shmId
);
35 SHM_Transporter::ndb_shm_create()
37 shmId
= shmget(shmKey
, shmSize
, IPC_CREAT
| 960);
46 SHM_Transporter::ndb_shm_get()
48 shmId
= shmget(shmKey
, shmSize
, 0);
57 SHM_Transporter::ndb_shm_attach()
59 shmBuf
= (char *)shmat(shmId
, 0, 0);
68 SHM_Transporter::checkConnected(){
70 const int res
= shmctl(shmId
, IPC_STAT
, &info
);
73 int r
= snprintf(buf
, sizeof(buf
),
74 "shmctl(%d, IPC_STAT) errno: %d(%s). ", shmId
,
75 errno
, strerror(errno
));
76 make_error_info(buf
+r
, sizeof(buf
)-r
);
77 DBUG_PRINT("error",(buf
));
81 report_error(TE_SHM_IPC_PERMANENT
, buf
);
84 report_error(TE_SHM_IPC_STAT
, buf
);
90 if(info
.shm_nattch
!= 2){
92 make_error_info(buf
, sizeof(buf
));
93 report_error(TE_SHM_DISCONNECT
);
94 DBUG_PRINT("error", ("Already connected to node %d",
102 SHM_Transporter::disconnectImpl(){
104 const int res
= shmdt(shmBuf
);
106 perror("shmdelete: ");
110 if(!isServer
&& _shmSegCreated
)
111 _shmSegCreated
= false;
114 if(isServer
&& _shmSegCreated
){
115 const int res
= shmctl(shmId
, IPC_RMID
, 0);
118 make_error_info(buf
, sizeof(buf
));
119 report_error(TE_SHM_UNABLE_TO_REMOVE_SEGMENT
);
122 _shmSegCreated
= false;
124 setupBuffersDone
=false;