diff options
author | Volodymyr Gotra <vgotra@gmail.com> | 2017-01-16 02:34:28 +0200 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2017-01-25 00:04:45 +0100 |
commit | b62247e0ea23139a9922a1de965357907319e937 (patch) | |
tree | 29ea509b9386d35016f0e103c9fe469e8229e760 /lib | |
parent | 55f976e0decefb284b0f0a459745dd57f038ab4f (diff) | |
download | thrift-b62247e0ea23139a9922a1de965357907319e937.tar.gz |
THRIFT-4039 Update of Apache Thrift .Net Core lib
Client: NetCore
Patch: Volodymyr Gotra <vgotra@gmail.com>
This closes #1163
Changes:
- Added framed transport, updated docs, updated global.json with SDKversion
- Added usage to multiplexer to tutorial
- Changed sdk to current sdk 1.0.0-preview2-1-003177
Diffstat (limited to 'lib')
-rw-r--r-- | lib/netcore/README.md | 30 | ||||
-rw-r--r-- | lib/netcore/Thrift/TBaseClient.cs | 1 | ||||
-rw-r--r-- | lib/netcore/Thrift/Transports/Client/TFramedClientTransport.cs | 2 | ||||
-rw-r--r-- | lib/netcore/Thrift/Transports/Server/TServerFramedTransport.cs | 150 | ||||
-rw-r--r-- | lib/netcore/global.json | 5 |
5 files changed, 177 insertions, 11 deletions
diff --git a/lib/netcore/README.md b/lib/netcore/README.md index ae926e978..a2b19a88c 100644 --- a/lib/netcore/README.md +++ b/lib/netcore/README.md @@ -2,20 +2,34 @@ Thrift client library ported to Microsoft .Net Core +# Content +- Tests/Thrift.PublicInterfaces.Compile.Tests - project for checking public interfaces during adding changes to Thrift library +- Thrift - Thrift library + +# Reused components +- NET Core Standard 1.6 (SDK 1.0.0-preview2-003121) +- NET Core App 1.1 + # How to build -* Download the latest version of dotnet from https://www.microsoft.com/net/core (it can be https://go.microsoft.com/fwlink/?LinkID=809122 in case of VS Code) -* Install downloaded version of dotnet -* Clone repo -* Run **build.sh** or **build.cmd** from the root of cloned repository -* Check tests in **src/Tests** folder -* Continue with /tutorials/netcore +- Download and install .NET Core SDK for your platform https://www.microsoft.com/net/core#windowsvs2015 +- Ensure that you have thrift.exe which supports netcore lib and it added to PATH +- Go to current folder +- Run **build.sh** or **build.cmd** from the root of cloned repository +- Check tests in **src/Tests** folder +- Continue with /tutorials/netcore #Notes -* No Silverlight suport, no longer supported by Microsoft +- Migration to .NET Standard 2.0 planned for later (Q1 2017) according to https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/ +- Possible adding additional platforms after stabilization of .NET Core (runtimes, platforms (Red Haat Linux, OpenSuse, etc.) #Known issues -* Framed transport not fully implemenented yet +- In trace logging mode you can see some not important internal exceptions +- Ubuntu 16.10 still not supported fully +- There is some problems with .NET Core CLI and usage specific -r|--runtime for building and publishing projects with different target frameworks (netstandard1.6 and netcoreapp1.1) + +# Troubleshouting +It's possible to change dotnet SDK version for building for solution (in **global.json**). Just run **dotnet --info** to check your current version (or check your dotnet sdk folder for installed versions)
\ No newline at end of file diff --git a/lib/netcore/Thrift/TBaseClient.cs b/lib/netcore/Thrift/TBaseClient.cs index 24e08cef9..5b338c6a9 100644 --- a/lib/netcore/Thrift/TBaseClient.cs +++ b/lib/netcore/Thrift/TBaseClient.cs @@ -35,6 +35,7 @@ namespace Thrift private readonly TProtocol _outputProtocol; private bool _isDisposed; private int _seqId; + public readonly Guid ClientId = Guid.NewGuid(); protected TBaseClient(TProtocol inputProtocol, TProtocol outputProtocol) { diff --git a/lib/netcore/Thrift/Transports/Client/TFramedClientTransport.cs b/lib/netcore/Thrift/Transports/Client/TFramedClientTransport.cs index 514c1a6e6..f54a42a86 100644 --- a/lib/netcore/Thrift/Transports/Client/TFramedClientTransport.cs +++ b/lib/netcore/Thrift/Transports/Client/TFramedClientTransport.cs @@ -37,8 +37,6 @@ namespace Thrift.Transports.Client public TFramedClientTransport(TClientTransport transport) { - throw new NotImplementedException("TFramedClientTransport is not fully ready for usage"); - if (transport == null) { throw new ArgumentNullException(nameof(transport)); diff --git a/lib/netcore/Thrift/Transports/Server/TServerFramedTransport.cs b/lib/netcore/Thrift/Transports/Server/TServerFramedTransport.cs new file mode 100644 index 000000000..0b86e9ebb --- /dev/null +++ b/lib/netcore/Thrift/Transports/Server/TServerFramedTransport.cs @@ -0,0 +1,150 @@ +// Licensed to the Apache Software Foundation(ASF) under one +// or more contributor license agreements.See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership.The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using System.Threading.Tasks; +using Thrift.Transports.Client; + +namespace Thrift.Transports.Server +{ + // ReSharper disable once InconsistentNaming + public class TServerFramedTransport : TServerTransport + { + private readonly int _clientTimeout; + private readonly int _port; + private TcpListener _server; + + public TServerFramedTransport(TcpListener listener) + : this(listener, 0) + { + } + + public TServerFramedTransport(TcpListener listener, int clientTimeout) + { + _server = listener; + _clientTimeout = clientTimeout; + } + + public TServerFramedTransport(int port) + : this(port, 0) + { + } + + public TServerFramedTransport(int port, int clientTimeout) + { + _port = port; + _clientTimeout = clientTimeout; + try + { + // Make server socket + _server = new TcpListener(IPAddress.Any, _port); + _server.Server.NoDelay = true; + } + catch (Exception) + { + _server = null; + throw new TTransportException("Could not create ServerSocket on port " + port + "."); + } + } + + public override void Listen() + { + // Make sure not to block on accept + if (_server != null) + { + try + { + _server.Start(); + } + catch (SocketException sx) + { + throw new TTransportException("Could not accept on listening socket: " + sx.Message); + } + } + } + + public override bool IsClientPending() + { + return _server.Pending(); + } + + protected override async Task<TClientTransport> AcceptImplementationAsync(CancellationToken cancellationToken) + { + if (cancellationToken.IsCancellationRequested) + { + return await Task.FromCanceled<TClientTransport>(cancellationToken); + } + + if (_server == null) + { + throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket."); + } + + try + { + TFramedClientTransport tSocketTransport = null; + var tcpClient = await _server.AcceptTcpClientAsync(); + + try + { + tSocketTransport = new TFramedClientTransport(new TSocketClientTransport(tcpClient) + { + Timeout = _clientTimeout + }); + + return tSocketTransport; + } + catch (Exception) + { + if (tSocketTransport != null) + { + tSocketTransport.Dispose(); + } + else // Otherwise, clean it up ourselves. + { + ((IDisposable) tcpClient).Dispose(); + } + + throw; + } + } + catch (Exception ex) + { + throw new TTransportException(ex.ToString()); + } + } + + public override void Close() + { + if (_server != null) + { + try + { + _server.Stop(); + } + catch (Exception ex) + { + throw new TTransportException("WARNING: Could not close server socket: " + ex); + } + _server = null; + } + } + } +}
\ No newline at end of file diff --git a/lib/netcore/global.json b/lib/netcore/global.json index 8c0927574..e5162419d 100644 --- a/lib/netcore/global.json +++ b/lib/netcore/global.json @@ -1,3 +1,6 @@ { - "projects": [ "." ] + "projects": [ "." ], + "sdk": { + "version": "1.0.0-preview2-1-003177" // "1.0.0-preview2-003121", "1.0.0-preview4-004233" + } }
\ No newline at end of file |