Skip to content

Commit 4307922

Browse files
palichoroba
authored andcommitted
Connection to Embedded server does not have socket
Connection to Embedded server is not socket orientated, so it does not have socket. Fix code and tests for Embedded server connection.
1 parent c7e42cc commit 4307922

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

dbdimp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,12 @@ static bool mariadb_dr_connect(
23762376
sock->reconnect = FALSE;
23772377
#endif
23782378

2379+
/* Connection to Embedded server does not have socket */
2380+
if (imp_dbh->is_embedded)
2381+
{
2382+
imp_dbh->sock_fd = -1;
2383+
}
2384+
else
23792385
{
23802386
my_socket sock_os;
23812387
int retval;
@@ -3171,8 +3177,11 @@ static void mariadb_db_close_mysql(pTHX_ imp_drh_t *imp_drh, imp_dbh_t *imp_dbh)
31713177
socket from C file descriptor sock_fd via _set_osfhnd() function and then
31723178
close sock_fd via close() function.
31733179
*/
3180+
if (imp_dbh->sock_fd >= 0)
3181+
{
31743182
_set_osfhnd(imp_dbh->sock_fd, INVALID_HANDLE_VALUE);
31753183
close(imp_dbh->sock_fd);
3184+
}
31763185
#endif
31773186
imp_dbh->sock_fd = -1;
31783187
svp = hv_fetchs((HV*)DBIc_MY_H(imp_dbh), "ChildHandles", FALSE);

t/15reconnect.t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ ok($dbh->do("SELECT 1"), "implicitly reconnecting handle with 'do'");
3838

3939
ok($dbh->{Active}, "checking for reactivated handle");
4040

41+
SKIP: {
42+
43+
skip "Connection to Embedded server does not have socket", 3 if $dbh->{mariadb_hostinfo} eq 'Embedded';
44+
4145
ok(shutdown_mariadb_socket($dbh), "shutdown socket handle");
4246

4347
ok($dbh->do("SELECT 1"), "implicitly reconnecting handle after shutdown with 'do'");
4448

4549
ok($dbh->{Active}, "checking for reactivated handle");
4650

51+
}
52+
4753
ok($dbh->disconnect(), "disconnecting active handle");
4854

4955
ok(!$dbh->{Active}, "checking for inactive handle");

t/17close_on_exec.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ require 'lib.pl';
1010

1111
my $dbh = DbiTestConnect($test_dsn, $test_user, $test_password, { RaiseError => 1, PrintError => 0 });
1212

13+
plan skip_all => "Connection to Embedded server does not have socket" if $dbh->{mariadb_hostinfo} eq 'Embedded';
14+
1315
plan tests => 2;
1416

1517
# Spawn new perl child process with MariaDB file descriptor passed as first argument and check that it is invalid (EBADF) in spawned process

t/18begin_work_without_raise_error.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ require 'lib.pl';
1010

1111
my $dbh = DbiTestConnect($test_dsn, $test_user, $test_password, { RaiseError => 0, PrintError => 1 });
1212

13+
plan skip_all => "Connection to Embedded server does not have socket" if $dbh->{mariadb_hostinfo} eq 'Embedded';
14+
1315
plan tests => 12;
1416

1517
my $warn;

t/lib.pl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ sub shutdown_mariadb_socket {
9191
# close automatically close C file descriptor in Perl file handle
9292
# mysql client library does not expect if somebody closes its file descriptors
9393
# so always take a copy of mariadb_sockfd() C file descriptor and just shutdown it
94-
open my $socket, '+<&', $dbh->mariadb_sockfd();
94+
my $fd = $dbh->mariadb_sockfd();
95+
return undef unless defined $fd;
96+
open my $socket, '+<&', $fd;
97+
return undef unless defined $socket;
9598
my $ret = shutdown($socket, 2);
9699
close $socket;
97100
return $ret;

t/rt110983-valid-mysqlfd.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ require "lib.pl";
1010

1111
my $dbh = DbiTestConnect($test_dsn, $test_user, $test_password, { RaiseError => 1, PrintError => 0, AutoCommit => 0 });
1212

13+
plan skip_all => "Connection to Embedded server does not have socket" if $dbh->{mariadb_hostinfo} eq 'Embedded';
14+
1315
plan tests => 4;
1416

1517
my $fd = $dbh->mariadb_sockfd;

0 commit comments

Comments
 (0)