From cba92fcef07d49fd6f198b99175ac7e538e45a83 Mon Sep 17 00:00:00 2001 From: s-tarasov Date: Thu, 3 Nov 2016 00:32:47 +0300 Subject: [PATCH 1/5] Prevent throw IOException in Thread Pool Thread --- Sphinx.Client/Network/TcpStreamAdapter.cs | 43 ++++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/Sphinx.Client/Network/TcpStreamAdapter.cs b/Sphinx.Client/Network/TcpStreamAdapter.cs index 403a3bd..0e13005 100644 --- a/Sphinx.Client/Network/TcpStreamAdapter.cs +++ b/Sphinx.Client/Network/TcpStreamAdapter.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Text; using System.Threading; using Sphinx.Client.Helpers; using Sphinx.Client.Resources; @@ -44,6 +42,11 @@ public override int ReadBytes(byte[] buffer, int length) _resetEvent.Reset(); Stream.BeginRead(buffer, length - state.BytesLeft, state.BytesLeft, ReadDataCallback, state); WaitForNetworkData(); + + if (!string.IsNullOrEmpty(state.ErrorMessage)) + { + throw new IOException(state.ErrorMessage); + } } return length; } @@ -66,19 +69,41 @@ private void WaitForNetworkData() private void ReadDataCallback(IAsyncResult asyncResult) { NetworkReadState state = ((NetworkReadState)asyncResult.AsyncState); - if (!state.DataStream.CanRead) - throw new IOException(String.Format(Messages.Exception_CouldNotReadFromStream, state.BytesLeft, 0)); - int actualBytes = state.DataStream.EndRead(asyncResult); - if (actualBytes == 0) - throw new IOException(String.Format(Messages.Exception_CouldNotReadFromStream, state.BytesLeft, actualBytes)); - state.BytesLeft -= actualBytes; - _resetEvent.Set(); + try + { + if (!state.DataStream.CanRead) + { + state.ErrorMessage = String.Format(Messages.Exception_CouldNotReadFromStream, state.BytesLeft, 0); + } + else + { + + int actualBytes = state.DataStream.EndRead(asyncResult); + if (actualBytes == 0) + { + state.ErrorMessage = String.Format(Messages.Exception_CouldNotReadFromStream, state.BytesLeft, actualBytes); + } + else + { + state.BytesLeft -= actualBytes; + } + } + } + catch (Exception ex) + { + state.ErrorMessage = ex.ToString(); + } + finally + { + _resetEvent.Set(); + } } private class NetworkReadState { public Stream DataStream; public int BytesLeft; + public string ErrorMessage; } #endregion From b66a2738a4baf42127ca494ca932a71cdde04387 Mon Sep 17 00:00:00 2001 From: s-tarasov Date: Tue, 15 Nov 2016 04:08:38 +0300 Subject: [PATCH 2/5] Added nuspec --- Sphinx.Client/Sphinx.Client.nuspec | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Sphinx.Client/Sphinx.Client.nuspec diff --git a/Sphinx.Client/Sphinx.Client.nuspec b/Sphinx.Client/Sphinx.Client.nuspec new file mode 100644 index 0000000..c1df526 --- /dev/null +++ b/Sphinx.Client/Sphinx.Client.nuspec @@ -0,0 +1,15 @@ + + + + Sphinx.Client + 1.0.1.0 + Sphinx.Client + eionov Eskat0n starasov + eionov Eskat0n starasov + http://www.gnu.org/licenses/lgpl.html + https://github.com/s-tarasov/Sphinx.Client + false + Open source .NET library which provides advanced client API to use Sphinx search server services, using Sphinx native binary protocol. It can be used from C#, VB.Net etc. + Sphinx + + \ No newline at end of file From 5a1affe5fd2d8f110b6e21b9bd7c206c4a18394f Mon Sep 17 00:00:00 2001 From: s-tarasov Date: Tue, 15 Nov 2016 04:51:29 +0300 Subject: [PATCH 3/5] Added create Nuget-Package script --- Sphinx.Client/NugetPack.bat | 1 + Sphinx.Client/Sphinx.Client.csproj | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Sphinx.Client/NugetPack.bat diff --git a/Sphinx.Client/NugetPack.bat b/Sphinx.Client/NugetPack.bat new file mode 100644 index 0000000..0702796 --- /dev/null +++ b/Sphinx.Client/NugetPack.bat @@ -0,0 +1 @@ +nuget pack Sphinx.Client.csproj -properties Configuration=Release \ No newline at end of file diff --git a/Sphinx.Client/Sphinx.Client.csproj b/Sphinx.Client/Sphinx.Client.csproj index fa25f18..53cafec 100644 --- a/Sphinx.Client/Sphinx.Client.csproj +++ b/Sphinx.Client/Sphinx.Client.csproj @@ -46,7 +46,7 @@ pdbonly true - ..\..\bin\ + bin\Release\ TRACE prompt 4 @@ -206,6 +206,9 @@ true + + +