You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2008/12/04 15:49:25 UTC
svn commit: r723340 - in
/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp:
Etch/Util/TcpConnection.cs Etch/Util/TcpOptions.cs
Etch/Util/TcpTransport.cs EtchProj.csproj
Author: sccomer
Date: Thu Dec 4 06:49:24 2008
New Revision: 723340
URL: http://svn.apache.org/viewvc?rev=723340&view=rev
Log:
csharp fix for ETCH-19: Break out common tcp transport options so that they may be shared among various transports.
Added:
incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpOptions.cs (with props)
Modified:
incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpConnection.cs
incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpTransport.cs
incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/EtchProj.csproj
Modified: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpConnection.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpConnection.cs?rev=723340&r1=723339&r2=723340&view=diff
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpConnection.cs (original)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpConnection.cs Thu Dec 4 06:49:24 2008
@@ -36,16 +36,16 @@
{
if (socket == null)
{
- String host = uri.Host;
- if (host == null)
- throw new ArgumentNullException("host == null");
-
- int? port = uri.Port;
- if (port == null)
- throw new ArgumentNullException("port == null");
+ if (uri.Host == null)
+ throw new ArgumentNullException("host");
+ host = uri.Host;
+
+ if (uri.Port == null)
+ throw new ArgumentNullException("port");
+ port = (int)uri.Port;
if (port <= 0 || port >= 65536)
- throw new ArgumentOutOfRangeException("port <= 0 || port >= 65536");
+ throw new ArgumentException("port <= 0 || port >= 65536");
this.socket = null;
this.host = host;
@@ -54,8 +54,8 @@
else
{
this.socket = socket;
- this.host = null;
- this.port = 0;
+ host = null;
+ port = 0;
}
}
Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpOptions.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpOptions.cs?rev=723340&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpOptions.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpOptions.cs Thu Dec 4 06:49:24 2008
@@ -0,0 +1,165 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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;
+
+namespace Etch.Util
+{
+ /// <summary>
+ /// TCP connection options.
+ /// </summary>
+ public class TcpOptions
+ {
+ /// <summary>
+ /// Constructs TcpOptions from uri and resources.
+ /// </summary>
+ /// <param name="uri"></param>
+ /// <param name="resources"></param>
+ public TcpOptions( URL uri, Resources resources )
+ {
+ autoFlush = uri.GetBooleanTerm(AUTO_FLUSH, false);
+ bufferSize = CheckBufferSize(uri.GetIntegerTerm(BUFFER_SIZE, 0));
+ keepAlive = uri.GetBooleanTerm(KEEP_ALIVE, false);
+ lingerTime = CheckLingerTime(uri.GetIntegerTerm(LINGER_TIME, 30));
+ noDelay = uri.GetBooleanTerm(NO_DELAY, true);
+ reconnectDelay = CheckReconnectDelay(uri.GetIntegerTerm(RECONNECT_DELAY, 0));
+ trafficClass = CheckTrafficClass(uri.GetIntegerTerm(TRAFFIC_CLASS, 0));
+ }
+
+ private static int CheckBufferSize(int bufferSize)
+ {
+ if (bufferSize < 0 || bufferSize > 65536)
+ throw new ArgumentException(
+ "bufferSize < 0 || bufferSize > 65536");
+ return bufferSize;
+ }
+
+ private static int CheckLingerTime(int lingerTime)
+ {
+ if (lingerTime < -1 || lingerTime > 240)
+ throw new ArgumentException(
+ "lingerTime < -1 || lingerTime > 240");
+ return lingerTime;
+ }
+
+ private static int CheckReconnectDelay(int reconnectDelay)
+ {
+ if (reconnectDelay < 0)
+ throw new ArgumentException(
+ "reconnectDelay < 0");
+ return reconnectDelay;
+ }
+
+ private static int CheckTrafficClass(int trafficClass)
+ {
+ if (trafficClass < 0 || trafficClass > 255)
+ throw new ArgumentException(
+ "trafficClass < 0 || trafficClass > 255");
+ return trafficClass;
+ }
+
+ /// <summary>
+ /// The auto flush setting for this connection. If true, each call to send
+ /// must automatically call flush.
+ /// </summary>
+ public bool autoFlush;
+
+ /// <summary>
+ /// The output buffer size to use for this connection. Bytes, 0 means
+ /// unbuffered output. If using buffered output, you'll want to disable
+ /// auto flush and call flush manually only when needed.
+ /// </summary>
+ public int bufferSize;
+
+ /// <summary>
+ /// The tcp keep alive setting for this connection.
+ /// </summary>
+ public bool keepAlive;
+
+ /// <summary>
+ /// The tcp linger time setting for this connection. Time in seconds, -1
+ /// means disable.
+ /// </summary>
+ public int lingerTime;
+
+ /// <summary>
+ /// The tcp no delay setting for this connection. True disables nagle's
+ /// algorithm and causes all sends to be made asap.
+ /// </summary>
+ public bool noDelay;
+
+ /// <summary>
+ /// The reconnect delay for this connection. Time in milliseconds, 0 means
+ /// do not reconnect.
+ /// </summary>
+ public int reconnectDelay;
+
+ /// <summary>
+ /// The traffic class for this connection. 0-255, 0 means normal handling.
+ /// Also called type of service or dscp.
+ /// </summary>
+ public int trafficClass;
+
+ /// <summary>
+ /// Term on the uri which specifies the auto flush flag. The term string is
+ /// "TcpTransport.autoFlush". The value is "true" or "false". The default
+ /// is "false".
+ /// </summary>
+ public const String AUTO_FLUSH = "TcpTransport.autoFlush";
+
+ /// <summary>
+ /// Term on the uri which specifies the buffer size in bytes. The term
+ /// string is "TcpTransport.bufferSize". The value is an integer between
+ /// 0 and 65536. The default is 0.
+ /// </summary>
+ public const String BUFFER_SIZE = "TcpTransport.bufferSize";
+
+ /// <summary>
+ /// Term on the uri which specifies the keep alive flag. The term string is
+ /// "TcpTransport.keepAlive". The value is "true" or "false". The default is
+ /// "false".
+ /// </summary>
+ public const String KEEP_ALIVE = "TcpTransport.keepAlive";
+
+ /// <summary>
+ /// Term on the uri which specifies the linger time in seconds. The term
+ /// string is "TcpTransport.lingerTime". The value is an integer between -1
+ /// and 240. The default is 30. -1 means disable.
+ /// </summary>
+ public const String LINGER_TIME = "TcpTransport.lingerTime";
+
+ /// <summary>
+ /// Term on the uri which specifies the no delay flag. The term string is
+ /// "TcpTransport.noDelay". The value is "true" or "false". The default is
+ /// "true".
+ /// </summary>
+ public const String NO_DELAY = "TcpTransport.noDelay";
+
+ /// <summary>
+ /// Term on the uri which specifies the reconnect delay in milliseconds. The
+ /// term string is "TcpTransport.reconnectDelay". The value is an integer >=
+ /// 0. The default is 0.
+ /// </summary>
+ public const String RECONNECT_DELAY = "TcpTransport.reconnectDelay";
+
+ /// <summary>
+ /// Term on the uri which specifies the traffic class. The term string is
+ /// "TcpTransport.trafficClass". The value is an integer between 0 and 255.
+ /// The default is 0.
+ /// </summary>
+ public const String TRAFFIC_CLASS = "TcpTransport.trafficClass";
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpOptions.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpOptions.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpTransport.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpTransport.cs?rev=723340&r1=723339&r2=723340&view=diff
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpTransport.cs (original)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Etch/Util/TcpTransport.cs Thu Dec 4 06:49:24 2008
@@ -28,158 +28,16 @@
abstract public class TcpTransport : Connection<SessionData>, TransportData
{
/// <summary>
- /// Term on the uri which specifies the auto flush flag. The term string is
- /// "TcpTransport.autoFlush". The value is "true" or "false". The default
- /// is "false".
- /// </summary>
- public const String AUTO_FLUSH = "TcpTransport.autoFlush";
-
- /// <summary>
- /// Term on the uri which specifies the buffer size in bytes. The term
- /// string is "TcpTransport.bufferSize". The value is an integer between
- /// 0 and 65536. The default is 0.
- /// </summary>
- public const String BUFFER_SIZE = "TcpTransport.bufferSize";
-
- /// <summary>
- /// Term on the uri which specifies the keep alive flag. The term string is
- /// "TcpTransport.keepAlive". The value is "true" or "false". The default is
- /// "false".
- /// </summary>
- public const String KEEP_ALIVE = "TcpTransport.keepAlive";
-
- /// <summary>
- /// Term on the uri which specifies the linger time in seconds. The term
- /// string is "TcpTransport.lingerTime". The value is an integer between -1
- /// and 240. The default is 30. -1 means disable.
- /// </summary>
- public const String LINGER_TIME = "TcpTransport.lingerTime";
-
- /// <summary>
- /// Term on the uri which specifies the no delay flag. The term string is
- /// "TcpTransport.noDelay". The value is "true" or "false". The default is
- /// "true".
- /// </summary>
- public const String NO_DELAY = "TcpTransport.noDelay";
-
- /// <summary>
- /// Term on the uri which specifies the reconnect delay in milliseconds. The
- /// term string is "TcpTransport.reconnectDelay". The value is an integer >=
- /// 0. The default is 0.
- /// </summary>
- public const String RECONNECT_DELAY = "TcpTransport.reconnectDelay";
-
- /// <summary>
- /// Term on the uri which specifies the traffic class. The term string is
- /// "TcpTransport.trafficClass". The value is an integer between 0 and 255.
- /// The default is 0.
- /// </summary>
- public const String TRAFFIC_CLASS = "TcpTransport.trafficClass";
-
- /// <summary>
/// Constructs the TcpTransport. Pulls common parameters off the uri.
/// </summary>
/// <param name="uri"></param>
/// <param name="resources"></param>
protected TcpTransport(URL uri, Resources resources)
{
- SetDefaultAutoFlush(uri.GetBooleanTerm(AUTO_FLUSH, false));
- SetDefaultBufferSize((int) uri.GetIntegerTerm(BUFFER_SIZE, 0));
- SetDefaultKeepAlive(uri.GetBooleanTerm(KEEP_ALIVE, false));
- SetDefaultLingerTime((int) uri.GetIntegerTerm(LINGER_TIME, 30));
- SetDefaultNoDelay(uri.GetBooleanTerm(NO_DELAY, true));
- SetDefaultReconnectDelay((int) uri.GetIntegerTerm(RECONNECT_DELAY, 0));
- SetDefaultTrafficClass((int) uri.GetIntegerTerm(TRAFFIC_CLASS, 0));
+ options = new TcpOptions(uri, resources);
}
- private void SetDefaultAutoFlush(bool autoFlush)
- {
- this.autoFlush = autoFlush;
- }
-
- /// <summary>
- /// The auto flush setting for this connection. If true, each call to send
- /// must automatically call flush.
- /// </summary>
- protected bool autoFlush;
-
- private void SetDefaultBufferSize(int bufferSize)
- {
- if (bufferSize < 0 || bufferSize > 65536)
- throw new ArgumentException(
- "bufferSize < 0 || bufferSize > 65536");
- this.bufferSize = bufferSize;
- }
-
- /// <summary>
- /// The output buffer size to use for this connection. Bytes, 0 means
- /// unbuffered output. If using buffered output, you'll want to disable
- /// auto flush and call flush manually only when needed.
- /// </summary>
- protected int bufferSize;
-
- private void SetDefaultKeepAlive(bool keepAlive)
- {
- this.keepAlive = keepAlive;
- }
-
- /// <summary>
- /// The tcp keep alive setting for this connection.
- /// </summary>
- protected bool keepAlive;
-
- private void SetDefaultLingerTime(int lingerTime)
- {
- if (lingerTime < -1 || lingerTime > 240)
- throw new ArgumentException(
- "lingerTime < -1 || lingerTime > 240");
- this.lingerTime = lingerTime;
- }
-
- /// <summary>
- /// The tcp linger time setting for this connection. Time in seconds, -1
- /// means disable.
- /// </summary>
- protected int lingerTime;
-
- private void SetDefaultNoDelay(bool noDelay)
- {
- this.noDelay = noDelay;
- }
-
- /// <summary>
- /// The tcp no delay setting for this connection. True disables nagle's
- /// algorithm and causes all sends to be made asap.
- /// </summary>
- protected bool noDelay;
-
- private void SetDefaultReconnectDelay(int reconnectDelay)
- {
- if (reconnectDelay < 0)
- throw new ArgumentException(
- "reconnectDelay < 0");
- this.reconnectDelay = reconnectDelay;
- }
-
- /// <summary>
- /// The reconnect delay for this connection. Time in milliseconds, 0 means
- /// do not reconnect.
- /// </summary>
- protected int reconnectDelay;
-
- private void SetDefaultTrafficClass(int trafficClass)
- {
- if (trafficClass < 0 || trafficClass > 255)
- throw new ArgumentException(
- "trafficClass < 0 || trafficClass > 255");
- this.trafficClass = trafficClass;
- }
-
- /// <summary>
- /// The traffic class for this connection. 0-255, 0 means normal handling.
- /// Also called type of service or dscp.
- /// </summary>
- protected int trafficClass;
+ private readonly TcpOptions options;
protected override void Stop0()
{
@@ -187,7 +45,7 @@
{
Close(false);
}
- catch (Exception)
+ catch
{
// ignore
}
@@ -232,7 +90,7 @@
s.Close();
}
}
- catch (Exception)
+ catch
{
// ignore.
}
@@ -254,7 +112,7 @@
/// data. Such a problem causes the current connection to be
/// reset.
/// <seealso cref="Flush()"/>
- /// <seealso cref="SetDefaultAutoFlush(bool)"/>
+ /// <seealso cref="TcpOptions.autoFlush"/>
public void Send(byte[] buf)
{
Send(buf, 0, buf.Length);
@@ -273,15 +131,15 @@
{
Stream s = checkStream();
s.Write(buf, off, len);
- if (autoFlush)
+ if (options.autoFlush)
{
s.Flush();
}
}
- catch (Exception e)
+ catch (Exception)
{
Close(true);
- throw e;
+ throw;
}
}
@@ -291,10 +149,10 @@
{
checkStream().Flush();
}
- catch (Exception e)
+ catch (Exception)
{
Close(true);
- throw e;
+ throw;
}
}
@@ -332,9 +190,9 @@
{
Socket s = CheckSocket();
- s.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.KeepAlive, keepAlive);
- s.LingerState = new LingerOption(lingerTime >= 0, lingerTime >= 0 ? lingerTime : 0);
- s.NoDelay = noDelay;
+ s.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.KeepAlive, options.keepAlive);
+ s.LingerState = new LingerOption(options.lingerTime >= 0, options.lingerTime >= 0 ? options.lingerTime : 0);
+ s.NoDelay = options.noDelay;
//s.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TypeOfService, trafficClass);
stream = new NetworkStream(socket);
@@ -377,7 +235,7 @@
return false;
// if a reconnect but no retries allowed, then bail.
- if (reconnect && reconnectDelay == 0)
+ if (reconnect && options.reconnectDelay == 0)
return false;
// ok, we don't have an existing socket, and this is either the first
@@ -394,10 +252,10 @@
if (reconnect || !first)
{
- if (reconnectDelay == 0)
+ if (options.reconnectDelay == 0)
return false;
- System.Threading.Monitor.Wait(this, reconnectDelay);
+ System.Threading.Monitor.Wait(this, options.reconnectDelay);
if (!IsStarted())
break;
@@ -445,7 +303,7 @@
catch (Exception e)
{
if (e.Message == null)
- throw e;
+ throw;
if (e.Message.Contains("connection was aborted"))
return;
if (e.Message.Contains("blocking operation"))
@@ -454,7 +312,7 @@
return;
if (e.Message.Contains("read operation failed"))
return;
- throw e;
+ throw;
}
}
}
Modified: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/EtchProj.csproj
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/EtchProj.csproj?rev=723340&r1=723339&r2=723340&view=diff
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/EtchProj.csproj (original)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/EtchProj.csproj Thu Dec 4 06:49:24 2008
@@ -31,6 +31,8 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Etch\Msg\AsyncMode.cs" />
@@ -148,6 +150,7 @@
<Compile Include="Etch\Util\StrStrHashMapSerializer.cs" />
<Compile Include="Etch\Util\TcpConnection.cs" />
<Compile Include="Etch\Util\TcpListener.cs" />
+ <Compile Include="Etch\Util\TcpOptions.cs" />
<Compile Include="Etch\Util\TcpTransport.cs" />
<Compile Include="Etch\Util\Timer.cs" />
<Compile Include="Etch\Util\TlsConnection.cs" />