diff options
author | Mario Emmenlauer <mario@emmenlauer.de> | 2020-06-02 11:06:59 +0200 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2020-06-04 21:18:01 +0200 |
commit | bde5cbc0788b936aff516e2c0527ff950cc9b466 (patch) | |
tree | dbd75297c718a7ebbf5b36f4dd50f4a73c3ae4a3 /lib/netstd | |
parent | eac4d0c79a5fc550fb61bc18f20d3b5aae8f6e7f (diff) | |
download | thrift-bde5cbc0788b936aff516e2c0527ff950cc9b466.tar.gz |
Added IsOpen() and GetPort() for netstd transports
Client: netstd
Patch: Mario Emmenlauer
This closes #2166
Diffstat (limited to 'lib/netstd')
4 files changed, 69 insertions, 11 deletions
diff --git a/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs b/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs index aea0f865a..338111001 100644 --- a/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs +++ b/lib/netstd/Thrift/Transport/Server/TNamedPipeServerTransport.cs @@ -44,6 +44,10 @@ namespace Thrift.Transport.Server _pipeAddress = pipeAddress; } + public override bool IsOpen() { + return true; + } + public override void Listen() { // nothing to do here diff --git a/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs b/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs index 281c7ffe5..d7421c944 100644 --- a/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs +++ b/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs @@ -5,9 +5,9 @@ // 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 @@ -54,6 +54,32 @@ namespace Thrift.Transport.Server } } + public override bool IsOpen() + { + return (_server != null) + && (_server.Server != null) + && _server.Server.IsBound; + } + + public int GetPort() + { + if ((_server != null) && (_server.Server != null) && (_server.Server.LocalEndPoint != null)) + { + if (_server.Server.LocalEndPoint is IPEndPoint server) + { + return server.Port; + } + else + { + throw new TTransportException("ServerSocket is not a network socket"); + } + } + else + { + throw new TTransportException("ServerSocket is not open"); + } + } + public override void Listen() { // Make sure not to block on accept @@ -91,7 +117,7 @@ namespace Thrift.Transport.Server try { - tSocketTransport = new TSocketTransport(tcpClient,Configuration) + tSocketTransport = new TSocketTransport(tcpClient, Configuration) { Timeout = _clientTimeout }; @@ -106,7 +132,7 @@ namespace Thrift.Transport.Server } else // Otherwise, clean it up ourselves. { - ((IDisposable) tcpClient).Dispose(); + ((IDisposable)tcpClient).Dispose(); } throw; diff --git a/lib/netstd/Thrift/Transport/Server/TServerTransport.cs b/lib/netstd/Thrift/Transport/Server/TServerTransport.cs index 31f578d54..eee50fb5a 100644 --- a/lib/netstd/Thrift/Transport/Server/TServerTransport.cs +++ b/lib/netstd/Thrift/Transport/Server/TServerTransport.cs @@ -5,9 +5,9 @@ // 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 @@ -30,6 +30,8 @@ namespace Thrift.Transport Configuration = config ?? new TConfiguration(); } + public abstract bool IsOpen(); + public abstract void Listen(); public abstract void Close(); public abstract bool IsClientPending(); @@ -41,7 +43,7 @@ namespace Thrift.Transport protected abstract ValueTask<TTransport> AcceptImplementationAsync(CancellationToken cancellationToken); - public async ValueTask<TTransport> AcceptAsync() + public async ValueTask<TTransport> AcceptAsync() { return await AcceptAsync(CancellationToken.None); } diff --git a/lib/netstd/Thrift/Transport/Server/TTlsServerSocketTransport.cs b/lib/netstd/Thrift/Transport/Server/TTlsServerSocketTransport.cs index 79d2b1137..77abcaeb5 100644 --- a/lib/netstd/Thrift/Transport/Server/TTlsServerSocketTransport.cs +++ b/lib/netstd/Thrift/Transport/Server/TTlsServerSocketTransport.cs @@ -5,9 +5,9 @@ // 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 @@ -36,7 +36,7 @@ namespace Thrift.Transport.Server private readonly X509Certificate2 _serverCertificate; private readonly SslProtocols _sslProtocols; private TcpListener _server; - + public TTlsServerSocketTransport( TcpListener listener, TConfiguration config, @@ -81,6 +81,32 @@ namespace Thrift.Transport.Server } } + public override bool IsOpen() + { + return (_server != null) + && (_server.Server != null) + && _server.Server.IsBound; + } + + public int GetPort() + { + if ((_server != null) && (_server.Server != null) && (_server.Server.LocalEndPoint != null)) + { + if (_server.Server.LocalEndPoint is IPEndPoint server) + { + return server.Port; + } + else + { + throw new TTransportException("ServerSocket is not a network socket"); + } + } + else + { + throw new TTransportException("ServerSocket is not open"); + } + } + public override void Listen() { // Make sure accept is not blocking @@ -123,7 +149,7 @@ namespace Thrift.Transport.Server _localCertificateSelectionCallback, _sslProtocols); await tTlsSocket.SetupTlsAsync(); - + return tTlsSocket; } catch (Exception ex) |