From 6eb8ac278dd26f7f41e039d03002dcbb364de70c Mon Sep 17 00:00:00 2001 From: "adhavan.m" Date: Mon, 23 Jan 2017 19:54:58 +0530 Subject: [PATCH] Fix for Socket crash issue Signed-off-by: adhavan.m Change-Id: I47888f1a08f0be6130a4f1ae3a763c62cd5a1e15 --- .../Tizen.Network.Bluetooth/BluetoothServerSocket.cs | 7 ++++--- .../Tizen.Network.Bluetooth/BluetoothSocket.cs | 12 +++++++----- .../Tizen.Network.Bluetooth/BluetoothStructs.cs | 4 ++-- packaging/csapi-network-bluetooth.spec | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) mode change 100644 => 100755 Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothServerSocket.cs mode change 100644 => 100755 Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothSocket.cs diff --git a/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothServerSocket.cs b/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothServerSocket.cs old mode 100644 new mode 100755 index 0d1615e..b7bed91 --- a/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothServerSocket.cs +++ b/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothServerSocket.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -26,6 +26,7 @@ namespace Tizen.Network.Bluetooth public class BluetoothServerSocket : IDisposable { private event EventHandler _acceptStateChanged; + private Interop.Bluetooth.SocketConnectionStateChangedCallback _connectionStateChangedCallback; internal int socketFd; private bool disposed = false; @@ -54,7 +55,7 @@ namespace Tizen.Network.Bluetooth private void RegisterAcceptStateChangedEvent() { - Interop.Bluetooth.SocketConnectionStateChangedCallback ConnectionStateChangedCallback = (int result, BluetoothSocketState connectionState, ref SocketConnectionStruct socketConnection, IntPtr userData) => + _connectionStateChangedCallback = (int result, BluetoothSocketState connectionState, ref SocketConnectionStruct socketConnection, IntPtr userData) => { Log.Info(Globals.LogTag, "AcceptStateChanged cb is called"); if (_acceptStateChanged != null) @@ -67,7 +68,7 @@ namespace Tizen.Network.Bluetooth }; GCHandle handle1 = GCHandle.Alloc(this); IntPtr data = (IntPtr) handle1; - int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(ConnectionStateChangedCallback, data); + int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(_connectionStateChangedCallback, data); if (ret != (int)BluetoothError.None) { Log.Error(Globals.LogTag, "Failed to set accept state changed callback, Error - " + (BluetoothError)ret); diff --git a/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothSocket.cs b/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothSocket.cs old mode 100644 new mode 100755 index 4fb8416..c24b0d4 --- a/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothSocket.cs +++ b/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothSocket.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -43,6 +43,8 @@ namespace Tizen.Network.Bluetooth { private event EventHandler _dataReceived; private event EventHandler _connectionStateChanged; + private Interop.Bluetooth.DataReceivedCallback _dataReceivedCallback; + private Interop.Bluetooth.SocketConnectionStateChangedCallback _connectionStateChangedCallback; private bool disposed = false; internal int connectedSocket; internal string remoteAddress; @@ -96,7 +98,7 @@ namespace Tizen.Network.Bluetooth private void RegisterDataReceivedEvent() { - Interop.Bluetooth.DataReceivedCallback DataReceivedCallback = (ref SocketDataStruct socketData, IntPtr userData) => + _dataReceivedCallback = (ref SocketDataStruct socketData, IntPtr userData) => { Log.Info(Globals.LogTag, "DataReceivedCallback is called"); if (_dataReceived != null) @@ -107,7 +109,7 @@ namespace Tizen.Network.Bluetooth }; GCHandle handle1 = GCHandle.Alloc (this); IntPtr uData = (IntPtr) handle1; - int ret = Interop.Bluetooth.SetDataReceivedCallback(DataReceivedCallback, uData); + int ret = Interop.Bluetooth.SetDataReceivedCallback(_dataReceivedCallback, uData); if (ret != (int)BluetoothError.None) { Log.Error(Globals.LogTag, "Failed to set data received callback, Error - " + (BluetoothError)ret); @@ -127,7 +129,7 @@ namespace Tizen.Network.Bluetooth private void RegisterConnectionStateChangedEvent() { - Interop.Bluetooth.SocketConnectionStateChangedCallback ConnectionStateChangedCallback = (int result, BluetoothSocketState connectionState, ref SocketConnectionStruct socketConnection, IntPtr userData) => + _connectionStateChangedCallback = (int result, BluetoothSocketState connectionState, ref SocketConnectionStruct socketConnection, IntPtr userData) => { Log.Info(Globals.LogTag, "ConnectionStateChangedCallback is called"); if (_connectionStateChanged != null) @@ -139,7 +141,7 @@ namespace Tizen.Network.Bluetooth }; GCHandle handle1 = GCHandle.Alloc(this); IntPtr data = (IntPtr) handle1; - int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(ConnectionStateChangedCallback, data); + int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(_connectionStateChangedCallback, data); if (ret != (int)BluetoothError.None) { Log.Error(Globals.LogTag, "Failed to set connection state changed callback, Error - " + (BluetoothError)ret); diff --git a/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs b/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs index 9a2e87a..476e1d8 100755 --- a/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs +++ b/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothStructs.cs @@ -154,7 +154,7 @@ namespace Tizen.Network.Bluetooth { internal int SocketFd; internal int DataSize; - internal string Data; + internal IntPtr Data; } internal struct SocketConnectionStruct @@ -327,7 +327,7 @@ namespace Tizen.Network.Bluetooth SocketData data = new SocketData(); data.Fd = structInfo.SocketFd; data.Size = structInfo.DataSize; - data.RecvData = structInfo.Data; + data.RecvData = Marshal.PtrToStringAnsi(structInfo.Data); return data; } diff --git a/packaging/csapi-network-bluetooth.spec b/packaging/csapi-network-bluetooth.spec index de935bf..6b07ae2 100644 --- a/packaging/csapi-network-bluetooth.spec +++ b/packaging/csapi-network-bluetooth.spec @@ -8,7 +8,7 @@ Name: csapi-network-bluetooth Summary: Tizen Bluetooth API for C# -Version: 1.0.5 +Version: 1.0.6 Release: 1 Group: Development/Libraries License: Apache-2.0 -- 2.7.4