// $Id$ // // 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; namespace Org.Apache.Etch.Bindings.Csharp.Util { /// /// TCP connection options. /// public class TcpOptions { /// /// Constructs TcpOptions from uri and resources. /// /// /// 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; } /// /// The auto flush setting for this connection. If true, each call to send /// must automatically call flush. /// public bool autoFlush; /// /// 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. /// public int bufferSize; /// /// The tcp keep alive setting for this connection. /// public bool keepAlive; /// /// The tcp linger time setting for this connection. Time in seconds, -1 /// means disable. /// public int lingerTime; /// /// The tcp no delay setting for this connection. True disables nagle's /// algorithm and causes all sends to be made asap. /// public bool noDelay; /// /// The reconnect delay for this connection. Time in milliseconds, 0 means /// do not reconnect. /// public int reconnectDelay; /// /// The traffic class for this connection. 0-255, 0 means normal handling. /// Also called type of service or dscp. /// public int trafficClass; /// /// 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". /// public const String AUTO_FLUSH = "TcpTransport.autoFlush"; /// /// 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. /// public const String BUFFER_SIZE = "TcpTransport.bufferSize"; /// /// 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". /// public const String KEEP_ALIVE = "TcpTransport.keepAlive"; /// /// 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. /// public const String LINGER_TIME = "TcpTransport.lingerTime"; /// /// 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". /// public const String NO_DELAY = "TcpTransport.noDelay"; /// /// 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. /// public const String RECONNECT_DELAY = "TcpTransport.reconnectDelay"; /// /// 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. /// public const String TRAFFIC_CLASS = "TcpTransport.trafficClass"; } }