]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10054: [mod_smpp] mod_smpp will not reconnect if connection was interupted #resolve
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 17 Feb 2017 20:23:34 +0000 (14:23 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 17 Feb 2017 20:23:52 +0000 (14:23 -0600)
src/mod/event_handlers/mod_smpp/mod_smpp_gateway.c

index e4a927b1117cb6b0f8decb4494f08fb5f90c7bd2..15448178293d63ff3af2ed0a269cd9d3512e55fc 100644 (file)
@@ -178,6 +178,22 @@ switch_status_t mod_smpp_gateway_authenticate(mod_smpp_gateway_t *gateway) {
 switch_status_t mod_smpp_gateway_connect(mod_smpp_gateway_t *gateway) {
        switch_status_t status;
 
+       if (gateway->socket) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Closing existing socket\n");
+               switch_socket_shutdown(gateway->socket, SWITCH_SHUTDOWN_READWRITE);
+               switch_socket_close(gateway->socket);
+               gateway->socket = NULL;
+       }
+
+
+       if (!gateway->socket) {
+               if ( switch_socket_create(&(gateway->socket), switch_sockaddr_get_family(gateway->socketaddr),
+                                                                 SOCK_STREAM, SWITCH_PROTO_TCP, mod_smpp_globals.pool) != SWITCH_STATUS_SUCCESS ) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create the socket\n");
+                       return SWITCH_STATUS_GENERR;
+               }
+       }
+       
        if ( (status = switch_socket_connect(gateway->socket, gateway->socketaddr)) != SWITCH_STATUS_SUCCESS ) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to connect the socket %d\n", status);
                return SWITCH_STATUS_GENERR;
@@ -190,7 +206,6 @@ switch_status_t mod_smpp_gateway_connect(mod_smpp_gateway_t *gateway) {
        return SWITCH_STATUS_SUCCESS;
 }
 
-
 /* Expects the gateway to be locked already */
 switch_status_t mod_smpp_gateway_connection_read(mod_smpp_gateway_t *gateway, switch_event_t **event, unsigned int *command_id)
 {
@@ -302,7 +317,9 @@ static void *SWITCH_THREAD_FUNC mod_smpp_gateway_read_thread(switch_thread_t *th
 
                if ( mod_smpp_gateway_connection_read(gateway, &event, &command_id) != SWITCH_STATUS_SUCCESS) {
                        if ( gateway->running ) {
+                               printf("WTF??\n");
                                if ( mod_smpp_gateway_connect(gateway) != SWITCH_STATUS_SUCCESS) {
+                               printf("WTF2??\n");
                                        switch_sleep(1000 * 1000);
                                }
                        }