Skip to content

Commit 0ff5b47

Browse files
committed
make sure that mysql socket is cooperative wrt gc global lock
1 parent b3e21c2 commit 0ff5b47

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

libs/mysql/socket.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define _GNU_SOURCE
2323
#include "socket.h"
2424
#include <string.h>
25+
#include <hl.h>
2526

2627
#ifdef OS_WINDOWS
2728
static int init_done = 0;
@@ -97,30 +98,37 @@ void psock_close( PSOCK s ) {
9798

9899
int psock_send( PSOCK s, const char *buf, int size ) {
99100
int ret;
101+
hl_blocking(true);
100102
POSIX_LABEL(send_again);
101103
ret = send(s,buf,size,MSG_NOSIGNAL);
102104
if( ret == SOCKET_ERROR ) {
103105
HANDLE_EINTR(send_again);
106+
hl_blocking(false);
104107
return block_error();
105108
}
109+
hl_blocking(false);
106110
return ret;
107111
}
108112

109113
int psock_recv( PSOCK s, char *buf, int size ) {
110114
int ret;
115+
hl_blocking(true);
111116
POSIX_LABEL(recv_again);
112117
ret = recv(s,buf,size,MSG_NOSIGNAL);
113118
if( ret == SOCKET_ERROR ) {
114119
HANDLE_EINTR(recv_again);
120+
hl_blocking(false);
115121
return block_error();
116122
}
123+
hl_blocking(false);
117124
return ret;
118125
}
119126

120127
PHOST phost_resolve( const char *host ) {
121128
PHOST ip = inet_addr(host);
122129
if( ip == INADDR_NONE ) {
123130
struct hostent *h;
131+
hl_blocking(true);
124132
# if defined(OS_WINDOWS) || defined(OS_MAC) || defined(OS_CYGWIN)
125133
h = gethostbyname(host);
126134
# else
@@ -129,6 +137,7 @@ PHOST phost_resolve( const char *host ) {
129137
int errcode;
130138
gethostbyname_r(host,&hbase,buf,1024,&h,&errcode);
131139
# endif
140+
hl_blocking(false);
132141
if( h == NULL )
133142
return UNRESOLVED_HOST;
134143
ip = *((unsigned int*)h->h_addr_list[0]);
@@ -142,8 +151,12 @@ SERR psock_connect( PSOCK s, PHOST host, int port ) {
142151
addr.sin_family = AF_INET;
143152
addr.sin_port = htons(port);
144153
*(int*)&addr.sin_addr.s_addr = host;
145-
if( connect(s,(struct sockaddr*)&addr,sizeof(addr)) != 0 )
154+
hl_blocking(true);
155+
if( connect(s,(struct sockaddr*)&addr,sizeof(addr)) != 0 ) {
156+
hl_blocking(false);
146157
return block_error();
158+
}
159+
hl_blocking(false);
147160
return PS_OK;
148161
}
149162

@@ -193,6 +206,7 @@ SERR psock_set_fastsend( PSOCK s, int fast ) {
193206
}
194207

195208
void psock_wait( PSOCK s ) {
209+
hl_blocking(true);
196210
# ifdef OS_WINDOWS
197211
fd_set set;
198212
FD_ZERO(&set);
@@ -208,6 +222,7 @@ void psock_wait( PSOCK s ) {
208222
HANDLE_EINTR(poll_again);
209223
}
210224
# endif
225+
hl_blocking(false);
211226
}
212227

213228
/* ************************************************************************ */

0 commit comments

Comments
 (0)