From: Nishant Chaprana Date: Wed, 23 Sep 2020 15:15:54 +0000 (+0530) Subject: Use mutex instead of copying of network_info inside event handler X-Git-Tag: submit/tizen/20201008.114009^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c40a6afad33d2be4a8150c029c41b42eb392f8f4;p=platform%2Fcore%2Fapi%2Fconnection.git Use mutex instead of copying of network_info inside event handler Change-Id: Ia8f8b86ed6ea293c3ed6703109dce020d276871f Signed-off-by: Nishant Chaprana --- diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec index 69e3da9..26d0699 100755 --- a/packaging/capi-network-connection.spec +++ b/packaging/capi-network-connection.spec @@ -1,6 +1,6 @@ Name: capi-network-connection Summary: Network Connection library in TIZEN C API -Version: 1.0.122 +Version: 1.0.123 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/libnetwork.c b/src/libnetwork.c index 89d3cdb..401841c 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -170,20 +170,16 @@ static void __libnet_clear_profile_list(struct _profile_list_s *profile_list) static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data) { + CONN_LOCK; bool is_requested = false; connection_error_e result = CONNECTION_ERROR_NONE; - CONN_LOCK; - connection_handle_s conn_handle_local; - connection_handle_s *conn_handle = &conn_handle_local; - connection_handle_s *conn_handle_origin = (connection_handle_s *)user_data; + connection_handle_s *conn_handle = (connection_handle_s *)user_data; - if(!_connection_check_handle_validity(conn_handle_origin)) { + if (!_connection_check_handle_validity(conn_handle)) { CONNECTION_LOG(CONNECTION_INFO, "Invalid handle"); CONN_UNLOCK; return; } - memcpy(conn_handle, conn_handle_origin, sizeof(connection_handle_s)); - CONN_UNLOCK; switch (event_cb->Event) { case NET_EVENT_OPEN_RSP: @@ -211,6 +207,7 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data) CONNECTION_LOG(CONNECTION_INFO, "Successfully open connection"); __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_CONNECTED); + CONN_UNLOCK; return; default: CONNECTION_LOG(CONNECTION_ERROR, "Failed to open connection[%s]", @@ -244,6 +241,7 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data) CONNECTION_LOG(CONNECTION_INFO, "Successfully closed connection"); __libnet_state_changed_cb(event_cb->ProfileName, CONNECTION_PROFILE_STATE_DISCONNECTED); + CONN_UNLOCK; return; default: CONNECTION_LOG(CONNECTION_ERROR, "Failed to close connection[%s]", @@ -254,8 +252,10 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data) case NET_EVENT_NET_STATE_IND: CONNECTION_LOG(CONNECTION_INFO, "State changed IND"); - if (event_cb->Datalength != sizeof(net_state_type_t)) + if (event_cb->Datalength != sizeof(net_state_type_t)) { + CONN_UNLOCK; return; + } net_state_type_t *profile_state = (net_state_type_t *)event_cb->Data; connection_profile_state_e cp_state = _profile_convert_to_cp_state(*profile_state); @@ -422,6 +422,8 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data) default: break; } + + CONN_UNLOCK; } //LCOV_EXCL_STOP