Skip to content

Commit 82a304f

Browse files
committed
Fail silently in cases where we cannot connect to server
1 parent 9f1b866 commit 82a304f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

mysql-plugin/src/mysql-notification.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ my_bool MySQLNotification_init(UDF_INIT *initid,
6464
_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
6565
if (_server == -1) {
6666
strcpy(message, "Failed to create socket");
67-
return -1;
67+
return 0;
6868
}
6969

7070
// bind to local address
@@ -74,7 +74,7 @@ my_bool MySQLNotification_init(UDF_INIT *initid,
7474
saddr.sin_addr.s_addr = inet_addr(LOCAL_ADDRESS);
7575
if (bind(_server, (struct sockaddr*)&saddr, sizeof(saddr)) != 0) {
7676
sprintf(message, "Failed to bind to %s", LOCAL_ADDRESS);
77-
return -1;
77+
return 0;
7878
}
7979

8080
// connect to server
@@ -84,15 +84,13 @@ my_bool MySQLNotification_init(UDF_INIT *initid,
8484
remote.sin_addr.s_addr = inet_addr(SERVER_ADDRESS);
8585
if (connect(_server, (struct sockaddr*)&remote, sizeof(remote)) != 0) {
8686
sprintf(message, "Failed to connect to server %s:%d", SERVER_ADDRESS, SERVER_PORT);
87-
return -1;
88-
}
87+
return 0;
88+
}
8989

9090
return 0;
9191
}
9292

9393
void MySQLNotification_deinit(UDF_INIT *initid) {
94-
// free any allocated memory here
95-
//free((longlong*)initid->ptr);
9694
// close server socket
9795
if (_server != -1) {
9896
close(_server);
@@ -108,7 +106,9 @@ longlong MySQLNotification(UDF_INIT *initid,
108106
// format a message containing id of row and type of change
109107
sprintf(packet, "{\"id\":\"%lld\", \"type\":\"%lld\"}", *((longlong*)args->args[0]), *((longlong*)args->args[1]));
110108

111-
send(_server, packet, strlen(packet), 0);
109+
if (_server != -1) {
110+
send(_server, packet, strlen(packet), 0);
111+
}
112112

113113
return 0;
114114
}

0 commit comments

Comments
 (0)