Commit f2727ff2 authored by unknown's avatar unknown

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
parent 2ad6ceb2
......@@ -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
......
......@@ -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;
}
......@@ -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;
}
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment