You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2020/06/04 19:21:02 UTC
[thrift] branch master updated: Added IsOpen() and GetPort() for
netstd transports Client: netstd Patch: Mario Emmenlauer
This is an automated email from the ASF dual-hosted git repository.
jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new bde5cbc Added IsOpen() and GetPort() for netstd transports Client: netstd Patch: Mario Emmenlauer
bde5cbc is described below
commit bde5cbc0788b936aff516e2c0527ff950cc9b466
Author: Mario Emmenlauer <ma...@emmenlauer.de>
AuthorDate: Tue Jun 2 11:06:59 2020 +0200
Added IsOpen() and GetPort() for netstd transports
Client: netstd
Patch: Mario Emmenlauer
This closes #2166
---
.../Transport/Server/TNamedPipeServerTransport.cs | 4 +++
.../Transport/Server/TServerSocketTransport.cs | 34 +++++++++++++++++++---
.../Thrift/Transport/Server/TServerTransport.cs | 8 +++--
.../Transport/Server/TTlsServerSocketTransport.cs | 34 +++++++++++++++++++---
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 aea0f86..3381110 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 281c7ff..d7421c9 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 31f578d..eee50fb 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 79d2b11..77abcae 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)