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 2014/10/03 20:13:29 UTC
[08/10] THRIFT-2768: Whitespace Fixup Client: C#,
Delphi Patch: Jens Geyer
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TType.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Protocol/TType.cs b/lib/csharp/src/Protocol/TType.cs
index efc7bef..9ce915e 100644
--- a/lib/csharp/src/Protocol/TType.cs
+++ b/lib/csharp/src/Protocol/TType.cs
@@ -25,20 +25,20 @@ using System;
namespace Thrift.Protocol
{
- public enum TType : byte
- {
- Stop = 0,
- Void = 1,
- Bool = 2,
- Byte = 3,
- Double = 4,
- I16 = 6,
- I32 = 8,
- I64 = 10,
- String = 11,
- Struct = 12,
- Map = 13,
- Set = 14,
- List = 15
- }
+ public enum TType : byte
+ {
+ Stop = 0,
+ Void = 1,
+ Bool = 2,
+ Byte = 3,
+ Double = 4,
+ I16 = 6,
+ I32 = 8,
+ I64 = 10,
+ String = 11,
+ Struct = 12,
+ Map = 13,
+ Set = 14,
+ List = 15
+ }
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Server/TSimpleServer.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Server/TSimpleServer.cs b/lib/csharp/src/Server/TSimpleServer.cs
index 42e0cbe..36bbe9d 100644
--- a/lib/csharp/src/Server/TSimpleServer.cs
+++ b/lib/csharp/src/Server/TSimpleServer.cs
@@ -118,7 +118,7 @@ namespace Thrift.Server
//Process client requests until client disconnects
while (true)
{
- if (!inputTransport.Peek())
+ if (!inputTransport.Peek())
break;
//Fire processContext server event
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Server/TThreadPoolServer.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Server/TThreadPoolServer.cs b/lib/csharp/src/Server/TThreadPoolServer.cs
index 8542b6d..aff5733 100644
--- a/lib/csharp/src/Server/TThreadPoolServer.cs
+++ b/lib/csharp/src/Server/TThreadPoolServer.cs
@@ -172,7 +172,7 @@ namespace Thrift.Server
//Process client requests until client disconnects
while (true)
{
- if (!inputTransport.Peek())
+ if (!inputTransport.Peek())
break;
//Fire processContext server event
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Server/TThreadedServer.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Server/TThreadedServer.cs b/lib/csharp/src/Server/TThreadedServer.cs
index 87bff31..9e96371 100644
--- a/lib/csharp/src/Server/TThreadedServer.cs
+++ b/lib/csharp/src/Server/TThreadedServer.cs
@@ -204,7 +204,7 @@ namespace Thrift.Server
//Process client requests until client disconnects
while (true)
{
- if (!inputTransport.Peek())
+ if (!inputTransport.Peek())
break;
//Fire processContext server event
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/TApplicationException.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/TApplicationException.cs b/lib/csharp/src/TApplicationException.cs
index 4a1b2d2..4c0d3a3 100644
--- a/lib/csharp/src/TApplicationException.cs
+++ b/lib/csharp/src/TApplicationException.cs
@@ -26,116 +26,116 @@ using Thrift.Protocol;
namespace Thrift
{
- public class TApplicationException : TException
- {
- protected ExceptionType type;
-
- public TApplicationException()
- {
- }
-
- public TApplicationException(ExceptionType type)
- {
- this.type = type;
- }
-
- public TApplicationException(ExceptionType type, string message)
- : base(message)
- {
- this.type = type;
- }
-
- public static TApplicationException Read(TProtocol iprot)
- {
- TField field;
-
- string message = null;
- ExceptionType type = ExceptionType.Unknown;
-
- iprot.ReadStructBegin();
- while (true)
- {
- field = iprot.ReadFieldBegin();
- if (field.Type == TType.Stop)
- {
- break;
- }
-
- switch (field.ID)
- {
- case 1:
- if (field.Type == TType.String)
- {
- message = iprot.ReadString();
- }
- else
- {
- TProtocolUtil.Skip(iprot, field.Type);
- }
- break;
- case 2:
- if (field.Type == TType.I32)
- {
- type = (ExceptionType)iprot.ReadI32();
- }
- else
- {
- TProtocolUtil.Skip(iprot, field.Type);
- }
- break;
- default:
- TProtocolUtil.Skip(iprot, field.Type);
- break;
- }
-
- iprot.ReadFieldEnd();
- }
-
- iprot.ReadStructEnd();
-
- return new TApplicationException(type, message);
- }
-
- public void Write(TProtocol oprot)
- {
- TStruct struc = new TStruct("TApplicationException");
- TField field = new TField();
-
- oprot.WriteStructBegin(struc);
-
- if (!String.IsNullOrEmpty(Message))
- {
- field.Name = "message";
- field.Type = TType.String;
- field.ID = 1;
- oprot.WriteFieldBegin(field);
- oprot.WriteString(Message);
- oprot.WriteFieldEnd();
- }
-
- field.Name = "type";
- field.Type = TType.I32;
- field.ID = 2;
- oprot.WriteFieldBegin(field);
- oprot.WriteI32((int)type);
- oprot.WriteFieldEnd();
- oprot.WriteFieldStop();
- oprot.WriteStructEnd();
- }
-
- public enum ExceptionType
- {
- Unknown,
- UnknownMethod,
- InvalidMessageType,
- WrongMethodName,
- BadSequenceID,
- MissingResult,
- InternalError,
- ProtocolError,
- InvalidTransform,
- InvalidProtocol,
- UnsupportedClientType
- }
- }
+ public class TApplicationException : TException
+ {
+ protected ExceptionType type;
+
+ public TApplicationException()
+ {
+ }
+
+ public TApplicationException(ExceptionType type)
+ {
+ this.type = type;
+ }
+
+ public TApplicationException(ExceptionType type, string message)
+ : base(message)
+ {
+ this.type = type;
+ }
+
+ public static TApplicationException Read(TProtocol iprot)
+ {
+ TField field;
+
+ string message = null;
+ ExceptionType type = ExceptionType.Unknown;
+
+ iprot.ReadStructBegin();
+ while (true)
+ {
+ field = iprot.ReadFieldBegin();
+ if (field.Type == TType.Stop)
+ {
+ break;
+ }
+
+ switch (field.ID)
+ {
+ case 1:
+ if (field.Type == TType.String)
+ {
+ message = iprot.ReadString();
+ }
+ else
+ {
+ TProtocolUtil.Skip(iprot, field.Type);
+ }
+ break;
+ case 2:
+ if (field.Type == TType.I32)
+ {
+ type = (ExceptionType)iprot.ReadI32();
+ }
+ else
+ {
+ TProtocolUtil.Skip(iprot, field.Type);
+ }
+ break;
+ default:
+ TProtocolUtil.Skip(iprot, field.Type);
+ break;
+ }
+
+ iprot.ReadFieldEnd();
+ }
+
+ iprot.ReadStructEnd();
+
+ return new TApplicationException(type, message);
+ }
+
+ public void Write(TProtocol oprot)
+ {
+ TStruct struc = new TStruct("TApplicationException");
+ TField field = new TField();
+
+ oprot.WriteStructBegin(struc);
+
+ if (!String.IsNullOrEmpty(Message))
+ {
+ field.Name = "message";
+ field.Type = TType.String;
+ field.ID = 1;
+ oprot.WriteFieldBegin(field);
+ oprot.WriteString(Message);
+ oprot.WriteFieldEnd();
+ }
+
+ field.Name = "type";
+ field.Type = TType.I32;
+ field.ID = 2;
+ oprot.WriteFieldBegin(field);
+ oprot.WriteI32((int)type);
+ oprot.WriteFieldEnd();
+ oprot.WriteFieldStop();
+ oprot.WriteStructEnd();
+ }
+
+ public enum ExceptionType
+ {
+ Unknown,
+ UnknownMethod,
+ InvalidMessageType,
+ WrongMethodName,
+ BadSequenceID,
+ MissingResult,
+ InternalError,
+ ProtocolError,
+ InvalidTransform,
+ InvalidProtocol,
+ UnsupportedClientType
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/TException.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/TException.cs b/lib/csharp/src/TException.cs
index a99bfa8..65509ec 100644
--- a/lib/csharp/src/TException.cs
+++ b/lib/csharp/src/TException.cs
@@ -25,16 +25,16 @@ using System;
namespace Thrift
{
- public class TException : Exception
- {
- public TException()
- {
- }
+ public class TException : Exception
+ {
+ public TException()
+ {
+ }
- public TException( string message)
- : base(message)
- {
- }
+ public TException( string message)
+ : base(message)
+ {
+ }
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/TProcessor.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/TProcessor.cs b/lib/csharp/src/TProcessor.cs
index dc1b795..71ce755 100644
--- a/lib/csharp/src/TProcessor.cs
+++ b/lib/csharp/src/TProcessor.cs
@@ -26,8 +26,8 @@ using Thrift.Protocol;
namespace Thrift
{
- public interface TProcessor
- {
- bool Process(TProtocol iprot, TProtocol oprot);
- }
+ public interface TProcessor
+ {
+ bool Process(TProtocol iprot, TProtocol oprot);
+ }
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Thrift.WP7.csproj
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Thrift.WP7.csproj b/lib/csharp/src/Thrift.WP7.csproj
index d35adf4..ee4942f 100644
--- a/lib/csharp/src/Thrift.WP7.csproj
+++ b/lib/csharp/src/Thrift.WP7.csproj
@@ -108,7 +108,7 @@
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
<ProjectExtensions />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Thrift.sln
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Thrift.sln b/lib/csharp/src/Thrift.sln
index ee0a3e7..dd8437d 100644
--- a/lib/csharp/src/Thrift.sln
+++ b/lib/csharp/src/Thrift.sln
@@ -4,35 +4,35 @@ Microsoft Visual Studio Solution File, Format Version 11.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thrift", "Thrift.csproj", "{499EB63C-D74C-47E8-AE48-A2FC94538E9D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftTest", "..\test\ThriftTest\ThriftTest.csproj", "{48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}"
- ProjectSection(ProjectDependencies) = postProject
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D} = {499EB63C-D74C-47E8-AE48-A2FC94538E9D}
- EndProjectSection
+ ProjectSection(ProjectDependencies) = postProject
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D} = {499EB63C-D74C-47E8-AE48-A2FC94538E9D}
+ EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftMSBuildTask", "..\ThriftMSBuildTask\ThriftMSBuildTask.csproj", "{EC0A0231-66EA-4593-A792-C6CA3BB8668E}"
EndProject
Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.Build.0 = Release|Any CPU
- {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.Build.0 = Release|Any CPU
- {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(MonoDevelopProperties) = preSolution
- StartupItem = Thrift.csproj
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = Thrift.csproj
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
EndGlobal
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TBufferedTransport.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TBufferedTransport.cs b/lib/csharp/src/Transport/TBufferedTransport.cs
index 6cb0457..89b9ca7 100644
--- a/lib/csharp/src/Transport/TBufferedTransport.cs
+++ b/lib/csharp/src/Transport/TBufferedTransport.cs
@@ -23,85 +23,85 @@ using System.IO;
namespace Thrift.Transport
{
public class TBufferedTransport : TTransport, IDisposable
- {
- private BufferedStream inputBuffer;
- private BufferedStream outputBuffer;
- private int bufSize;
- private TStreamTransport transport;
-
- public TBufferedTransport(TStreamTransport transport)
- :this(transport, 1024)
- {
-
- }
-
- public TBufferedTransport(TStreamTransport transport, int bufSize)
- {
- this.bufSize = bufSize;
- this.transport = transport;
- InitBuffers();
- }
-
- private void InitBuffers()
- {
- if (transport.InputStream != null)
- {
- inputBuffer = new BufferedStream(transport.InputStream, bufSize);
- }
- if (transport.OutputStream != null)
- {
- outputBuffer = new BufferedStream(transport.OutputStream, bufSize);
- }
- }
-
- private void CloseBuffers()
- {
- if (inputBuffer != null && inputBuffer.CanRead)
- {
- inputBuffer.Close();
- }
- if (outputBuffer != null && outputBuffer.CanWrite)
- {
- outputBuffer.Close();
- }
- }
-
- public TTransport UnderlyingTransport
- {
- get { return transport; }
- }
-
- public override bool IsOpen
- {
- get { return transport.IsOpen; }
- }
-
- public override void Open()
- {
- transport.Open();
- InitBuffers();
- }
-
- public override void Close()
- {
- CloseBuffers();
- transport.Close();
- }
-
- public override int Read(byte[] buf, int off, int len)
- {
- return inputBuffer.Read(buf, off, len);
- }
-
- public override void Write(byte[] buf, int off, int len)
- {
- outputBuffer.Write(buf, off, len);
- }
-
- public override void Flush()
- {
- outputBuffer.Flush();
- }
+ {
+ private BufferedStream inputBuffer;
+ private BufferedStream outputBuffer;
+ private int bufSize;
+ private TStreamTransport transport;
+
+ public TBufferedTransport(TStreamTransport transport)
+ :this(transport, 1024)
+ {
+
+ }
+
+ public TBufferedTransport(TStreamTransport transport, int bufSize)
+ {
+ this.bufSize = bufSize;
+ this.transport = transport;
+ InitBuffers();
+ }
+
+ private void InitBuffers()
+ {
+ if (transport.InputStream != null)
+ {
+ inputBuffer = new BufferedStream(transport.InputStream, bufSize);
+ }
+ if (transport.OutputStream != null)
+ {
+ outputBuffer = new BufferedStream(transport.OutputStream, bufSize);
+ }
+ }
+
+ private void CloseBuffers()
+ {
+ if (inputBuffer != null && inputBuffer.CanRead)
+ {
+ inputBuffer.Close();
+ }
+ if (outputBuffer != null && outputBuffer.CanWrite)
+ {
+ outputBuffer.Close();
+ }
+ }
+
+ public TTransport UnderlyingTransport
+ {
+ get { return transport; }
+ }
+
+ public override bool IsOpen
+ {
+ get { return transport.IsOpen; }
+ }
+
+ public override void Open()
+ {
+ transport.Open();
+ InitBuffers();
+ }
+
+ public override void Close()
+ {
+ CloseBuffers();
+ transport.Close();
+ }
+
+ public override int Read(byte[] buf, int off, int len)
+ {
+ return inputBuffer.Read(buf, off, len);
+ }
+
+ public override void Write(byte[] buf, int off, int len)
+ {
+ outputBuffer.Write(buf, off, len);
+ }
+
+ public override void Flush()
+ {
+ outputBuffer.Flush();
+ }
#region " IDisposable Support "
private bool _IsDisposed;
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TFramedTransport.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TFramedTransport.cs b/lib/csharp/src/Transport/TFramedTransport.cs
index aefbc09..8af227f 100644
--- a/lib/csharp/src/Transport/TFramedTransport.cs
+++ b/lib/csharp/src/Transport/TFramedTransport.cs
@@ -20,147 +20,147 @@ using System;
using System.IO;
namespace Thrift.Transport
-{
+{
public class TFramedTransport : TTransport, IDisposable
- {
- protected TTransport transport = null;
- protected MemoryStream writeBuffer;
- protected MemoryStream readBuffer = null;
-
- private const int header_size = 4;
- private static byte[] header_dummy = new byte[header_size]; // used as header placeholder while initilizing new write buffer
-
- public class Factory : TTransportFactory
- {
- public override TTransport GetTransport(TTransport trans)
- {
- return new TFramedTransport(trans);
- }
- }
-
- protected TFramedTransport()
- {
- InitWriteBuffer();
- }
-
- public TFramedTransport(TTransport transport) : this()
- {
- this.transport = transport;
- }
-
- public override void Open()
- {
- transport.Open();
- }
-
- public override bool IsOpen
- {
- get
- {
- return transport.IsOpen;
- }
- }
-
- public override void Close()
- {
- transport.Close();
- }
-
- public override int Read(byte[] buf, int off, int len)
- {
- if (readBuffer != null)
- {
- int got = readBuffer.Read(buf, off, len);
- if (got > 0)
- {
- return got;
- }
- }
-
- // Read another frame of data
- ReadFrame();
-
- return readBuffer.Read(buf, off, len);
- }
-
- private void ReadFrame()
- {
- byte[] i32rd = new byte[header_size];
- transport.ReadAll(i32rd, 0, header_size);
- int size = DecodeFrameSize(i32rd);
-
- byte[] buff = new byte[size];
- transport.ReadAll(buff, 0, size);
- readBuffer = new MemoryStream(buff);
- }
-
- public override void Write(byte[] buf, int off, int len)
- {
- writeBuffer.Write(buf, off, len);
- }
-
- public override void Flush()
- {
- byte[] buf = writeBuffer.GetBuffer();
- int len = (int)writeBuffer.Length;
- int data_len = len - header_size;
- if ( data_len < 0 )
- throw new System.InvalidOperationException (); // logic error actually
-
- InitWriteBuffer();
-
- // Inject message header into the reserved buffer space
- EncodeFrameSize(data_len,ref buf);
-
- // Send the entire message at once
- transport.Write(buf, 0, len);
-
- transport.Flush();
- }
-
- private void InitWriteBuffer ()
- {
- // Create new buffer instance
- writeBuffer = new MemoryStream(1024);
-
- // Reserve space for message header to be put right before sending it out
- writeBuffer.Write ( header_dummy, 0, header_size );
- }
-
- private static void EncodeFrameSize(int frameSize, ref byte[] buf)
- {
- buf[0] = (byte)(0xff & (frameSize >> 24));
- buf[1] = (byte)(0xff & (frameSize >> 16));
- buf[2] = (byte)(0xff & (frameSize >> 8));
- buf[3] = (byte)(0xff & (frameSize));
- }
-
- private static int DecodeFrameSize(byte[] buf)
- {
- return
- ((buf[0] & 0xff) << 24) |
- ((buf[1] & 0xff) << 16) |
- ((buf[2] & 0xff) << 8) |
- ((buf[3] & 0xff));
- }
-
-
- #region " IDisposable Support "
- private bool _IsDisposed;
-
- // IDisposable
- protected override void Dispose(bool disposing)
- {
- if (!_IsDisposed)
- {
- if (disposing)
- {
- if (readBuffer != null)
- readBuffer.Dispose();
- }
- }
- _IsDisposed = true;
- }
- #endregion
- }
+ {
+ protected TTransport transport = null;
+ protected MemoryStream writeBuffer;
+ protected MemoryStream readBuffer = null;
+
+ private const int header_size = 4;
+ private static byte[] header_dummy = new byte[header_size]; // used as header placeholder while initilizing new write buffer
+
+ public class Factory : TTransportFactory
+ {
+ public override TTransport GetTransport(TTransport trans)
+ {
+ return new TFramedTransport(trans);
+ }
+ }
+
+ protected TFramedTransport()
+ {
+ InitWriteBuffer();
+ }
+
+ public TFramedTransport(TTransport transport) : this()
+ {
+ this.transport = transport;
+ }
+
+ public override void Open()
+ {
+ transport.Open();
+ }
+
+ public override bool IsOpen
+ {
+ get
+ {
+ return transport.IsOpen;
+ }
+ }
+
+ public override void Close()
+ {
+ transport.Close();
+ }
+
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (readBuffer != null)
+ {
+ int got = readBuffer.Read(buf, off, len);
+ if (got > 0)
+ {
+ return got;
+ }
+ }
+
+ // Read another frame of data
+ ReadFrame();
+
+ return readBuffer.Read(buf, off, len);
+ }
+
+ private void ReadFrame()
+ {
+ byte[] i32rd = new byte[header_size];
+ transport.ReadAll(i32rd, 0, header_size);
+ int size = DecodeFrameSize(i32rd);
+
+ byte[] buff = new byte[size];
+ transport.ReadAll(buff, 0, size);
+ readBuffer = new MemoryStream(buff);
+ }
+
+ public override void Write(byte[] buf, int off, int len)
+ {
+ writeBuffer.Write(buf, off, len);
+ }
+
+ public override void Flush()
+ {
+ byte[] buf = writeBuffer.GetBuffer();
+ int len = (int)writeBuffer.Length;
+ int data_len = len - header_size;
+ if ( data_len < 0 )
+ throw new System.InvalidOperationException (); // logic error actually
+
+ InitWriteBuffer();
+
+ // Inject message header into the reserved buffer space
+ EncodeFrameSize(data_len,ref buf);
+
+ // Send the entire message at once
+ transport.Write(buf, 0, len);
+
+ transport.Flush();
+ }
+
+ private void InitWriteBuffer ()
+ {
+ // Create new buffer instance
+ writeBuffer = new MemoryStream(1024);
+
+ // Reserve space for message header to be put right before sending it out
+ writeBuffer.Write ( header_dummy, 0, header_size );
+ }
+
+ private static void EncodeFrameSize(int frameSize, ref byte[] buf)
+ {
+ buf[0] = (byte)(0xff & (frameSize >> 24));
+ buf[1] = (byte)(0xff & (frameSize >> 16));
+ buf[2] = (byte)(0xff & (frameSize >> 8));
+ buf[3] = (byte)(0xff & (frameSize));
+ }
+
+ private static int DecodeFrameSize(byte[] buf)
+ {
+ return
+ ((buf[0] & 0xff) << 24) |
+ ((buf[1] & 0xff) << 16) |
+ ((buf[2] & 0xff) << 8) |
+ ((buf[3] & 0xff));
+ }
+
+
+ #region " IDisposable Support "
+ private bool _IsDisposed;
+
+ // IDisposable
+ protected override void Dispose(bool disposing)
+ {
+ if (!_IsDisposed)
+ {
+ if (disposing)
+ {
+ if (readBuffer != null)
+ readBuffer.Dispose();
+ }
+ }
+ _IsDisposed = true;
+ }
+ #endregion
+ }
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/THttpClient.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/THttpClient.cs b/lib/csharp/src/Transport/THttpClient.cs
index 1581e83..a56a3e8 100644
--- a/lib/csharp/src/Transport/THttpClient.cs
+++ b/lib/csharp/src/Transport/THttpClient.cs
@@ -7,7 +7,7 @@
* "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
+ * 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
@@ -15,8 +15,8 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
- *
+ *
+ *
*/
using System;
@@ -48,40 +48,40 @@ namespace Thrift.Transport
private IWebProxy proxy = WebRequest.DefaultWebProxy;
#endif
- public THttpClient(Uri u)
+ public THttpClient(Uri u)
: this(u, Enumerable.Empty<X509Certificate>())
- {
- }
+ {
+ }
- public THttpClient(Uri u, IEnumerable<X509Certificate> certificates)
- {
- uri = u;
+ public THttpClient(Uri u, IEnumerable<X509Certificate> certificates)
+ {
+ uri = u;
this.certificates = (certificates ?? Enumerable.Empty<X509Certificate>()).ToArray();
- }
+ }
public int ConnectTimeout
- {
- set
- {
- connectTimeout = value;
- }
- }
-
- public int ReadTimeout
- {
- set
- {
- readTimeout = value;
- }
- }
-
- public IDictionary<String, String> CustomHeaders
- {
- get
- {
- return customHeaders;
- }
- }
+ {
+ set
+ {
+ connectTimeout = value;
+ }
+ }
+
+ public int ReadTimeout
+ {
+ set
+ {
+ readTimeout = value;
+ }
+ }
+
+ public IDictionary<String, String> CustomHeaders
+ {
+ get
+ {
+ return customHeaders;
+ }
+ }
#if !SILVERLIGHT
public IWebProxy Proxy
@@ -93,162 +93,162 @@ namespace Thrift.Transport
}
#endif
- public override bool IsOpen
- {
- get
- {
- return true;
- }
- }
-
- public override void Open()
- {
- }
-
- public override void Close()
- {
- if (inputStream != null)
- {
- inputStream.Close();
- inputStream = null;
- }
- if (outputStream != null)
- {
- outputStream.Close();
- outputStream = null;
- }
- }
-
- public override int Read(byte[] buf, int off, int len)
- {
- if (inputStream == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No request has been sent");
- }
-
- try
- {
- int ret = inputStream.Read(buf, off, len);
-
- if (ret == -1)
- {
- throw new TTransportException(TTransportException.ExceptionType.EndOfFile, "No more data available");
- }
-
- return ret;
- }
- catch (IOException iox)
- {
- throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
- }
- }
-
- public override void Write(byte[] buf, int off, int len)
- {
- outputStream.Write(buf, off, len);
- }
+ public override bool IsOpen
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ public override void Open()
+ {
+ }
+
+ public override void Close()
+ {
+ if (inputStream != null)
+ {
+ inputStream.Close();
+ inputStream = null;
+ }
+ if (outputStream != null)
+ {
+ outputStream.Close();
+ outputStream = null;
+ }
+ }
+
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (inputStream == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No request has been sent");
+ }
+
+ try
+ {
+ int ret = inputStream.Read(buf, off, len);
+
+ if (ret == -1)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.EndOfFile, "No more data available");
+ }
+
+ return ret;
+ }
+ catch (IOException iox)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
+ }
+ }
+
+ public override void Write(byte[] buf, int off, int len)
+ {
+ outputStream.Write(buf, off, len);
+ }
#if !SILVERLIGHT
- public override void Flush()
- {
- try
- {
- SendRequest();
- }
- finally
- {
- outputStream = new MemoryStream();
- }
- }
-
- private void SendRequest()
- {
- try
- {
- HttpWebRequest connection = CreateRequest();
-
- byte[] data = outputStream.ToArray();
- connection.ContentLength = data.Length;
-
- using (Stream requestStream = connection.GetRequestStream())
- {
- requestStream.Write(data, 0, data.Length);
-
- // Resolve HTTP hang that can happens after successive calls by making sure
- // that we release the response and response stream. To support this, we copy
- // the response to a memory stream.
- using (var response = connection.GetResponse())
- {
- using (var responseStream = response.GetResponseStream())
- {
- // Copy the response to a memory stream so that we can
- // cleanly close the response and response stream.
- inputStream = new MemoryStream();
- byte[] buffer = new byte[8096];
- int bytesRead;
- while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
- {
- inputStream.Write (buffer, 0, bytesRead);
- }
- inputStream.Seek(0, 0);
- }
- }
- }
- }
- catch (IOException iox)
- {
- throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
- }
- catch (WebException wx)
- {
- throw new TTransportException(TTransportException.ExceptionType.Unknown, "Couldn't connect to server: " + wx);
- }
- }
+ public override void Flush()
+ {
+ try
+ {
+ SendRequest();
+ }
+ finally
+ {
+ outputStream = new MemoryStream();
+ }
+ }
+
+ private void SendRequest()
+ {
+ try
+ {
+ HttpWebRequest connection = CreateRequest();
+
+ byte[] data = outputStream.ToArray();
+ connection.ContentLength = data.Length;
+
+ using (Stream requestStream = connection.GetRequestStream())
+ {
+ requestStream.Write(data, 0, data.Length);
+
+ // Resolve HTTP hang that can happens after successive calls by making sure
+ // that we release the response and response stream. To support this, we copy
+ // the response to a memory stream.
+ using (var response = connection.GetResponse())
+ {
+ using (var responseStream = response.GetResponseStream())
+ {
+ // Copy the response to a memory stream so that we can
+ // cleanly close the response and response stream.
+ inputStream = new MemoryStream();
+ byte[] buffer = new byte[8096];
+ int bytesRead;
+ while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ inputStream.Write (buffer, 0, bytesRead);
+ }
+ inputStream.Seek(0, 0);
+ }
+ }
+ }
+ }
+ catch (IOException iox)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
+ }
+ catch (WebException wx)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, "Couldn't connect to server: " + wx);
+ }
+ }
#endif
- private HttpWebRequest CreateRequest()
- {
- HttpWebRequest connection = (HttpWebRequest)WebRequest.Create(uri);
+ private HttpWebRequest CreateRequest()
+ {
+ HttpWebRequest connection = (HttpWebRequest)WebRequest.Create(uri);
#if !SILVERLIGHT
- // Adding certificates through code is not supported with WP7 Silverlight
- // see "Windows Phone 7 and Certificates_FINAL_121610.pdf"
- connection.ClientCertificates.AddRange(certificates);
-
- if (connectTimeout > 0)
- {
- connection.Timeout = connectTimeout;
- }
- if (readTimeout > 0)
- {
- connection.ReadWriteTimeout = readTimeout;
- }
+ // Adding certificates through code is not supported with WP7 Silverlight
+ // see "Windows Phone 7 and Certificates_FINAL_121610.pdf"
+ connection.ClientCertificates.AddRange(certificates);
+
+ if (connectTimeout > 0)
+ {
+ connection.Timeout = connectTimeout;
+ }
+ if (readTimeout > 0)
+ {
+ connection.ReadWriteTimeout = readTimeout;
+ }
#endif
- // Make the request
- connection.ContentType = "application/x-thrift";
- connection.Accept = "application/x-thrift";
- connection.UserAgent = "C#/THttpClient";
- connection.Method = "POST";
+ // Make the request
+ connection.ContentType = "application/x-thrift";
+ connection.Accept = "application/x-thrift";
+ connection.UserAgent = "C#/THttpClient";
+ connection.Method = "POST";
#if !SILVERLIGHT
- connection.ProtocolVersion = HttpVersion.Version10;
+ connection.ProtocolVersion = HttpVersion.Version10;
#endif
//add custom headers here
- foreach (KeyValuePair<string, string> item in customHeaders)
- {
+ foreach (KeyValuePair<string, string> item in customHeaders)
+ {
#if !SILVERLIGHT
- connection.Headers.Add(item.Key, item.Value);
+ connection.Headers.Add(item.Key, item.Value);
#else
connection.Headers[item.Key] = item.Value;
#endif
- }
+ }
#if !SILVERLIGHT
connection.Proxy = proxy;
#endif
return connection;
- }
+ }
public override IAsyncResult BeginFlush(AsyncCallback callback, object state)
{
@@ -388,12 +388,12 @@ namespace Thrift.Transport
}
internal void UpdateStatusToComplete()
{
- _isCompleted = true; //1. set _iscompleted to true
+ _isCompleted = true; //1. set _iscompleted to true
lock (_locker)
{
if (_evt != null)
{
- _evt.Set(); //2. set the event, when it exists
+ _evt.Set(); //2. set the event, when it exists
}
}
}
@@ -408,23 +408,23 @@ namespace Thrift.Transport
}
#region " IDisposable Support "
- private bool _IsDisposed;
-
- // IDisposable
- protected override void Dispose(bool disposing)
- {
- if (!_IsDisposed)
- {
- if (disposing)
- {
- if (inputStream != null)
- inputStream.Dispose();
- if (outputStream != null)
- outputStream.Dispose();
- }
- }
- _IsDisposed = true;
- }
+ private bool _IsDisposed;
+
+ // IDisposable
+ protected override void Dispose(bool disposing)
+ {
+ if (!_IsDisposed)
+ {
+ if (disposing)
+ {
+ if (inputStream != null)
+ inputStream.Dispose();
+ if (outputStream != null)
+ outputStream.Dispose();
+ }
+ }
+ _IsDisposed = true;
+ }
#endregion
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/THttpHandler.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/THttpHandler.cs b/lib/csharp/src/Transport/THttpHandler.cs
index 884f1ad..4115ef9 100644
--- a/lib/csharp/src/Transport/THttpHandler.cs
+++ b/lib/csharp/src/Transport/THttpHandler.cs
@@ -1,11 +1,23 @@
-//
-// THttpHandler.cs
-//
-// Authors:
-// Fredrik Hedberg <fh...@availo.com>
-//
-// Distributed under the Apache Public License
-//
+/**
+ * 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.Web;
@@ -31,7 +43,7 @@ namespace Thrift.Transport
{
}
-
+
public THttpHandler(TProcessor processor, TProtocolFactory protocolFactory)
: this(processor, protocolFactory, protocolFactory)
{
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TMemoryBuffer.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TMemoryBuffer.cs b/lib/csharp/src/Transport/TMemoryBuffer.cs
index ca31fee..d8ff9dc 100644
--- a/lib/csharp/src/Transport/TMemoryBuffer.cs
+++ b/lib/csharp/src/Transport/TMemoryBuffer.cs
@@ -23,77 +23,77 @@ using System.Reflection;
using Thrift.Protocol;
namespace Thrift.Transport {
- public class TMemoryBuffer : TTransport {
-
- private readonly MemoryStream byteStream;
-
- public TMemoryBuffer() {
- byteStream = new MemoryStream();
- }
-
- public TMemoryBuffer(byte[] buf) {
- byteStream = new MemoryStream(buf);
- }
-
- public override void Open() {
- /** do nothing **/
- }
-
- public override void Close() {
- /** do nothing **/
- }
-
- public override int Read(byte[] buf, int off, int len) {
- return byteStream.Read(buf, off, len);
- }
-
- public override void Write(byte[] buf, int off, int len) {
- byteStream.Write(buf, off, len);
- }
-
- public byte[] GetBuffer() {
- return byteStream.ToArray();
- }
-
-
- public override bool IsOpen {
- get { return true; }
- }
-
- public static byte[] Serialize(TAbstractBase s) {
- var t = new TMemoryBuffer();
- var p = new TBinaryProtocol(t);
-
- s.Write(p);
-
- return t.GetBuffer();
- }
-
- public static T DeSerialize<T>(byte[] buf) where T : TAbstractBase {
- var trans = new TMemoryBuffer(buf);
- var p = new TBinaryProtocol(trans);
- if (typeof (TBase).IsAssignableFrom(typeof (T))) {
- var method = typeof (T).GetMethod("Read", BindingFlags.Instance | BindingFlags.Public);
- var t = Activator.CreateInstance<T>();
- method.Invoke(t, new object[] {p});
- return t;
- } else {
- var method = typeof (T).GetMethod("Read", BindingFlags.Static | BindingFlags.Public);
- return (T) method.Invoke(null, new object[] {p});
- }
- }
-
- private bool _IsDisposed;
-
- // IDisposable
- protected override void Dispose(bool disposing) {
- if (!_IsDisposed) {
- if (disposing) {
- if (byteStream != null)
- byteStream.Dispose();
- }
- }
- _IsDisposed = true;
- }
- }
+ public class TMemoryBuffer : TTransport {
+
+ private readonly MemoryStream byteStream;
+
+ public TMemoryBuffer() {
+ byteStream = new MemoryStream();
+ }
+
+ public TMemoryBuffer(byte[] buf) {
+ byteStream = new MemoryStream(buf);
+ }
+
+ public override void Open() {
+ /** do nothing **/
+ }
+
+ public override void Close() {
+ /** do nothing **/
+ }
+
+ public override int Read(byte[] buf, int off, int len) {
+ return byteStream.Read(buf, off, len);
+ }
+
+ public override void Write(byte[] buf, int off, int len) {
+ byteStream.Write(buf, off, len);
+ }
+
+ public byte[] GetBuffer() {
+ return byteStream.ToArray();
+ }
+
+
+ public override bool IsOpen {
+ get { return true; }
+ }
+
+ public static byte[] Serialize(TAbstractBase s) {
+ var t = new TMemoryBuffer();
+ var p = new TBinaryProtocol(t);
+
+ s.Write(p);
+
+ return t.GetBuffer();
+ }
+
+ public static T DeSerialize<T>(byte[] buf) where T : TAbstractBase {
+ var trans = new TMemoryBuffer(buf);
+ var p = new TBinaryProtocol(trans);
+ if (typeof (TBase).IsAssignableFrom(typeof (T))) {
+ var method = typeof (T).GetMethod("Read", BindingFlags.Instance | BindingFlags.Public);
+ var t = Activator.CreateInstance<T>();
+ method.Invoke(t, new object[] {p});
+ return t;
+ } else {
+ var method = typeof (T).GetMethod("Read", BindingFlags.Static | BindingFlags.Public);
+ return (T) method.Invoke(null, new object[] {p});
+ }
+ }
+
+ private bool _IsDisposed;
+
+ // IDisposable
+ protected override void Dispose(bool disposing) {
+ if (!_IsDisposed) {
+ if (disposing) {
+ if (byteStream != null)
+ byteStream.Dispose();
+ }
+ }
+ _IsDisposed = true;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TNamedPipeClientTransport.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TNamedPipeClientTransport.cs b/lib/csharp/src/Transport/TNamedPipeClientTransport.cs
index 7dafdd6..9faa6e7 100644
--- a/lib/csharp/src/Transport/TNamedPipeClientTransport.cs
+++ b/lib/csharp/src/Transport/TNamedPipeClientTransport.cs
@@ -25,71 +25,71 @@ using System.IO.Pipes;
namespace Thrift.Transport
{
- public class TNamedPipeClientTransport : TTransport
- {
- private NamedPipeClientStream client;
- private string ServerName;
- private string PipeName;
+ public class TNamedPipeClientTransport : TTransport
+ {
+ private NamedPipeClientStream client;
+ private string ServerName;
+ private string PipeName;
- public TNamedPipeClientTransport(string pipe)
- {
- ServerName = ".";
- PipeName = pipe;
- }
+ public TNamedPipeClientTransport(string pipe)
+ {
+ ServerName = ".";
+ PipeName = pipe;
+ }
- public TNamedPipeClientTransport(string server, string pipe)
- {
- ServerName = (server != "") ? server : ".";
- PipeName = pipe;
- }
+ public TNamedPipeClientTransport(string server, string pipe)
+ {
+ ServerName = (server != "") ? server : ".";
+ PipeName = pipe;
+ }
- public override bool IsOpen
- {
- get { return client != null && client.IsConnected; }
- }
+ public override bool IsOpen
+ {
+ get { return client != null && client.IsConnected; }
+ }
- public override void Open()
- {
- if (IsOpen)
- {
- throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen);
- }
- client = new NamedPipeClientStream(ServerName, PipeName, PipeDirection.InOut, PipeOptions.None);
- client.Connect();
- }
+ public override void Open()
+ {
+ if (IsOpen)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen);
+ }
+ client = new NamedPipeClientStream(ServerName, PipeName, PipeDirection.InOut, PipeOptions.None);
+ client.Connect();
+ }
- public override void Close()
- {
- if (client != null)
- {
- client.Close();
- client = null;
- }
- }
+ public override void Close()
+ {
+ if (client != null)
+ {
+ client.Close();
+ client = null;
+ }
+ }
- public override int Read(byte[] buf, int off, int len)
- {
- if (client == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen);
- }
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (client == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen);
+ }
- return client.Read(buf, off, len);
- }
+ return client.Read(buf, off, len);
+ }
- public override void Write(byte[] buf, int off, int len)
- {
- if (client == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen);
- }
+ public override void Write(byte[] buf, int off, int len)
+ {
+ if (client == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen);
+ }
- client.Write(buf, off, len);
- }
+ client.Write(buf, off, len);
+ }
- protected override void Dispose(bool disposing)
- {
- client.Dispose();
- }
- }
+ protected override void Dispose(bool disposing)
+ {
+ client.Dispose();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
index 815af19..b3f34eb 100644
--- a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
+++ b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
@@ -27,110 +27,110 @@ using System.IO.Pipes;
namespace Thrift.Transport
{
- public class TNamedPipeServerTransport : TServerTransport
- {
- /// <summary>
- /// This is the address of the Pipe on the localhost.
- /// </summary>
- private readonly string pipeAddress;
- NamedPipeServerStream stream = null;
+ public class TNamedPipeServerTransport : TServerTransport
+ {
+ /// <summary>
+ /// This is the address of the Pipe on the localhost.
+ /// </summary>
+ private readonly string pipeAddress;
+ NamedPipeServerStream stream = null;
- public TNamedPipeServerTransport(string pipeAddress)
- {
- this.pipeAddress = pipeAddress;
- }
+ public TNamedPipeServerTransport(string pipeAddress)
+ {
+ this.pipeAddress = pipeAddress;
+ }
- public override void Listen()
- {
- // nothing to do here
- }
+ public override void Listen()
+ {
+ // nothing to do here
+ }
- public override void Close()
- {
- if (stream != null)
- {
- try
- {
- stream.Close();
- stream.Dispose();
- }
- finally
- {
- stream = null;
- }
- }
- }
+ public override void Close()
+ {
+ if (stream != null)
+ {
+ try
+ {
+ stream.Close();
+ stream.Dispose();
+ }
+ finally
+ {
+ stream = null;
+ }
+ }
+ }
- private void EnsurePipeInstance()
- {
- if( stream == null)
- stream = new NamedPipeServerStream(
- pipeAddress, PipeDirection.InOut, 254,
- PipeTransmissionMode.Byte,
- PipeOptions.None, 4096, 4096 /*TODO: security*/);
- }
+ private void EnsurePipeInstance()
+ {
+ if( stream == null)
+ stream = new NamedPipeServerStream(
+ pipeAddress, PipeDirection.InOut, 254,
+ PipeTransmissionMode.Byte,
+ PipeOptions.None, 4096, 4096 /*TODO: security*/);
+ }
- protected override TTransport AcceptImpl()
- {
- try
- {
- EnsurePipeInstance();
- stream.WaitForConnection();
- var trans = new ServerTransport(stream);
- stream = null; // pass ownership to ServerTransport
- return trans;
- }
- catch (Exception e)
- {
- Close();
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message);
- }
- }
+ protected override TTransport AcceptImpl()
+ {
+ try
+ {
+ EnsurePipeInstance();
+ stream.WaitForConnection();
+ var trans = new ServerTransport(stream);
+ stream = null; // pass ownership to ServerTransport
+ return trans;
+ }
+ catch (Exception e)
+ {
+ Close();
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message);
+ }
+ }
- private class ServerTransport : TTransport
- {
- private NamedPipeServerStream server;
- public ServerTransport(NamedPipeServerStream server)
- {
- this.server = server;
- }
+ private class ServerTransport : TTransport
+ {
+ private NamedPipeServerStream server;
+ public ServerTransport(NamedPipeServerStream server)
+ {
+ this.server = server;
+ }
- public override bool IsOpen
- {
- get { return server != null && server.IsConnected; }
- }
+ public override bool IsOpen
+ {
+ get { return server != null && server.IsConnected; }
+ }
- public override void Open()
- {
- }
+ public override void Open()
+ {
+ }
- public override void Close()
- {
- if (server != null) server.Close();
- }
+ public override void Close()
+ {
+ if (server != null) server.Close();
+ }
- public override int Read(byte[] buf, int off, int len)
- {
- if (server == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen);
- }
- return server.Read(buf, off, len);
- }
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (server == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen);
+ }
+ return server.Read(buf, off, len);
+ }
- public override void Write(byte[] buf, int off, int len)
- {
- if (server == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen);
- }
- server.Write(buf, off, len);
- }
+ public override void Write(byte[] buf, int off, int len)
+ {
+ if (server == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen);
+ }
+ server.Write(buf, off, len);
+ }
- protected override void Dispose(bool disposing)
- {
- server.Dispose();
- }
- }
- }
+ protected override void Dispose(bool disposing)
+ {
+ server.Dispose();
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TServerSocket.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TServerSocket.cs b/lib/csharp/src/Transport/TServerSocket.cs
index eefa4f9..82a367c 100644
--- a/lib/csharp/src/Transport/TServerSocket.cs
+++ b/lib/csharp/src/Transport/TServerSocket.cs
@@ -27,94 +27,94 @@ using System.Net.Sockets;
namespace Thrift.Transport
{
- public class TServerSocket : TServerTransport
- {
- /**
- * Underlying server with socket
- */
- private TcpListener server = null;
+ public class TServerSocket : TServerTransport
+ {
+ /**
+ * Underlying server with socket
+ */
+ private TcpListener server = null;
- /**
- * Port to listen on
- */
- private int port = 0;
+ /**
+ * Port to listen on
+ */
+ private int port = 0;
- /**
- * Timeout for client sockets from accept
- */
- private int clientTimeout = 0;
+ /**
+ * Timeout for client sockets from accept
+ */
+ private int clientTimeout = 0;
- /**
- * Whether or not to wrap new TSocket connections in buffers
- */
- private bool useBufferedSockets = false;
+ /**
+ * Whether or not to wrap new TSocket connections in buffers
+ */
+ private bool useBufferedSockets = false;
- /**
- * Creates a server socket from underlying socket object
- */
- public TServerSocket(TcpListener listener)
- :this(listener, 0)
- {
- }
+ /**
+ * Creates a server socket from underlying socket object
+ */
+ public TServerSocket(TcpListener listener)
+ :this(listener, 0)
+ {
+ }
- /**
- * Creates a server socket from underlying socket object
- */
- public TServerSocket(TcpListener listener, int clientTimeout)
- {
- this.server = listener;
- this.clientTimeout = clientTimeout;
- }
+ /**
+ * Creates a server socket from underlying socket object
+ */
+ public TServerSocket(TcpListener listener, int clientTimeout)
+ {
+ this.server = listener;
+ this.clientTimeout = clientTimeout;
+ }
- /**
- * Creates just a port listening server socket
- */
- public TServerSocket(int port)
- : this(port, 0)
- {
- }
+ /**
+ * Creates just a port listening server socket
+ */
+ public TServerSocket(int port)
+ : this(port, 0)
+ {
+ }
- /**
- * Creates just a port listening server socket
- */
- public TServerSocket(int port, int clientTimeout)
- :this(port, clientTimeout, false)
- {
- }
+ /**
+ * Creates just a port listening server socket
+ */
+ public TServerSocket(int port, int clientTimeout)
+ :this(port, clientTimeout, false)
+ {
+ }
- public TServerSocket(int port, int clientTimeout, bool useBufferedSockets)
- {
- this.port = port;
- this.clientTimeout = clientTimeout;
- this.useBufferedSockets = useBufferedSockets;
- try
- {
- // Make server socket
- server = new TcpListener(System.Net.IPAddress.Any, this.port);
- server.Server.NoDelay = true;
- }
- catch (Exception)
- {
- server = null;
- throw new TTransportException("Could not create ServerSocket on port " + port + ".");
- }
- }
+ public TServerSocket(int port, int clientTimeout, bool useBufferedSockets)
+ {
+ this.port = port;
+ this.clientTimeout = clientTimeout;
+ this.useBufferedSockets = useBufferedSockets;
+ try
+ {
+ // Make server socket
+ server = new TcpListener(System.Net.IPAddress.Any, this.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 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);
+ }
+ }
+ }
protected override TTransport AcceptImpl()
{
@@ -142,7 +142,7 @@ namespace Thrift.Transport
}
catch (System.Exception)
{
- // If a TSocket was successfully created, then let
+ // If a TSocket was successfully created, then let
// it do proper cleanup of the TcpClient object.
if (result2 != null)
result2.Dispose();
@@ -158,19 +158,19 @@ namespace Thrift.Transport
}
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;
- }
- }
- }
+ {
+ if (server != null)
+ {
+ try
+ {
+ server.Stop();
+ }
+ catch (Exception ex)
+ {
+ throw new TTransportException("WARNING: Could not close server socket: " + ex);
+ }
+ server = null;
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TServerTransport.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TServerTransport.cs b/lib/csharp/src/Transport/TServerTransport.cs
index c99d07f..05d7d0f 100644
--- a/lib/csharp/src/Transport/TServerTransport.cs
+++ b/lib/csharp/src/Transport/TServerTransport.cs
@@ -25,19 +25,19 @@ using System;
namespace Thrift.Transport
{
- public abstract class TServerTransport
- {
- public abstract void Listen();
- public abstract void Close();
- protected abstract TTransport AcceptImpl();
+ public abstract class TServerTransport
+ {
+ public abstract void Listen();
+ public abstract void Close();
+ protected abstract TTransport AcceptImpl();
- public TTransport Accept()
- {
- TTransport transport = AcceptImpl();
- if (transport == null) {
- throw new TTransportException("accept() may not return NULL");
- }
- return transport;
- }
- }
+ public TTransport Accept()
+ {
+ TTransport transport = AcceptImpl();
+ if (transport == null) {
+ throw new TTransportException("accept() may not return NULL");
+ }
+ return transport;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TSocket.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TSocket.cs b/lib/csharp/src/Transport/TSocket.cs
index 35fbe97..cf1a440 100644
--- a/lib/csharp/src/Transport/TSocket.cs
+++ b/lib/csharp/src/Transport/TSocket.cs
@@ -26,118 +26,118 @@ using System.Net.Sockets;
namespace Thrift.Transport
{
- public class TSocket : TStreamTransport
- {
- private TcpClient client = null;
- private string host = null;
- private int port = 0;
- private int timeout = 0;
-
- public TSocket(TcpClient client)
- {
- this.client = client;
-
- if (IsOpen)
- {
- inputStream = client.GetStream();
- outputStream = client.GetStream();
- }
- }
-
- public TSocket(string host, int port)
- : this(host, port, 0)
- {
- }
-
- public TSocket(string host, int port, int timeout)
- {
- this.host = host;
- this.port = port;
- this.timeout = timeout;
-
- InitSocket();
- }
-
- private void InitSocket()
- {
- client = new TcpClient();
- client.ReceiveTimeout = client.SendTimeout = timeout;
- client.Client.NoDelay = true;
- }
-
- public int Timeout
- {
- set
- {
- client.ReceiveTimeout = client.SendTimeout = timeout = value;
- }
- }
-
- public TcpClient TcpClient
- {
- get
- {
- return client;
- }
- }
-
- public string Host
- {
- get
- {
- return host;
- }
- }
-
- public int Port
- {
- get
- {
- return port;
- }
- }
-
- public override bool IsOpen
- {
- get
- {
- if (client == null)
- {
- return false;
- }
-
- return client.Connected;
- }
- }
-
- public override void Open()
- {
- if (IsOpen)
- {
- throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
- }
-
- if (String.IsNullOrEmpty(host))
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
- }
-
- if (port <= 0)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port");
- }
-
- if (client == null)
- {
- InitSocket();
- }
-
- if( timeout == 0) // no timeout -> infinite
- {
- client.Connect(host, port);
- }
- else // we have a timeout -> use it
- {
+ public class TSocket : TStreamTransport
+ {
+ private TcpClient client = null;
+ private string host = null;
+ private int port = 0;
+ private int timeout = 0;
+
+ public TSocket(TcpClient client)
+ {
+ this.client = client;
+
+ if (IsOpen)
+ {
+ inputStream = client.GetStream();
+ outputStream = client.GetStream();
+ }
+ }
+
+ public TSocket(string host, int port)
+ : this(host, port, 0)
+ {
+ }
+
+ public TSocket(string host, int port, int timeout)
+ {
+ this.host = host;
+ this.port = port;
+ this.timeout = timeout;
+
+ InitSocket();
+ }
+
+ private void InitSocket()
+ {
+ client = new TcpClient();
+ client.ReceiveTimeout = client.SendTimeout = timeout;
+ client.Client.NoDelay = true;
+ }
+
+ public int Timeout
+ {
+ set
+ {
+ client.ReceiveTimeout = client.SendTimeout = timeout = value;
+ }
+ }
+
+ public TcpClient TcpClient
+ {
+ get
+ {
+ return client;
+ }
+ }
+
+ public string Host
+ {
+ get
+ {
+ return host;
+ }
+ }
+
+ public int Port
+ {
+ get
+ {
+ return port;
+ }
+ }
+
+ public override bool IsOpen
+ {
+ get
+ {
+ if (client == null)
+ {
+ return false;
+ }
+
+ return client.Connected;
+ }
+ }
+
+ public override void Open()
+ {
+ if (IsOpen)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected");
+ }
+
+ if (String.IsNullOrEmpty(host))
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host");
+ }
+
+ if (port <= 0)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port");
+ }
+
+ if (client == null)
+ {
+ InitSocket();
+ }
+
+ if( timeout == 0) // no timeout -> infinite
+ {
+ client.Connect(host, port);
+ }
+ else // we have a timeout -> use it
+ {
ConnectHelper hlp = new ConnectHelper(client);
IAsyncResult asyncres = client.BeginConnect(host, port, new AsyncCallback(ConnectCallback), hlp);
bool bConnected = asyncres.AsyncWaitHandle.WaitOne(timeout) && client.Connected;
@@ -158,11 +158,11 @@ namespace Thrift.Transport
}
throw new TTransportException(TTransportException.ExceptionType.TimedOut, "Connect timed out");
}
- }
+ }
- inputStream = client.GetStream();
- outputStream = client.GetStream();
- }
+ inputStream = client.GetStream();
+ outputStream = client.GetStream();
+ }
static void ConnectCallback(IAsyncResult asyncres)
@@ -171,7 +171,7 @@ namespace Thrift.Transport
lock (hlp.Mutex)
{
hlp.CallbackDone = true;
-
+
try
{
if( hlp.Client.Client != null)
@@ -182,16 +182,16 @@ namespace Thrift.Transport
// catch that away
}
- if (hlp.DoCleanup)
+ if (hlp.DoCleanup)
{
- try {
- asyncres.AsyncWaitHandle.Close();
- } catch (Exception) {}
-
- try {
- if (hlp.Client is IDisposable)
- ((IDisposable)hlp.Client).Dispose();
- } catch (Exception) {}
+ try {
+ asyncres.AsyncWaitHandle.Close();
+ } catch (Exception) {}
+
+ try {
+ if (hlp.Client is IDisposable)
+ ((IDisposable)hlp.Client).Dispose();
+ } catch (Exception) {}
hlp.Client = null;
}
}
@@ -209,15 +209,15 @@ namespace Thrift.Transport
}
}
- public override void Close()
- {
- base.Close();
- if (client != null)
- {
- client.Close();
- client = null;
- }
- }
+ public override void Close()
+ {
+ base.Close();
+ if (client != null)
+ {
+ client.Close();
+ client = null;
+ }
+ }
#region " IDisposable Support "
private bool _IsDisposed;
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TStreamTransport.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TStreamTransport.cs b/lib/csharp/src/Transport/TStreamTransport.cs
index eb1d2cc..468743c 100644
--- a/lib/csharp/src/Transport/TStreamTransport.cs
+++ b/lib/csharp/src/Transport/TStreamTransport.cs
@@ -26,83 +26,83 @@ using System.IO;
namespace Thrift.Transport
{
- public class TStreamTransport : TTransport
- {
- protected Stream inputStream;
- protected Stream outputStream;
-
- protected TStreamTransport()
- {
- }
-
- public TStreamTransport(Stream inputStream, Stream outputStream)
- {
- this.inputStream = inputStream;
- this.outputStream = outputStream;
- }
-
- public Stream OutputStream
- {
- get { return outputStream; }
- }
-
- public Stream InputStream
- {
- get { return inputStream; }
- }
-
- public override bool IsOpen
- {
- get { return true; }
- }
-
- public override void Open()
- {
- }
-
- public override void Close()
- {
- if (inputStream != null)
- {
- inputStream.Close();
- inputStream = null;
- }
- if (outputStream != null)
- {
- outputStream.Close();
- outputStream = null;
- }
- }
-
- public override int Read(byte[] buf, int off, int len)
- {
- if (inputStream == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot read from null inputstream");
- }
-
- return inputStream.Read(buf, off, len);
- }
-
- public override void Write(byte[] buf, int off, int len)
- {
- if (outputStream == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot write to null outputstream");
- }
-
- outputStream.Write(buf, off, len);
- }
-
- public override void Flush()
- {
- if (outputStream == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot flush null outputstream");
- }
-
- outputStream.Flush();
- }
+ public class TStreamTransport : TTransport
+ {
+ protected Stream inputStream;
+ protected Stream outputStream;
+
+ protected TStreamTransport()
+ {
+ }
+
+ public TStreamTransport(Stream inputStream, Stream outputStream)
+ {
+ this.inputStream = inputStream;
+ this.outputStream = outputStream;
+ }
+
+ public Stream OutputStream
+ {
+ get { return outputStream; }
+ }
+
+ public Stream InputStream
+ {
+ get { return inputStream; }
+ }
+
+ public override bool IsOpen
+ {
+ get { return true; }
+ }
+
+ public override void Open()
+ {
+ }
+
+ public override void Close()
+ {
+ if (inputStream != null)
+ {
+ inputStream.Close();
+ inputStream = null;
+ }
+ if (outputStream != null)
+ {
+ outputStream.Close();
+ outputStream = null;
+ }
+ }
+
+ public override int Read(byte[] buf, int off, int len)
+ {
+ if (inputStream == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot read from null inputstream");
+ }
+
+ return inputStream.Read(buf, off, len);
+ }
+
+ public override void Write(byte[] buf, int off, int len)
+ {
+ if (outputStream == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot write to null outputstream");
+ }
+
+ outputStream.Write(buf, off, len);
+ }
+
+ public override void Flush()
+ {
+ if (outputStream == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot flush null outputstream");
+ }
+
+ outputStream.Flush();
+ }
#region " IDisposable Support "
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TTLSServerSocket.cs
----------------------------------------------------------------------
diff --git a/lib/csharp/src/Transport/TTLSServerSocket.cs b/lib/csharp/src/Transport/TTLSServerSocket.cs
index 948b1d7..9753d47 100644
--- a/lib/csharp/src/Transport/TTLSServerSocket.cs
+++ b/lib/csharp/src/Transport/TTLSServerSocket.cs
@@ -23,164 +23,164 @@ using System.Security.Cryptography.X509Certificates;
namespace Thrift.Transport
{
- /// <summary>
- /// SSL Server Socket Wrapper Class
- /// </summary>
- public class TTLSServerSocket : TServerTransport
- {
- /// <summary>
- /// Underlying tcp server
- /// </summary>
- private TcpListener server = null;
-
- /// <summary>
- /// The port where the socket listen
- /// </summary>
- private int port = 0;
-
- /// <summary>
- /// Timeout for the created server socket
- /// </summary>
- private int clientTimeout = 0;
-
- /// <summary>
- /// Whether or not to wrap new TSocket connections in buffers
- /// </summary>
- private bool useBufferedSockets = false;
-
- /// <summary>
- /// The servercertificate with the private- and public-key
- /// </summary>
- private X509Certificate serverCertificate;
-
-
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
- /// </summary>
- /// <param name="port">The port where the server runs.</param>
- /// <param name="certificate">The certificate object.</param>
- public TTLSServerSocket(int port, X509Certificate2 certificate)
- : this(port, 0, certificate)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
- /// </summary>
- /// <param name="port">The port where the server runs.</param>
- /// <param name="clientTimeout">Send/receive timeout.</param>
- /// <param name="certificate">The certificate object.</param>
- public TTLSServerSocket(int port, int clientTimeout, X509Certificate2 certificate)
- : this(port, clientTimeout, false, certificate)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
- /// </summary>
- /// <param name="port">The port where the server runs.</param>
- /// <param name="clientTimeout">Send/receive timeout.</param>
- /// <param name="useBufferedSockets">If set to <c>true</c> [use buffered sockets].</param>
- /// <param name="certificate">The certificate object.</param>
- public TTLSServerSocket(int port, int clientTimeout, bool useBufferedSockets, X509Certificate2 certificate)
- {
- if (!certificate.HasPrivateKey)
- {
- throw new TTransportException(TTransportException.ExceptionType.Unknown, "Your server-certificate needs to have a private key");
- }
-
- this.port = port;
- this.serverCertificate = certificate;
- this.useBufferedSockets = useBufferedSockets;
- try
- {
- // Create server socket
- server = new TcpListener(System.Net.IPAddress.Any, this.port);
- server.Server.NoDelay = true;
- }
- catch (Exception)
- {
- server = null;
- throw new TTransportException("Could not create ServerSocket on port " + port + ".");
- }
- }
-
- /// <summary>
- /// Starts the server.
- /// </summary>
- public override void Listen()
- {
- // Make sure accept is not blocking
- if (this.server != null)
- {
- try
- {
- this.server.Start();
- }
- catch (SocketException sx)
- {
- throw new TTransportException("Could not accept on listening socket: " + sx.Message);
- }
- }
- }
-
- /// <summary>
- /// Callback for Accept Implementation
- /// </summary>
- /// <returns>
- /// TTransport-object.
- /// </returns>
- protected override TTransport AcceptImpl()
- {
- if (this.server == null)
- {
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket.");
- }
-
- try
- {
- TcpClient client = this.server.AcceptTcpClient();
- client.SendTimeout = client.ReceiveTimeout = this.clientTimeout;
-
- //wrap the client in an SSL Socket passing in the SSL cert
- TTLSSocket socket = new TTLSSocket(client, this.serverCertificate, true);
-
- socket.setupTLS();
-
- if (useBufferedSockets)
- {
- TBufferedTransport trans = new TBufferedTransport(socket);
- return trans;
- }
- else
- {
- return socket;
- }
-
- }
- catch (Exception ex)
- {
- throw new TTransportException(ex.ToString());
- }
- }
-
- /// <summary>
- /// Stops the Server
- /// </summary>
- public override void Close()
- {
- if (this.server != null)
- {
- try
- {
- this.server.Stop();
- }
- catch (Exception ex)
- {
- throw new TTransportException("WARNING: Could not close server socket: " + ex);
- }
- this.server = null;
- }
- }
- }
+ /// <summary>
+ /// SSL Server Socket Wrapper Class
+ /// </summary>
+ public class TTLSServerSocket : TServerTransport
+ {
+ /// <summary>
+ /// Underlying tcp server
+ /// </summary>
+ private TcpListener server = null;
+
+ /// <summary>
+ /// The port where the socket listen
+ /// </summary>
+ private int port = 0;
+
+ /// <summary>
+ /// Timeout for the created server socket
+ /// </summary>
+ private int clientTimeout = 0;
+
+ /// <summary>
+ /// Whether or not to wrap new TSocket connections in buffers
+ /// </summary>
+ private bool useBufferedSockets = false;
+
+ /// <summary>
+ /// The servercertificate with the private- and public-key
+ /// </summary>
+ private X509Certificate serverCertificate;
+
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
+ /// </summary>
+ /// <param name="port">The port where the server runs.</param>
+ /// <param name="certificate">The certificate object.</param>
+ public TTLSServerSocket(int port, X509Certificate2 certificate)
+ : this(port, 0, certificate)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
+ /// </summary>
+ /// <param name="port">The port where the server runs.</param>
+ /// <param name="clientTimeout">Send/receive timeout.</param>
+ /// <param name="certificate">The certificate object.</param>
+ public TTLSServerSocket(int port, int clientTimeout, X509Certificate2 certificate)
+ : this(port, clientTimeout, false, certificate)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TTLSServerSocket" /> class.
+ /// </summary>
+ /// <param name="port">The port where the server runs.</param>
+ /// <param name="clientTimeout">Send/receive timeout.</param>
+ /// <param name="useBufferedSockets">If set to <c>true</c> [use buffered sockets].</param>
+ /// <param name="certificate">The certificate object.</param>
+ public TTLSServerSocket(int port, int clientTimeout, bool useBufferedSockets, X509Certificate2 certificate)
+ {
+ if (!certificate.HasPrivateKey)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, "Your server-certificate needs to have a private key");
+ }
+
+ this.port = port;
+ this.serverCertificate = certificate;
+ this.useBufferedSockets = useBufferedSockets;
+ try
+ {
+ // Create server socket
+ server = new TcpListener(System.Net.IPAddress.Any, this.port);
+ server.Server.NoDelay = true;
+ }
+ catch (Exception)
+ {
+ server = null;
+ throw new TTransportException("Could not create ServerSocket on port " + port + ".");
+ }
+ }
+
+ /// <summary>
+ /// Starts the server.
+ /// </summary>
+ public override void Listen()
+ {
+ // Make sure accept is not blocking
+ if (this.server != null)
+ {
+ try
+ {
+ this.server.Start();
+ }
+ catch (SocketException sx)
+ {
+ throw new TTransportException("Could not accept on listening socket: " + sx.Message);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Callback for Accept Implementation
+ /// </summary>
+ /// <returns>
+ /// TTransport-object.
+ /// </returns>
+ protected override TTransport AcceptImpl()
+ {
+ if (this.server == null)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, "No underlying server socket.");
+ }
+
+ try
+ {
+ TcpClient client = this.server.AcceptTcpClient();
+ client.SendTimeout = client.ReceiveTimeout = this.clientTimeout;
+
+ //wrap the client in an SSL Socket passing in the SSL cert
+ TTLSSocket socket = new TTLSSocket(client, this.serverCertificate, true);
+
+ socket.setupTLS();
+
+ if (useBufferedSockets)
+ {
+ TBufferedTransport trans = new TBufferedTransport(socket);
+ return trans;
+ }
+ else
+ {
+ return socket;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ throw new TTransportException(ex.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Stops the Server
+ /// </summary>
+ public override void Close()
+ {
+ if (this.server != null)
+ {
+ try
+ {
+ this.server.Stop();
+ }
+ catch (Exception ex)
+ {
+ throw new TTransportException("WARNING: Could not close server socket: " + ex);
+ }
+ this.server = null;
+ }
+ }
+ }
}