centralize closing and freeing logic for connections
This commit is contained in:
parent
ba4f3612b6
commit
0a7e7ee475
@ -104,8 +104,10 @@ static VALUE nogvl_connect(void *ptr) {
|
||||
return client ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
static void rb_mysql_client_free(void * ptr) {
|
||||
mysql_client_wrapper *wrapper = (mysql_client_wrapper *)ptr;
|
||||
static VALUE nogvl_close(void *ptr) {
|
||||
mysql_client_wrapper *wrapper = ptr;
|
||||
if (!wrapper->closed) {
|
||||
wrapper->closed = 1;
|
||||
|
||||
/*
|
||||
* we'll send a QUIT message to the server, but that message is more of a
|
||||
@ -129,29 +131,25 @@ static void rb_mysql_client_free(void * ptr) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/* It's safe to call mysql_close() on an already closed connection. */
|
||||
if (!wrapper->closed) {
|
||||
mysql_close(wrapper->client);
|
||||
if (!wrapper->freed) {
|
||||
free(wrapper->client);
|
||||
}
|
||||
}
|
||||
xfree(ptr);
|
||||
}
|
||||
|
||||
static VALUE nogvl_close(void * ptr) {
|
||||
mysql_client_wrapper *wrapper = ptr;
|
||||
if (!wrapper->closed) {
|
||||
wrapper->closed = 1;
|
||||
mysql_close(wrapper->client);
|
||||
wrapper->client->net.fd = -1;
|
||||
}
|
||||
|
||||
if (!wrapper->freed) {
|
||||
wrapper->freed = 1;
|
||||
free(wrapper->client);
|
||||
}
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static void rb_mysql_client_free(void * ptr) {
|
||||
mysql_client_wrapper *wrapper = (mysql_client_wrapper *)ptr;
|
||||
|
||||
nogvl_close(wrapper);
|
||||
|
||||
xfree(ptr);
|
||||
}
|
||||
|
||||
static VALUE allocate(VALUE klass) {
|
||||
VALUE obj;
|
||||
mysql_client_wrapper * wrapper;
|
||||
|
Loading…
Reference in New Issue
Block a user