diff options
author | unknown <stewart@mysql.com> | 2005-08-17 08:40:11 +1000 |
---|---|---|
committer | unknown <stewart@mysql.com> | 2005-08-17 08:40:11 +1000 |
commit | f2727ff26a160f981d300edd6cba79e49867db58 (patch) | |
tree | 41feb355753303fc813eef0438c6b06ebefb1209 /ndb | |
parent | 2ad6ceb23e825816d954349eb384457145dd4076 (diff) | |
download | mariadb-git-f2727ff26a160f981d300edd6cba79e49867db58.tar.gz |
BUG#10950
make previous patch portable by abstracting to Ndb_check_socket_hup.
Is in portlib rather than mysys due to the socket parameter being NDB_SOCKET_TYPE
ndb/include/portlib/NdbTCP.h:
Add Ndb_check_socket_hup prototype
ndb/src/common/portlib/NdbTCP.cpp:
Implement Ndb_check_socket_hup for unix like systems using the poll system call.
ndb/src/common/portlib/win32/NdbTCP.c:
Implement Ndb_check_socket_hup(NDB_SOCKET_TYPE) for win32 using the select() call.
(should work okay - unable to test on win32 due to status of ndb port though)
ndb/src/mgmapi/mgmapi.cpp:
Use the portable (portlib) Ndb_check_socket_hup to check socket status
Diffstat (limited to 'ndb')
-rw-r--r-- | ndb/include/portlib/NdbTCP.h | 2 | ||||
-rw-r--r-- | ndb/src/common/portlib/NdbTCP.cpp | 15 | ||||
-rw-r--r-- | ndb/src/common/portlib/win32/NdbTCP.c | 32 | ||||
-rw-r--r-- | ndb/src/mgmapi/mgmapi.cpp | 9 |
4 files changed, 50 insertions, 8 deletions
diff --git a/ndb/include/portlib/NdbTCP.h b/ndb/include/portlib/NdbTCP.h index 308a3833ffd..9ed5b5e7f96 100644 --- a/ndb/include/portlib/NdbTCP.h +++ b/ndb/include/portlib/NdbTCP.h @@ -95,6 +95,8 @@ int Ndb_getInAddr(struct in_addr * dst, const char *address); int NDB_CLOSE_SOCKET(int fd); #endif +int Ndb_check_socket_hup(NDB_SOCKET_TYPE sock); + #ifdef __cplusplus } #endif diff --git a/ndb/src/common/portlib/NdbTCP.cpp b/ndb/src/common/portlib/NdbTCP.cpp index c7b9d33c5f6..768292ac7c0 100644 --- a/ndb/src/common/portlib/NdbTCP.cpp +++ b/ndb/src/common/portlib/NdbTCP.cpp @@ -83,3 +83,18 @@ Ndb_getInAddr(struct in_addr * dst, const char *address) { return -1; } #endif + +int Ndb_check_socket_hup(NDB_SOCKET_TYPE sock) +{ + struct pollfd pfd[1]; + int r; + + pfd[0].fd= sock; + pfd[0].events= POLLHUP | POLLIN | POLLOUT | POLLNVAL; + pfd[0].revents= 0; + r= poll(pfd,1,0); + if(pfd[0].revents & (POLLHUP|POLLERR)) + return 1; + + return 0; +} diff --git a/ndb/src/common/portlib/win32/NdbTCP.c b/ndb/src/common/portlib/win32/NdbTCP.c index b936cd2db6c..a14cd4409eb 100644 --- a/ndb/src/common/portlib/win32/NdbTCP.c +++ b/ndb/src/common/portlib/win32/NdbTCP.c @@ -37,3 +37,35 @@ Ndb_getInAddr(struct in_addr * dst, const char *address) return -1; } +int Ndb_check_socket_hup(NDB_SOCKET_TYPE sock) +{ + fd_set readfds, writefds, errorfds; + struct timeval tv= {0,0}; + int s_err; + int s_err_size= sizeof(s_err); + + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&errorfds); + + FD_SET(sock, &readfds); + FD_SET(sock, &writefds); + FD_SET(sock, &errorfds); + + if(select(1, &readfds, &writefds, &errorfds, &t)==SOCKET_ERROR) + return 1; + + if(FD_ISSET(sock,&errorfds)) + return 1; + + s_err=0; + if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0) + return(1); + + if (s_err) + { /* getsockopt could succeed */ + return(1); /* but return an error... */ + } + + return 0; +} diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp index 26885a148a6..9f393d10528 100644 --- a/ndb/src/mgmapi/mgmapi.cpp +++ b/ndb/src/mgmapi/mgmapi.cpp @@ -360,19 +360,12 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow<ParserDummy> *command_reply, extern "C" int ndb_mgm_is_connected(NdbMgmHandle handle) { - struct pollfd pfd[1]; - int r; - if(!handle) return 0; if(handle->connected) { - pfd[0].fd= handle->socket; - pfd[0].events= POLLHUP | POLLIN | POLLOUT | POLLNVAL; - pfd[0].revents= 0; - r= poll(pfd,1,0); - if(pfd[0].revents & POLLHUP) + if(Ndb_check_socket_hup(handle->socket)) { handle->connected= 0; NDB_CLOSE_SOCKET(handle->socket); |