@@ -64,7 +64,7 @@ my_bool MySQLNotification_init(UDF_INIT *initid,
64
64
_server = socket (AF_INET , SOCK_STREAM , IPPROTO_TCP );
65
65
if (_server == -1 ) {
66
66
strcpy (message , "Failed to create socket" );
67
- return -1 ;
67
+ return 0 ;
68
68
}
69
69
70
70
// bind to local address
@@ -74,7 +74,7 @@ my_bool MySQLNotification_init(UDF_INIT *initid,
74
74
saddr .sin_addr .s_addr = inet_addr (LOCAL_ADDRESS );
75
75
if (bind (_server , (struct sockaddr * )& saddr , sizeof (saddr )) != 0 ) {
76
76
sprintf (message , "Failed to bind to %s" , LOCAL_ADDRESS );
77
- return -1 ;
77
+ return 0 ;
78
78
}
79
79
80
80
// connect to server
@@ -84,15 +84,13 @@ my_bool MySQLNotification_init(UDF_INIT *initid,
84
84
remote .sin_addr .s_addr = inet_addr (SERVER_ADDRESS );
85
85
if (connect (_server , (struct sockaddr * )& remote , sizeof (remote )) != 0 ) {
86
86
sprintf (message , "Failed to connect to server %s:%d" , SERVER_ADDRESS , SERVER_PORT );
87
- return -1 ;
88
- }
87
+ return 0 ;
88
+ }
89
89
90
90
return 0 ;
91
91
}
92
92
93
93
void MySQLNotification_deinit (UDF_INIT * initid ) {
94
- // free any allocated memory here
95
- //free((longlong*)initid->ptr);
96
94
// close server socket
97
95
if (_server != -1 ) {
98
96
close (_server );
@@ -108,7 +106,9 @@ longlong MySQLNotification(UDF_INIT *initid,
108
106
// format a message containing id of row and type of change
109
107
sprintf (packet , "{\"id\":\"%lld\", \"type\":\"%lld\"}" , * ((longlong * )args -> args [0 ]), * ((longlong * )args -> args [1 ]));
110
108
111
- send (_server , packet , strlen (packet ), 0 );
109
+ if (_server != -1 ) {
110
+ send (_server , packet , strlen (packet ), 0 );
111
+ }
112
112
113
113
return 0 ;
114
114
}
0 commit comments