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 2009/01/30 23:25:07 UTC

svn commit: r739432 [7/9] - in /incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp: ./ Msg/ Support/ Transport/ Transport/Filter/ Transport/Fmt/ Transport/Fmt/Binary/ Util/

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Packetizer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Packetizer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Packetizer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Packetizer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,294 @@
+// $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;
+using System.Diagnostics;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Packetizes a stream data source. Reads a packet header,
+    /// a 32-bit flag and a 32-bit length, little-endian, verifies
+    /// the flag, and then, using the length from the header,
+    /// reads the packet data and passes it to the packet handler.
+    /// As a packet source, accepts a packet and prepends a packet
+    /// header to it before delivering it to a data source.
+    /// </summary>
+    public class Packetizer : SessionData, TransportPacket
+    {
+
+        /// <summary>
+        /// URI term to specify max packet size
+        /// </summary>
+        public const String MAX_PKT_SIZE_TERM = "Packetizer.maxPktSize";
+
+        private const int SIG = unchecked( (int) 0xdeadbeef );
+
+	    private const int HEADER_SIZE = 8;
+        
+        /// <summary>
+        /// The default maximum packet size that will be accepted, 16376 bytes.
+        /// </summary>
+        public const int DEFAULT_MAX_PKT_SIZE = 16384 - HEADER_SIZE;
+
+        /// <summary>
+        /// Constructs the Packetizer with the specified transport
+        /// and the packet size. 
+        /// </summary>
+        /// <param name="transport">Transport to send data</param>
+        /// <param name="maxPktSize">the maximum packet size that will be accepted.
+        /// Must be >= 0. If maxPktSize == 0, the default will be used.</param>
+        private Packetizer( TransportData transport, int maxPktSize )
+        {
+            if ( maxPktSize < 0 )
+                throw new ArgumentOutOfRangeException( "maxPktSize < 0" );
+
+            this.transport = transport;
+            this.maxPktSize = maxPktSize;
+            
+            transport.SetSession(this);
+        }
+
+   
+
+        public Packetizer( TransportData transport, URL uri, Resources resources )
+            : this( transport, (int)uri.GetIntegerTerm( MAX_PKT_SIZE_TERM, DEFAULT_MAX_PKT_SIZE ) )
+        {
+            // nothing to do.
+        }
+
+        public Packetizer(TransportData transport, String uri, Resources resources)
+        	: this(transport, new URL(uri), resources)
+        {
+           // nothing to do.
+        }
+
+        private readonly TransportData transport;
+
+        private SessionPacket session;
+
+        private readonly int maxPktSize;
+
+        public override string ToString()
+        {
+            return String.Format("Packetizer / {0}", transport);
+        }
+
+        private bool wantHeader = true;
+
+        private int bodyLen;
+
+        private readonly FlexBuffer savedBuf = new FlexBuffer();
+
+        private int ProcessHeader( FlexBuffer buf, bool reset )
+        {
+            int sig = buf.GetInt();
+            if ( sig != SIG )
+                throw new Exception( "bad SIG" );
+
+            int pktSize = buf.GetInt();
+
+            if ( reset )
+                buf.Reset();
+
+            if ( pktSize < 0 || (maxPktSize > 0 && pktSize > maxPktSize) )
+                throw new Exception( "pktSize < 0 || (maxPktSize > 0 && pktSize > maxPktSize)" );
+
+            return pktSize;
+
+        }
+
+  
+
+        public int HeaderSize()
+        {
+            return HEADER_SIZE;
+        }
+
+       
+
+
+        public Object SessionQuery( Object query )
+        {
+            return session.SessionQuery( query );
+        }
+
+        public void SessionControl( Object control, Object value )
+        {
+            session.SessionControl( control, value );
+        }
+
+        public void SessionNotify( Object eventObj )
+        {
+            session.SessionNotify( eventObj );
+        }
+
+
+      
+       
+
+       
+
+        public Object TransportQuery( Object query )
+        {
+            return transport.TransportQuery( query );
+        }
+
+        public void TransportControl( Object control, Object value )
+        {
+            transport.TransportControl( control, value );
+        }
+
+        public void TransportNotify( Object eventObj )
+        {
+            transport.TransportNotify( eventObj );
+        }
+
+        #region TransportPacket Members
+
+        public void SetSession(SessionPacket session)
+        {
+            this.session = session;
+        }
+
+        public SessionPacket GetSession()
+        {
+            return this.session;
+        }
+
+        public void TransportPacket(Who recipient, FlexBuffer buf)
+        {
+            // Data-ize the packet
+
+            // assert index is at the start of the header.
+            int dataSize = buf.Avail();
+            if (dataSize < HEADER_SIZE)
+                throw new ArgumentException("dataSize < HEADER_SIZE");
+
+			int pktSize = dataSize - HEADER_SIZE;
+			if (maxPktSize > 0 && pktSize > maxPktSize)
+				throw new ArgumentException( "maxPktSize > 0 && pktSize > maxPktSize" );
+			
+            int index = buf.Index();
+            buf.PutInt(SIG);
+            buf.PutInt(pktSize);
+            buf.SetIndex(index);
+            transport.TransportData(recipient, buf);
+        }
+
+        #endregion
+
+        #region SessionData Members
+
+        public void SessionData(Who sender, FlexBuffer buf)
+        {
+            while (buf.Avail() > 0)
+            {
+                if (wantHeader)
+                {
+                    // do we have enough to make a header
+                    if ((savedBuf.Length() + buf.Avail()) >= HEADER_SIZE)
+                    {
+                        int pktSize;
+                        if (savedBuf.Length() == 0)
+                        {
+                            // savedBuf is empty, entire header in buf.
+                            pktSize = ProcessHeader(buf, false);
+                        }
+                        else   // header split across savedBuf and buf
+                        {
+                            // move just enough data from buf to savedBuf to have a header.
+
+                            int needFromBuf = HEADER_SIZE - savedBuf.Length();
+                            savedBuf.Put(buf, needFromBuf);
+                            savedBuf.SetIndex(0);
+
+                            pktSize = ProcessHeader(savedBuf, true);
+
+
+                        }
+                        if (pktSize == 0)
+                            continue;
+
+                        bodyLen = pktSize;
+                        wantHeader = false;
+                    }
+                    else     // want header but not enough space to make it
+                    {
+                        // save buf in savedBuf.
+
+                        savedBuf.SetIndex(savedBuf.Length());
+                        savedBuf.Put(buf);
+                    }
+                }
+                else if ((savedBuf.Length() + buf.Avail()) >= bodyLen)
+                {
+                    // want body, and there's enough to make it.
+
+                    // three possible cases: the body is entirely in savedBuf,
+                    // the body is split, or the body is entirely in buf. assert
+                    // that the body cannot entirely be in savedBuf, or else
+                    // we'd have processed it last time.
+
+                    Debug.Assert(savedBuf.Length() < bodyLen);
+
+                    if (savedBuf.Length() == 0)
+                    {
+                        // savedBuf is empty, entire body in buf.
+
+                        int length = buf.Length();
+                        int index = buf.Index();
+                        buf.SetLength(index + bodyLen);
+
+                      //  handler.Packet(sender, buf);
+                        session.SessionPacket(sender,buf);
+
+                        buf.SetLength(length);
+                        buf.SetIndex(index + bodyLen);
+
+                        wantHeader = true;
+                    }
+
+                    else    // body split across savedBuf and buf
+                    {
+                        // move just enough data from buf to savedBuf to have a body.
+
+                        int needFromBuf = bodyLen - savedBuf.Length();
+                        savedBuf.Put(buf, needFromBuf);
+                        savedBuf.SetIndex(0);
+
+               //         handler.Packet(sender, savedBuf);
+                        session.SessionPacket(sender,savedBuf);
+
+                        savedBuf.Reset();
+                        wantHeader = true;
+                    }
+                }
+
+                else     // want body, but there's not enough to make it.
+                {
+                    // save buf in savedBuf.
+
+                    savedBuf.Put(buf);
+                }
+            }
+            // buf is now empty, and there's nothing else to do.
+            Debug.Assert(buf.Avail() == 0);
+        }
+
+        #endregion
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Packetizer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Packetizer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/PerfTest.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/PerfTest.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/PerfTest.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/PerfTest.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,114 @@
+// $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;
+using System.Collections.Generic;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Framework for running performance tests.
+    /// </summary>
+    public class PerfTest
+    {
+        private readonly String _descr;
+        private readonly int _runtime;
+        private readonly int _count;
+        private readonly RunTimes _r;
+
+        /// <summary>
+        /// Construct the perftest
+        /// </summary>
+        /// <param name="descr">description of the test</param>
+        /// <param name="runtime">the number of seconds to run each test cycle</param>
+        /// <param name="count">the number of test cycles to run</param>
+        public PerfTest( String descr, int runtime, int count, RunTimes rt )
+        {
+            _descr = descr;
+            _runtime = runtime;
+            _count = count;
+            _r = rt;
+        }
+
+        /// <summary>
+        /// Runs the PerfTest
+        /// </summary>
+        public void Run( )
+        {
+            
+            long oldn = 0;
+            long n = 1;
+            double t = 0;
+
+            while (t < 1)
+		    {
+			    if (t > 0.1)
+				    Console.WriteLine( "{0}: {1} took {2}, trying {3} to get >= 1 second\n", _descr, oldn, t, n );
+			    oldn = n;
+			    t = RunOne( n );
+			    n *= 2;
+		    }
+		    n = oldn;
+
+            int k = 2;
+		    n = (long) (k * n / t);
+		    Console.WriteLine( "{0}: {1} took {2}, trying {3} for {4} seconds\n", _descr, oldn, t, n, k );
+		    oldn = n;
+		    t = RunOne( n );
+
+            k = 4;
+		    n = (long) (k * n / t);
+		    Console.WriteLine( "{0}: {1} took {2}, trying {3} for {4} seconds\n", _descr, oldn, t, n, k );
+		    oldn = n;
+		    t = RunOne( n );
+    		
+		    n = (long) (_runtime * n / t);
+            Console.WriteLine( "{0}: {1} took {2}, using {3} for {4} seconds\n",
+			    _descr, oldn, t, n, _runtime );
+
+            List<double> list = new List<double>( _count );
+            double sum = 0;
+		    for (int i = 1; i <= _count; i++)
+		    {
+			    t = RunOne( n );
+			    double r = n/t;
+			    list.Add( r );
+			    sum += r;
+			    Console.WriteLine( "{0} {1}/{2}\t{3}\t{4}\t{5}\n",
+				    _descr, i, _count, n, t, r );
+		    }
+
+            list.Sort();
+            Console.WriteLine( "{0} min\t{1}\n", _descr, list[ 0 ] );
+            Console.WriteLine( "{0} median\t{1}\n", _descr, list[ _count/2 ] );
+		    Console.WriteLine( "{0} avg\t{1}\n", _descr, sum/_count );
+		    Console.WriteLine( "{0} max\t{1}\n", _descr, list[ _count-1 ] );
+        }
+
+        private double RunOne( long n )
+        {
+            long t0 = HPTimer.Now();
+            _r( n );
+            return HPTimer.SecondsSince(t0);
+        }
+
+        /// <summary>
+        /// Runs the test with the specific number of times.
+        /// </summary>
+        /// <param name="n"></param>
+        public delegate void RunTimes( long n );
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/PerfTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/PerfTest.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Resources.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Resources.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Resources.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Resources.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,45 @@
+// $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;
+using System.Collections.Generic;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public class Resources : Dictionary<String, Object>
+    {
+        public Resources()
+        {
+            // ignore
+        }
+
+        public Resources( Resources r )
+            : base( r )
+        { }
+
+        public Object Get( String key )
+        {
+            try
+            {
+                return this[ key ];
+            }
+            catch ( KeyNotFoundException )
+            {
+                return null;
+            }
+        }
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Resources.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Resources.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Runner.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Runner.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Runner.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Runner.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,131 @@
+// $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;
+using System.Threading;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Implementation of startable which creates a thread and runs.
+    /// </summary>
+    abstract public class Runner : AbstractStartable 
+    {
+        /// <summary>
+        /// Constructs the Runner.
+        /// </summary>
+        public Runner()
+        { 
+            // nothing to do.
+        }
+
+        /// <summary>
+        /// The handler is used to report started and stopped events.
+        /// </summary>
+        private RunnerHandler handler;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="handler">handler the handler to notify of started and stopped events.</param>
+        public void SetHandler(RunnerHandler handler)
+        {
+            this.handler = handler;
+        }
+
+        protected override void Start0()
+        {
+            thisThread = new Thread(new ThreadStart(Run));
+            thisThread.Start();
+        }
+
+        Thread thisThread;
+
+        protected override void Stop0()
+        {
+            Thread t = thisThread;
+            if (t != null)
+            {
+                thisThread = null;
+      //          t.Join( 30 );
+            }
+        }
+
+        public void Run()
+        {
+            FireStarted();
+
+            try
+            {
+                bool first = true;
+                while (IsStarted())
+                {
+                    if (!Run0(first))
+                        break;
+                    first = false;
+                }
+            }
+            catch (Exception e)
+            {
+                FireException("run", e);
+            }
+            finally
+            {
+                SetStopped();
+                FireStopped();
+            }
+        }
+
+        private void FireStarted()
+        {
+            handler.Started();
+        }
+
+        /// <summary>
+        /// Reports an exception caught by the thread managing the runnable.
+        /// </summary>
+        /// <param name="what"></param>
+        /// <param name="e"></param>
+        protected void FireException(String what, Exception e)
+        {
+            //Console.WriteLine( e );
+            try
+            {
+                handler.Exception(what, e);
+            }
+            catch (Exception x)
+            {
+                Console.WriteLine(e);
+                Console.WriteLine(x);
+            }
+        }
+
+        private void FireStopped()
+        {
+            handler.Stopped();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="first">true the first time we are called</param>
+        /// <returns>true if we should keep running.</returns>
+        /// Exception:
+        ///     throws Exception
+        abstract protected bool Run0(bool first);
+
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Runner.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Runner.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/RunnerHandler.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/RunnerHandler.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/RunnerHandler.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/RunnerHandler.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,45 @@
+// $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 Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// RunnerHandler receives notification of runner events.
+    /// </summary>
+    public interface RunnerHandler
+    {
+        /// <summary>
+        /// Reports that the thread controlling the runner has started.
+        /// </summary>
+        void Started( );
+
+        /// <summary>
+        /// Reports that the thread controlling the runner has stopped.
+        /// </summary>
+        void Stopped();
+
+        /// <summary>
+        /// Reports that the thread controlling the runner has caught an
+        /// exception.
+        /// </summary>
+        /// <param name="what">A short description of the origin</param>
+        /// <param name="e">Exception that was caught</param>
+        void Exception( String what, Exception e );
+
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/RunnerHandler.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/RunnerHandler.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Session.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Session.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Session.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Session.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,78 @@
+// $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 Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Out-of-band query, control, and notification interface for sessions.
+    /// </summary>
+    public interface Session
+    {
+        /// <summary>
+        /// Gets a configuration or operational value from the handler. The
+        /// request is passed up the chain of sessions until some session
+        /// recognises the query, whereupon it returns the requested value.
+        /// </summary>
+        /// <param name="query">an object representing a query, which could be as
+        /// simple as a string, integer, or enum, or more complex such as
+        /// a class with instance variables for query terms.</param>
+        /// <returns>the requested value, or null if not defined.</returns>
+        /// Exception:
+        ///     throws Exception if the query is not recognised
+        ///     by any session (which is to say, if the last session in the session
+        ///     chain does not recognise it, it should throw this exception). Typically
+        ///     this would be a service's client or server implementation.
+        ///     
+        Object SessionQuery( Object query );
+
+        /// <summary>
+        /// Sets a configuration or operational value in the session. The
+        /// request is passed up the chain of sessions until some session
+        /// recognises the control, whereupon it stores the specified value
+        /// and returns.
+        /// </summary>
+        /// <param name="control">an object representing a control, which could be as
+        /// simple as a string, integer, or enum, or more complex such as
+        /// a class with instance variables for control terms.</param>
+        /// <param name="value">the value to set</param>
+        /// Exception:
+        /// 
+        ///     throws ArgumentException if the value is not the right
+        ///     type or if the value is inappropriate.
+        /// 
+        ///     throws Exception if the query is not recognised
+        ///     by any session (which is to say, if the last session in the session
+        ///     chain does not recognise it, it should throw this exception). Typically
+        ///     this would be a service's client or server implementation.
+        ///     
+        void SessionControl( Object control, Object value );
+
+        /// <summary>
+        /// Notifies the chain of sessions of the specified event. Unlike query
+        /// and control operations above, events are always passed up to the
+        /// top to allow all sessions to notice them.
+        /// </summary>
+        /// <param name="eventObj">a class which represents the event, possibly with
+        /// parameters. The simplest event could be a string, integer,
+        /// or enum, but any class instance will do (as long as some session
+        /// in the chain expects it).</param>
+        /// 
+        void SessionNotify( Object eventObj );
+
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Session.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Session.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionConsts.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionConsts.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionConsts.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionConsts.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,38 @@
+// $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 Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public class SessionConsts
+    {
+
+        #region WELL KNOWN EVENTS
+
+        /// <summary>
+        /// Session event reporting the transport is up.
+        /// </summary>
+        public const String UP = "UP";
+
+        /// <summary>
+        /// Session event reporting the transport is down.
+        /// </summary>
+        public const String DOWN = "DOWN";
+
+        #endregion
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionConsts.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionConsts.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionData.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionData.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionData.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionData.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,23 @@
+// $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.
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public interface SessionData : Session
+    {
+        void SessionData(Who sender, FlexBuffer buf);
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionData.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionData.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionListener.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionListener.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionListener.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionListener.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,27 @@
+// $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.
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Interface used to deliver new connections to the session from the listener.
+    /// </summary>
+    /// <typeparam name="T">the type of the connection for the session.</typeparam>
+    public interface SessionListener<T> : Session
+    {
+        void SessionAccepted(T socket);
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionListener.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionListener.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionPacket.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionPacket.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionPacket.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionPacket.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,23 @@
+// $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.
+ 
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public interface SessionPacket : Session
+    {
+        void SessionPacket(Who sender, FlexBuffer buf);
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionPacket.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SessionPacket.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SingleIterator.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SingleIterator.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SingleIterator.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SingleIterator.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,87 @@
+// $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;
+using System.Collections.Generic;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// An iterator over a single object
+    /// </summary>
+    public class SingleIterator<E> : IEnumerator<E>
+    {
+        private E _obj;
+
+        public SingleIterator( Object obj )
+        {
+            _obj = ( E ) obj;
+        }
+
+        #region IEnumerator<E> Members
+
+        public E Current
+        {
+            get 
+            {
+                if ( _obj == null )
+                    throw new Exception( "No Such element" );
+
+                E o = _obj;
+                _obj = default(E);
+                return o;
+            }
+        }
+
+        #endregion
+
+        #region IDisposable Members
+
+        public void Dispose()
+        {
+            throw new Exception( "The method or operation is not implemented." );
+        }
+
+        #endregion
+
+        #region IEnumerator Members
+
+        object System.Collections.IEnumerator.Current
+        {
+            get
+            {
+                if ( _obj == null )
+                    throw new Exception( "No Such element" );
+
+                E o = _obj;
+                _obj = default( E );
+                return o;
+            }
+        }
+
+        public bool MoveNext()
+        {
+            return _obj != null;
+        }
+
+        public void Reset()
+        {
+            throw new Exception( "The method or operation is not implemented." );
+        }
+
+        #endregion
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SingleIterator.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/SingleIterator.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Startable.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Startable.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Startable.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Startable.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,47 @@
+// $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.
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Description of Startable
+    /// </summary>
+    public interface Startable
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// Exception:
+        ///     throws Exception
+        void Start();
+
+        /// Exception:
+        ///     throws Exception
+        void Stop();
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns>true if started</returns>
+        bool IsStarted();
+
+        /// <summary>
+        /// Check the startable is started
+        /// </summary>
+        void CheckIsStarted();
+    
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Startable.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/Startable.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMap.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMap.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMap.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMap.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,40 @@
+// $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.Collections.Generic;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// A hashmap which is from string to integer
+    /// </summary>
+    public class StrIntHashMap : Dictionary<string, int?>
+    {
+        public StrIntHashMap()
+        {
+            // nothing to do .
+        }
+
+        /// <summary>
+        /// Constructs a StrIntHashMap initialized from another
+        /// </summary>
+        /// <param name="other"></param>
+        public StrIntHashMap( StrIntHashMap other )
+            : base( other )
+        { }
+
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMap.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMap.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMapSerializer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMapSerializer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMapSerializer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMapSerializer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,92 @@
+// $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;
+using System.Collections.Generic;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+using Org.Apache.Etch.Bindings.Csharp.Support;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// An etch serializer for StrIntHashMap.
+    /// </summary>
+    public class StrIntHashMapSerializer : ImportExportHelper
+    {
+        private static String FIELD_NAME = "keysAndValues";
+
+        /// <summary>
+        /// Defines custom fields in the value factory so that the importer
+        /// can find them.
+        /// </summary>
+        /// <param name="type"></param>
+        ///  <param name="class2type"></param>
+        public static void Init( XType type, Class2TypeMap class2type )
+        {
+            Field field = type.GetField( FIELD_NAME );
+            class2type.Add( typeof( StrIntHashMap ), type );
+            type.SetComponentType( typeof( StrIntHashMap ) );
+            type.SetImportExportHelper( new StrIntHashMapSerializer( type, field ) );
+            type.PutValidator( field, Validator_object.Get( 1 ) );
+            type.Lock();
+        }
+
+        public StrIntHashMapSerializer( XType type, Field field )
+        {
+            this.type = type;
+            this.field = field;
+        }
+
+        private readonly XType type;
+        private readonly Field field;
+
+        public override Object ImportValue( StructValue sv )
+        {
+            StrIntHashMap map = new StrIntHashMap();
+
+            Object[] keysAndValues = ( Object[] ) sv.Get( field );
+            int n = keysAndValues.Length;
+            int index = 0;
+            while ( index < n )
+            {
+                string key = ( String ) keysAndValues[ index++ ];
+                int? value = ( int? ) keysAndValues[ index++ ];
+                map.Add( key, value );
+            }
+            
+            return map;
+        }
+
+        public override StructValue ExportValue(ValueFactory vf, Object value)
+        {
+            StrIntHashMap map = ( StrIntHashMap ) value;
+
+            Object[] keysAndValues = new Object[ map.Count * 2 ];
+            int index = 0;
+
+            foreach( KeyValuePair<String, int?> me in map )
+            {
+                keysAndValues[ index++ ] = me.Key;
+                keysAndValues[ index++ ] = me.Value;
+            }
+
+            StructValue sv = new StructValue(type, vf);
+            sv.Add( field, keysAndValues );
+            return sv;
+
+        }
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMapSerializer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrIntHashMapSerializer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMap.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMap.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMap.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMap.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,40 @@
+// $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.Collections.Generic;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// A hashmap which is from string to integer
+    /// </summary>
+    public class StrStrHashMap : Dictionary<string, string>
+    {
+        public StrStrHashMap()
+        {
+            // nothing to do .
+        }
+
+        /// <summary>
+        /// Constructs a StrStrHashMap initialized from another
+        /// </summary>
+        /// <param name="other"></param>
+        public StrStrHashMap( StrStrHashMap other )
+            : base( other )
+        { }
+
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMap.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMap.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMapSerializer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMapSerializer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMapSerializer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMapSerializer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,94 @@
+// $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;
+using System.Collections.Generic;
+using Org.Apache.Etch.Bindings.Csharp.Msg;
+using Org.Apache.Etch.Bindings.Csharp.Support;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// An etch serializer for StrStrHashMap.
+    /// </summary>
+    public class StrStrHashMapSerializer : ImportExportHelper
+    {
+        private static String FIELD_NAME = "keysAndValues";
+
+        /// <summary>
+        /// Defines custom fields in the value factory so that the importer
+        /// can find them.
+        /// </summary>
+        /// <param name="type"></param>
+        /// <param name="class2type"></param>
+        public static void Init( XType type, Class2TypeMap class2type )
+        {
+            Field field = type.GetField( FIELD_NAME );
+            class2type.Add( typeof( StrStrHashMap ), type );
+            type.SetComponentType( typeof( StrStrHashMap ) );
+            type.SetImportExportHelper( new StrStrHashMapSerializer( type, field ) );
+            type.PutValidator( field, Validator_object.Get( 1 ) );
+            type.Lock();
+        }
+
+        public StrStrHashMapSerializer( XType type, Field field )
+        {
+            this.type = type;
+            this.field = field;
+        }
+
+        private readonly XType type;
+        private readonly Field field;
+
+
+        public override Object ImportValue( StructValue sv )
+        {
+            StrStrHashMap map = new StrStrHashMap();
+
+            Object[] keysAndValues = ( Object[] ) sv.Get( field );
+            int n = keysAndValues.Length;
+            int index = 0;
+            while ( index < n )
+            {
+                String key = ( String ) keysAndValues[ index++ ];
+                String value = ( String ) keysAndValues[ index++ ];
+                map.Add( key, value );
+            }
+
+            return map;
+        }
+
+        public override StructValue ExportValue(ValueFactory vf, Object value)
+        {
+            StrStrHashMap map = ( StrStrHashMap ) value;
+
+            Object[] keysAndValues = new Object[ map.Count * 2 ];
+            int index = 0;
+
+            foreach ( KeyValuePair<String, String> me in map )
+            {
+                keysAndValues[ index++ ] = me.Key;
+                keysAndValues[ index++ ] = me.Value;
+            }
+
+            StructValue sv = new StructValue(type, vf);
+            sv.Add( field, keysAndValues );
+            return sv;
+
+        }
+
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMapSerializer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StrStrHashMapSerializer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringTokenizer.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringTokenizer.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringTokenizer.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringTokenizer.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,84 @@
+// $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 Org.Apache.Etch.Bindings.Csharp.Util
+{
+    public class StringTokenizer
+    {
+        public StringTokenizer(string s, string seps)
+        {
+            this.s = s;
+            this.seps = seps;
+        }
+
+        private readonly string s;
+
+        private readonly string seps;
+
+        private int index = 0;
+
+        public bool HasMoreTokens()
+        {
+            if (token == null)
+                token = GetNextToken();
+
+            return token != null;
+        }
+
+        public string NextToken()
+        {
+            if (token == null)
+            {
+                token = GetNextToken();
+                if (token == null)
+                    throw new IndexOutOfRangeException("no more tokens");
+            }
+
+            string t = token;
+            token = null;
+            return t;
+        }
+
+        private string GetNextToken()
+        {
+            SkipSeps();
+
+            int i = index;
+            while (index < s.Length  &&  !IsSep(s[index]))
+                index++;
+
+            if (index > i)
+                return s.Substring(i, index - i);
+
+            return null;
+        }
+
+        private void SkipSeps()
+        {
+            while (index < s.Length && IsSep(s[index]))
+                index++;
+        }
+
+        private bool IsSep(char c)
+        {
+            return seps.IndexOf(c) >= 0;
+        }
+
+        private string token;
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringTokenizer.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringTokenizer.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringUtil.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringUtil.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringUtil.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringUtil.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,118 @@
+// $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 Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Miscellaneous string utility functions
+    /// </summary>
+    /// 
+    public class StringUtil
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="s"></param>
+        /// <param name="c"></param>
+        /// <returns>an array x of two elements containing s split in two by the
+        /// leftmost c. x[0] is the chars before c, x[1] is the chars after c.
+        /// If c is not in s, returns null.</returns>
+        /// 
+        public static String[] LeftSplit( String s, char c )
+        {
+            if ( s == null )
+                throw new ArgumentNullException( "Passed string is null" );
+
+            int i = s.IndexOf( c );
+            if ( i < 0 )
+                return null;
+
+            return new String[] { s.Substring( 0, i ), s.Substring( i+1 ) };
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="s"></param>
+        /// <param name="c"></param>
+        /// <returns>an array x of two elements containing s split in two by the
+        /// rightmost c. x[0] is the chars before c, x[1] is the chars after c.
+        /// If c is not in s, returns null.</returns>
+        public static String[] RightSplit( String s, Char c )
+        {
+            if ( s == null )
+                throw new ArgumentNullException( "Passed string is null" );
+
+            int i = s.LastIndexOf( c );
+            if ( i < 0 )
+                return null;
+
+            return new String[] { s.Substring( 0, i ), s.Substring( i+1 ) };
+        }
+
+        /// <summary>
+        /// Translates an int into a hex char.
+        /// </summary>
+        /// <param name="i">i an int (0-15)</param>
+        /// <returns>a hex char (0-9, a-f).</returns>
+        /// 
+        public static char ToHex( int i )
+        {
+            if ( i >= 0 && i <= 9 )
+                return ( char ) ( '0' + i );
+            if ( i >= 10 && i <= 15 )
+                return ( char ) ( 'a' + i - 10 );
+            throw new ArgumentException( "bad hex digit selector "+i );
+        }
+
+        /// <summary>
+        /// Translates a hex char into an int.
+        /// </summary>
+        /// <param name="c">a hex char (0-9, A-F, a-f).</param>
+        /// <returns>an int (0-15).</returns>
+        /// 
+        public static int FromHex( char c )
+        {
+            if ( c >= '0' && c <= '9' )
+                return c - '0';
+            if ( c >= 'A' && c <= 'F' )
+                return c - 'a' + 10;
+            if ( c >= 'a' && c <= 'f' )
+                return c - 'a' + 10;
+            throw new ArgumentException( "bad hex char "+c );
+        }
+
+        public static bool Eq(string a, string b)
+        {
+            if (ReferenceEquals(a, b))
+                return true;
+            if (a == null || b == null)
+                return false;
+            return a.Equals(b);
+        }
+
+        public static bool EqIgnoreCase(string a, string b)
+        {
+            if (ReferenceEquals(a, b))
+                return true;
+            if (a == null || b == null)
+                return false;
+            return a.Equals(b, StringComparison.CurrentCultureIgnoreCase);
+        }
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringUtil.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/StringUtil.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpConnection.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpConnection.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpConnection.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpConnection.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,104 @@
+// $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;
+using System.Net;
+using System.Net.Sockets;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Implementation of connection which handles a tcp connection.
+    /// </summary>
+    public class TcpConnection : TcpTransport
+    {
+        public TcpConnection(Socket socket, string uri, Resources resources)
+            : this(socket, new URL(uri), resources)
+        {
+            // nothing to do.
+        }
+
+        public TcpConnection(Socket socket, URL uri, Resources resources)
+            : base(uri, resources)
+        {
+            if (socket == 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 ArgumentException("port <= 0 || port >= 65536");
+
+                this.socket = null;
+                //this.host = host;
+                //this.port = (int)port;
+            }
+            else
+            {
+                this.socket = socket;
+                host = null;
+                port = 0;
+            }
+        }
+
+        private readonly String host;
+
+        private readonly int port;
+
+        public override string ToString()
+        {
+            Socket s = socket;
+
+            if (s != null)
+                return String.Format("TcpConnection(up, {0}, {1})",
+                    s.LocalEndPoint, s.RemoteEndPoint);
+
+            return String.Format("TcpConnection(down, {0}, {1})", host, port);
+        }
+
+        protected override bool IsServer()
+        {
+            return host == null;
+        }
+
+        protected override Socket NewSocket()
+        {
+            IPAddress addr;
+
+            if (host != null)
+            {
+                IPAddress[] addrs = Dns.GetHostAddresses(host);
+                if (addrs == null || addrs.Length == 0)
+                    throw new ArgumentException("host is invalid");
+                addr = addrs[0];
+            }
+            else
+            {
+                addr = IPAddress.Any;
+            }
+
+            IPEndPoint ipe = new IPEndPoint(addr, port);
+            Socket socket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+            socket.Connect(ipe);
+            return socket;
+        }
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpConnection.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpConnection.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpListener.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpListener.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpListener.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpListener.cs Fri Jan 30 22:25:03 2009
@@ -0,0 +1,269 @@
+// $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;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Runtime.CompilerServices;
+
+namespace Org.Apache.Etch.Bindings.Csharp.Util
+{
+    /// <summary>
+    /// Implementation of a connection which handles a socket listener.
+    /// </summary>
+    public class TcpListener : Connection<SessionListener<Socket>>
+    {
+        /// <summary>
+        /// Constructs the TcpListener.
+        /// </summary>
+        /// <param name="backlog">max number of pending connection requests.</param>
+        /// <param name="host">address to listen to. Null means any local address.</param>
+        /// <param name="port">port to listen on. Port must be >= 0. Port of 0
+        /// means allocate an available port.</param>
+        /// <param name="delay">how long in milliseconds to wait before retrying a
+        /// failure. Delay must be >= 0. Delay of 0 means do not retry.</param>
+
+        private TcpListener( int backlog, String host, int port, int delay ) 
+        {
+            if ( backlog < 0 )
+                throw new ArgumentException( "backlog < 0" );
+
+            if ( port < 0 || port > 65535 )
+                throw new ArgumentException( "port < 0 || port > 65535" );
+
+            if ( delay < 0 )
+                throw new ArgumentException( "delay < 0" );
+
+            this.backlog = backlog;
+            this.host = host;
+            this.port = port;
+            this.delay = delay;
+        }
+
+        /// <summary>
+        /// Query term from URI to specify backlog value to ServerSocket. The
+        /// value is "TcpListener.backlog".
+        /// </summary>
+        public const String BACKLOG = "TcpListener.backlog";
+
+
+        public TcpListener(URL uri, Resources resources)
+            : this((int)uri.GetIntegerTerm(BACKLOG, 0), TranslateHost(uri.Host), uri.Port != null ? uri.Port.Value : 0, 0)
+        {
+            // nothing else.
+        }
+
+        /// <summary>
+        /// Constructs a TcpListener, initialized from the URI. Listens on the host
+        /// and port specified in the URI. To listen on all interfaces, specify
+        /// host as ALL_INTFS ("0.0.0.0"). If port is specified or defaulted to 0,
+        /// an unused port will be selected.
+        /// </summary>
+        /// <param name="uri"></param>
+
+        public TcpListener(string uri, Resources resources)
+            : this(new URL(uri), resources)
+        {
+            // nothing else.
+        }
+
+        private int backlog;
+	
+	    private String host;
+    	
+	    private int port;
+    	
+	    private int delay;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// Exception:
+        ///     throws Exception
+        
+        protected override void Stop0()
+        {
+            Close( true );
+            base.Stop0();
+        }
+        
+        /// <summary>
+        /// 
+        /// </summary>
+        /// Exception:
+        ///     throws Exception
+        /// <returns></returns>
+        private Socket CheckSocket()
+        {
+            Socket ss = serverSocket;
+            if ( ss == null )
+            {
+                //Console.WriteLine( "----socket was null----" );
+                throw new IOException("server socket is closed");
+            }
+            return ss;
+        }
+
+        private Socket serverSocket;
+
+        public override string ToString()
+        {
+            Socket ss = serverSocket;
+
+            if ( ss == null )
+                return String.Format("TcpListener (down, {0}:{1})", host, port);
+
+            return String.Format("TcpListener (up, {0})", ss.LocalEndPoint);
+        }
+
+        [MethodImpl (MethodImplOptions.Synchronized)]
+        protected override bool OpenSocket( bool reconnect )
+        {
+            bool first = true;
+            while ( IsStarted() )
+            {
+                if ( reconnect || !first )
+                {
+                    if ( delay == 0 )
+                        return false;
+
+                    System.Threading.Monitor.Wait(this, delay);
+
+                    if ( !IsStarted() )
+                        break;
+                }
+
+                try
+                {
+                    //IPHostEntry ipEntry = Dns.GetHostEntry( host );
+
+                    IPAddress addr;
+                    if ( host != null )
+                    {
+                        IPAddress[] addrs = Dns.GetHostAddresses( host );
+                        if ( addrs == null || addrs.Length == 0 )
+                            throw new ArgumentException( "host is invalid" );
+                        addr = addrs[ 0 ];
+                    }
+                    else 
+                    {
+                        addr = IPAddress.Any;
+                    }
+                    
+                    //IPAddress[] addr = ipEntry.AddressList;
+                    //string sIPAddress = addr[ 0 ].ToString();
+
+                    IPEndPoint ipe = new IPEndPoint( addr, port );
+                    
+                    serverSocket = new Socket( ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp );
+
+                    try
+                    {
+                        serverSocket.Bind(ipe);
+                    }
+                    catch (SocketException e)
+                    {
+                        throw new IOException("Could not bind address "+host+":"+port, e);
+                    }
+
+                    serverSocket.Listen( backlog );
+
+                    return true;
+                }
+                catch (Exception e)
+                {
+                    if ( first )
+                    {
+                        first = false;
+                        FireException( "open", e );
+                    }
+                }
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// Exception:
+        ///     throws Exception
+        protected override void SetUpSocket()
+        {
+            // nothing to do.
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// Exception:
+        ///     throws Exception
+        protected override void ReadSocket()
+        {
+            try
+            {
+                Socket ss = CheckSocket();
+                while (IsStarted())
+                {
+                    Socket s = ss.Accept();
+
+                    try
+                    {
+                        session.SessionAccepted(s);
+                    }
+                    catch (Exception e)
+                    {
+                        s.Close();
+                        FireException("accepted", e);
+                    }
+                }
+            }
+            catch (SocketException e)
+            {
+                if (e.Message != null && e.Message.Contains("interrupted"))
+                    return;
+                throw;
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="reset"></param>
+        /// Exception:
+        ///     throws Exception
+        public override void Close( bool reset )
+        {
+            Socket ss = serverSocket;
+            if ( ss != null )
+            {
+                serverSocket = null;
+                ss.Close();
+            }
+        }
+
+        public override EndPoint LocalAddress()
+        {
+            return CheckSocket().LocalEndPoint;
+        }
+
+        public override EndPoint RemoteAddress()
+        {
+            // ignore
+            return null;
+        }
+    }
+}

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpListener.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpListener.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpOptions.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpOptions.cs?rev=739432&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpOptions.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpOptions.cs Fri Jan 30 22:25:03 2009
@@ -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 Org.Apache.Etch.Bindings.Csharp.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/Org.Apache.Etch.Bindings.Csharp/Util/TcpOptions.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/etch/trunk/binding-csharp/runtime/src/main/csharp/Org.Apache.Etch.Bindings.Csharp/Util/TcpOptions.cs
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"