]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8796 #resolve [issues with verto mcast]
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 28 Jan 2016 18:29:45 +0000 (12:29 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 28 Jan 2016 18:29:45 +0000 (12:29 -0600)
src/mod/endpoints/mod_verto/mcast/mcast.c
src/mod/endpoints/mod_verto/mod_verto.c

index 915c831df40889999e859005368566a75935a315..f15ff6efc5917171bf21eabda1995fc9ce9e6efc 100644 (file)
@@ -68,7 +68,7 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle,
                family = AF_INET6;
        }
        
-       if ((!(flags & MCAST_SEND) && !(flags & MCAST_RECV)) || (handle->sock = (mcast_socket_t)socket(family, SOCK_DGRAM, 0)) != mcast_sock_invalid ) {
+       if ((!(flags & MCAST_SEND) && !(flags & MCAST_RECV)) || (handle->sock = (mcast_socket_t)socket(family, SOCK_DGRAM, 0)) == mcast_sock_invalid ) {
                return -1;
        }
 
@@ -190,7 +190,8 @@ void mcast_socket_close(mcast_handle_t *handle)
 
 ssize_t mcast_socket_send(mcast_handle_t *handle, void *data, size_t datalen)
 {
-       if (handle->sock != mcast_sock_invalid) {
+       if (handle->sock == mcast_sock_invalid) {
+               errno = EINVAL;
                return -1;
        }
 
@@ -202,6 +203,7 @@ ssize_t mcast_socket_send(mcast_handle_t *handle, void *data, size_t datalen)
        if (handle->family == AF_INET6) {
                return sendto(handle->sock, data, (int)datalen, 0, (struct sockaddr *) &handle->send_addr6, sizeof(handle->send_addr6));
        } else {
+               //printf("WTF %d %p %ld %s\n", handle->sock, (void *)data, datalen, inet_ntoa(handle->send_addr.sin_addr));
                return sendto(handle->sock, data, (int)datalen, 0, (struct sockaddr *) &handle->send_addr, sizeof(handle->send_addr));
        }
 }
@@ -210,6 +212,11 @@ ssize_t mcast_socket_recv(mcast_handle_t *handle, void *data, size_t datalen, in
 {
        socklen_t addrlen = sizeof(handle->recv_addr);
 
+       if (handle->sock == mcast_sock_invalid) {
+               errno = EINVAL;
+               return -1;
+       }
+
        if (data == NULL || datalen == 0) {
                data = handle->buffer;
                datalen = sizeof(handle->buffer);
index ba1e78752fc212a5a5b220a047d8caddebd97031..24dc581e47f6bf84a3849c7978ceb230fb360e74 100644 (file)
@@ -3798,14 +3798,16 @@ static switch_bool_t verto__broadcast_func(const char *method, cJSON *params, js
        if (jsock->profile->mcast_pub.sock != ws_sock_invalid) {
                if ((json_text = cJSON_PrintUnformatted(params))) {
 
-                       if ( mcast_socket_send(&jsock->profile->mcast_pub, json_text, strlen(json_text) + 1) < 0 ) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "multicast socket send error!\n");
+                       if (mcast_socket_send(&jsock->profile->mcast_pub, json_text, strlen(json_text) + 1) <= 0) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "multicast socket send error! %s\n", strerror(errno));
+                               r = SWITCH_FALSE;
+                               cJSON_AddItemToObject(*response, "message", cJSON_CreateString("MCAST Data Send failure!"));
+                       } else {
+                               r = SWITCH_TRUE;
+                               cJSON_AddItemToObject(*response, "message", cJSON_CreateString("MCAST Data Sent"));
                        }
-
                        free(json_text);
                        json_text = NULL;
-                       r = SWITCH_TRUE;
-                       cJSON_AddItemToObject(*response, "message", cJSON_CreateString("MCAST Data Sent"));
                } else {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "JSON ERROR!\n");
                }
@@ -4481,6 +4483,10 @@ static switch_status_t parse_config(const char *cf)
 
                        profile->local_network = "localnet.auto";
 
+                       profile->mcast_sub.sock = ws_sock_invalid;
+                       profile->mcast_pub.sock = ws_sock_invalid;
+
+
                        for (param = switch_xml_child(xprofile, "param"); param; param = param->next) {
                                char *var = NULL;
                                char *val = NULL;