Return-Path: Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: (qmail 53620 invoked from network); 3 Dec 2009 22:05:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Dec 2009 22:05:01 -0000 Received: (qmail 49127 invoked by uid 500); 3 Dec 2009 22:05:01 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 49108 invoked by uid 500); 3 Dec 2009 22:05:01 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 49099 invoked by uid 99); 3 Dec 2009 22:05:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Dec 2009 22:05:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Dec 2009 22:04:49 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5D47D2388A66; Thu, 3 Dec 2009 22:04:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r886940 [7/14] - in /qpid/trunk/qpid/dotnet/client-010: ./ addins/ addins/ExcelAddIn/ addins/ExcelAddInMessageProcessor/ addins/ExcelAddInProducer/ client/ client/client/ client/transport/ client/transport/codec/ client/transport/exception/... Date: Thu, 03 Dec 2009 22:03:55 -0000 To: commits@qpid.apache.org From: aidan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091203220402.5D47D2388A66@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoSSLTransport.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoSSLTransport.cs?rev=886940&r1=886939&r2=886940&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoSSLTransport.cs (original) +++ qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoSSLTransport.cs Thu Dec 3 22:03:51 2009 @@ -1,194 +1,194 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ -using System; -using System.IO; -using System.Net.Security; -using System.Net.Sockets; -using System.Security.Authentication; -using System.Security.Cryptography.X509Certificates; -using org.apache.qpid.transport.util; - -namespace org.apache.qpid.transport.network.io -{ - public sealed class IoSSLTransport : IIoTransport - { - // constants - private const int DEFAULT_READ_WRITE_BUFFER_SIZE = 64*1024; - private const int TIMEOUT = 60000; - private const int QUEUE_SIZE = 1000; - // props - private static readonly Logger log = Logger.get(typeof (IoSSLTransport)); - private Stream m_stream; - private IoSender m_sender; - private Receiver> m_receiver; - private TcpClient m_socket; - private Connection m_con; - private readonly bool _rejectUntrusted; - - public static Connection connect(String host, int port, string serverName, string certPath, bool rejectUntrusted, ConnectionDelegate conndel) - { - IIoTransport transport = new IoSSLTransport(host, port, serverName, certPath, rejectUntrusted, conndel); - return transport.Connection; - } - - public IoSSLTransport(String host, int port, string serverName, string certPath, bool rejectUntrusted, ConnectionDelegate conndel) - { - _rejectUntrusted = rejectUntrusted; - createSocket(host, port, serverName, certPath); - Sender = new IoSender(this, QUEUE_SIZE, TIMEOUT); - Receiver = new IoReceiver(Stream, Socket.ReceiveBufferSize*2, TIMEOUT); - Assembler assembler = new Assembler(); - InputHandler inputHandler = new InputHandler(InputHandler.State.PROTO_HDR); - Connection = new Connection(assembler, new Disassembler(Sender, 64*1024 - 1), conndel); - // Input handler listen to Receiver events - Receiver.Received += inputHandler.On_ReceivedBuffer; - // Assembler listen to inputhandler events - inputHandler.ReceivedEvent += assembler.On_ReceivedEvent; - // Connection listen to asembler protocol event - Receiver.Closed += Connection.On_ReceivedClosed; - Receiver.Exception += Connection.On_ReceivedException; - inputHandler.HandlerClosed += Connection.On_ReceivedClosed; - inputHandler.ExceptionProcessing += Connection.On_ReceivedException; - assembler.HandlerClosed += Connection.On_ReceivedClosed; - assembler.ExceptionProcessing += Connection.On_ReceivedException; - assembler.ReceivedEvent += Connection.On_ReceivedEvent; - } - - public Connection Connection - { - get { return m_con; } - set { m_con = value; } - } - - public Receiver> Receiver - { - get { return m_receiver; } - set { m_receiver = value; } - } - - public IoSender Sender - { - get { return m_sender; } - set { m_sender = value; } - } - - - public Stream Stream - { - get { return m_stream; } - set { m_stream = value; } - } - - public TcpClient Socket - { - get { return m_socket; } - set { m_socket = value; } - } - - #region Private Support Functions - - private void createSocket(String host, int port, string serverName, string certPath) - { - TcpClient socket; - try - { - socket = new TcpClient(); - String noDelay = Environment.GetEnvironmentVariable("qpid.tcpNoDelay"); - String writeBufferSize = Environment.GetEnvironmentVariable("qpid.writeBufferSize"); - String readBufferSize = Environment.GetEnvironmentVariable("qpid.readBufferSize"); - socket.NoDelay = noDelay != null && bool.Parse(noDelay); - socket.ReceiveBufferSize = readBufferSize == null - ? DEFAULT_READ_WRITE_BUFFER_SIZE - : int.Parse(readBufferSize); - socket.SendBufferSize = writeBufferSize == null - ? DEFAULT_READ_WRITE_BUFFER_SIZE - : int.Parse(writeBufferSize); - - log.debug("NoDelay : {0}", socket.NoDelay); - log.debug("ReceiveBufferSize : {0}", socket.ReceiveBufferSize); - log.debug("SendBufferSize : {0}", socket.SendBufferSize); - log.debug("Openning connection with host : {0}; port: {1}", host, port); - - socket.Connect(host, port); - Socket = socket; - } - catch (Exception e) - { - throw new TransportException("Error connecting to broker", e); - } - try - { - //Initializes a new instance of the SslStream class using the specified Stream, stream closure behavior, certificate validation delegate and certificate selection delegate - SslStream sslStream = new SslStream(socket.GetStream(), false, ValidateServerCertificate, LocalCertificateSelection); - if (certPath != null) - { - X509CertificateCollection col = new X509CertificateCollection(); - X509Certificate cert = X509Certificate.CreateFromCertFile(certPath); - col.Add(cert); - sslStream.AuthenticateAsClient(serverName, col, SslProtocols.Default, true); - } - else - { - sslStream.AuthenticateAsClient(serverName); - } - Stream = sslStream; - } - catch (AuthenticationException e) - { - log.warn("Exception: {0}", e.Message); - if (e.InnerException != null) - { - log.warn("Inner exception: {0}", e.InnerException.Message); - } - socket.Close(); - throw new TransportException("Authentication failed - closing the connection."); - } - } - - // The following method is invoked by the RemoteCertificateValidationDelegate. - public bool ValidateServerCertificate( - object sender, - X509Certificate certificate, - X509Chain chain, - SslPolicyErrors sslPolicyErrors) - { - bool result = true; - if (sslPolicyErrors != SslPolicyErrors.None && _rejectUntrusted ) - { - log.warn("Certificate error: {0}", sslPolicyErrors); - // Do not allow this client to communicate with unauthenticated servers. - result = false; - } - return result; - } - - public X509Certificate LocalCertificateSelection( - Object sender, - string targetHost, - X509CertificateCollection localCertificates, - X509Certificate remoteCertificate, - string[] acceptableIssuers - ) - { - return remoteCertificate; - } - - #endregion - } -} +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +using System; +using System.IO; +using System.Net.Security; +using System.Net.Sockets; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; +using org.apache.qpid.transport.util; + +namespace org.apache.qpid.transport.network.io +{ + public sealed class IoSSLTransport : IIoTransport + { + // constants + private const int DEFAULT_READ_WRITE_BUFFER_SIZE = 64*1024; + private const int TIMEOUT = 60000; + private const int QUEUE_SIZE = 1000; + // props + private static readonly Logger log = Logger.get(typeof (IoSSLTransport)); + private Stream m_stream; + private IoSender m_sender; + private Receiver> m_receiver; + private TcpClient m_socket; + private Connection m_con; + private readonly bool _rejectUntrusted; + + public static Connection connect(String host, int port, string serverName, string certPath, bool rejectUntrusted, ConnectionDelegate conndel) + { + IIoTransport transport = new IoSSLTransport(host, port, serverName, certPath, rejectUntrusted, conndel); + return transport.Connection; + } + + public IoSSLTransport(String host, int port, string serverName, string certPath, bool rejectUntrusted, ConnectionDelegate conndel) + { + _rejectUntrusted = rejectUntrusted; + createSocket(host, port, serverName, certPath); + Sender = new IoSender(this, QUEUE_SIZE, TIMEOUT); + Receiver = new IoReceiver(Stream, Socket.ReceiveBufferSize*2, TIMEOUT); + Assembler assembler = new Assembler(); + InputHandler inputHandler = new InputHandler(InputHandler.State.PROTO_HDR); + Connection = new Connection(assembler, new Disassembler(Sender, 64*1024 - 1), conndel); + // Input handler listen to Receiver events + Receiver.Received += inputHandler.On_ReceivedBuffer; + // Assembler listen to inputhandler events + inputHandler.ReceivedEvent += assembler.On_ReceivedEvent; + // Connection listen to asembler protocol event + Receiver.Closed += Connection.On_ReceivedClosed; + Receiver.Exception += Connection.On_ReceivedException; + inputHandler.HandlerClosed += Connection.On_ReceivedClosed; + inputHandler.ExceptionProcessing += Connection.On_ReceivedException; + assembler.HandlerClosed += Connection.On_ReceivedClosed; + assembler.ExceptionProcessing += Connection.On_ReceivedException; + assembler.ReceivedEvent += Connection.On_ReceivedEvent; + } + + public Connection Connection + { + get { return m_con; } + set { m_con = value; } + } + + public Receiver> Receiver + { + get { return m_receiver; } + set { m_receiver = value; } + } + + public IoSender Sender + { + get { return m_sender; } + set { m_sender = value; } + } + + + public Stream Stream + { + get { return m_stream; } + set { m_stream = value; } + } + + public TcpClient Socket + { + get { return m_socket; } + set { m_socket = value; } + } + + #region Private Support Functions + + private void createSocket(String host, int port, string serverName, string certPath) + { + TcpClient socket; + try + { + socket = new TcpClient(); + String noDelay = Environment.GetEnvironmentVariable("qpid.tcpNoDelay"); + String writeBufferSize = Environment.GetEnvironmentVariable("qpid.writeBufferSize"); + String readBufferSize = Environment.GetEnvironmentVariable("qpid.readBufferSize"); + socket.NoDelay = noDelay != null && bool.Parse(noDelay); + socket.ReceiveBufferSize = readBufferSize == null + ? DEFAULT_READ_WRITE_BUFFER_SIZE + : int.Parse(readBufferSize); + socket.SendBufferSize = writeBufferSize == null + ? DEFAULT_READ_WRITE_BUFFER_SIZE + : int.Parse(writeBufferSize); + + log.debug("NoDelay : {0}", socket.NoDelay); + log.debug("ReceiveBufferSize : {0}", socket.ReceiveBufferSize); + log.debug("SendBufferSize : {0}", socket.SendBufferSize); + log.debug("Openning connection with host : {0}; port: {1}", host, port); + + socket.Connect(host, port); + Socket = socket; + } + catch (Exception e) + { + throw new TransportException("Error connecting to broker", e); + } + try + { + //Initializes a new instance of the SslStream class using the specified Stream, stream closure behavior, certificate validation delegate and certificate selection delegate + SslStream sslStream = new SslStream(socket.GetStream(), false, ValidateServerCertificate, LocalCertificateSelection); + if (certPath != null) + { + X509CertificateCollection col = new X509CertificateCollection(); + X509Certificate cert = X509Certificate.CreateFromCertFile(certPath); + col.Add(cert); + sslStream.AuthenticateAsClient(serverName, col, SslProtocols.Default, true); + } + else + { + sslStream.AuthenticateAsClient(serverName); + } + Stream = sslStream; + } + catch (AuthenticationException e) + { + log.warn("Exception: {0}", e.Message); + if (e.InnerException != null) + { + log.warn("Inner exception: {0}", e.InnerException.Message); + } + socket.Close(); + throw new TransportException("Authentication failed - closing the connection."); + } + } + + // The following method is invoked by the RemoteCertificateValidationDelegate. + public bool ValidateServerCertificate( + object sender, + X509Certificate certificate, + X509Chain chain, + SslPolicyErrors sslPolicyErrors) + { + bool result = true; + if (sslPolicyErrors != SslPolicyErrors.None && _rejectUntrusted ) + { + log.warn("Certificate error: {0}", sslPolicyErrors); + // Do not allow this client to communicate with unauthenticated servers. + result = false; + } + return result; + } + + public X509Certificate LocalCertificateSelection( + Object sender, + string targetHost, + X509CertificateCollection localCertificates, + X509Certificate remoteCertificate, + string[] acceptableIssuers + ) + { + return remoteCertificate; + } + + #endregion + } +} Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoSender.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoSender.cs?rev=886940&r1=886939&r2=886940&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoSender.cs (original) +++ qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoSender.cs Thu Dec 3 22:03:51 2009 @@ -1,134 +1,134 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ -using System; -using System.IO; -using System.Threading; -using common.org.apache.qpid.transport.util; -using org.apache.qpid.transport.util; - -namespace org.apache.qpid.transport.network.io -{ - public sealed class IoSender : IIOSender - { - private static readonly Logger log = Logger.get(typeof (IoReceiver)); - private readonly Stream bufStream; - private bool closed; - private readonly Mutex mutClosed = new Mutex(); - private readonly CircularBuffer queue; - private readonly Thread thread; - private readonly int timeout; - private readonly MemoryStream _tobeSent = new MemoryStream(); - public IoSender(IIoTransport transport, int queueSize, int timeout) - { - this.timeout = timeout; - bufStream = transport.Stream; - queue = new CircularBuffer(queueSize); - thread = new Thread(Go); - log.debug("Creating IoSender thread"); - thread.Name = String.Format("IoSender - {0}", transport.Socket) ; - thread.IsBackground = true; - thread.Start(); - } - - public void send(MemoryStream str) - { - int pos = (int) str.Position; - str.Seek(0, SeekOrigin.Begin); - send(str, pos); - } - - public void send(MemoryStream str, int size) - { - mutClosed.WaitOne(); - if (closed) - { - throw new TransportException("sender is closed"); - } - mutClosed.ReleaseMutex(); - byte[] buf = new byte[size]; - str.Read(buf, 0, size); - _tobeSent.Write(buf, 0, size); - } - - public void flush() - { - int length = (int)_tobeSent.Position; - byte[] buf = new byte[length]; - _tobeSent.Seek(0, SeekOrigin.Begin); - _tobeSent.Read(buf, 0, length); - queue.Enqueue(buf); - // bufStream.Write(buf, 0, length); - // _tobeSent = new MemoryStream(); - // _writer.Write(buf, 0, length); - // _writer.Flush(); - _tobeSent.Seek(0, SeekOrigin.Begin); - } - - public void close() - { - log.debug("Closing Sender"); - mutClosed.WaitOne(); - if (!closed) - { - try - { - closed = true; - queue.close(); - thread.Join(timeout); - if (thread.IsAlive) - { - throw new TransportException("join timed out"); - } - } - catch (ThreadInterruptedException e) - { - throw new TransportException(e); - } - catch (IOException e) - { - throw new TransportException(e); - } - } - mutClosed.ReleaseMutex(); - } - - private void Go() - { - while (! closed) - { - //MemoryStream st = queue.Dequeue(); - byte[] st = queue.Dequeue(); - if (st != null) - { - try - { - // int length = (int) st.Length; - // byte[] buf = new byte[length]; - // st.Read(buf, 0, length); - bufStream.Write(st, 0, st.Length); - } - catch (Exception e) - { - Console.WriteLine(e); - } - } - } - } - } +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +using System; +using System.IO; +using System.Threading; +using common.org.apache.qpid.transport.util; +using org.apache.qpid.transport.util; + +namespace org.apache.qpid.transport.network.io +{ + public sealed class IoSender : IIOSender + { + private static readonly Logger log = Logger.get(typeof (IoReceiver)); + private readonly Stream bufStream; + private bool closed; + private readonly Mutex mutClosed = new Mutex(); + private readonly CircularBuffer queue; + private readonly Thread thread; + private readonly int timeout; + private readonly MemoryStream _tobeSent = new MemoryStream(); + public IoSender(IIoTransport transport, int queueSize, int timeout) + { + this.timeout = timeout; + bufStream = transport.Stream; + queue = new CircularBuffer(queueSize); + thread = new Thread(Go); + log.debug("Creating IoSender thread"); + thread.Name = String.Format("IoSender - {0}", transport.Socket) ; + thread.IsBackground = true; + thread.Start(); + } + + public void send(MemoryStream str) + { + int pos = (int) str.Position; + str.Seek(0, SeekOrigin.Begin); + send(str, pos); + } + + public void send(MemoryStream str, int size) + { + mutClosed.WaitOne(); + if (closed) + { + throw new TransportException("sender is closed"); + } + mutClosed.ReleaseMutex(); + byte[] buf = new byte[size]; + str.Read(buf, 0, size); + _tobeSent.Write(buf, 0, size); + } + + public void flush() + { + int length = (int)_tobeSent.Position; + byte[] buf = new byte[length]; + _tobeSent.Seek(0, SeekOrigin.Begin); + _tobeSent.Read(buf, 0, length); + queue.Enqueue(buf); + // bufStream.Write(buf, 0, length); + // _tobeSent = new MemoryStream(); + // _writer.Write(buf, 0, length); + // _writer.Flush(); + _tobeSent.Seek(0, SeekOrigin.Begin); + } + + public void close() + { + log.debug("Closing Sender"); + mutClosed.WaitOne(); + if (!closed) + { + try + { + closed = true; + queue.close(); + thread.Join(timeout); + if (thread.IsAlive) + { + throw new TransportException("join timed out"); + } + } + catch (ThreadInterruptedException e) + { + throw new TransportException(e); + } + catch (IOException e) + { + throw new TransportException(e); + } + } + mutClosed.ReleaseMutex(); + } + + private void Go() + { + while (! closed) + { + //MemoryStream st = queue.Dequeue(); + byte[] st = queue.Dequeue(); + if (st != null) + { + try + { + // int length = (int) st.Length; + // byte[] buf = new byte[length]; + // st.Read(buf, 0, length); + bufStream.Write(st, 0, st.Length); + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + } + } + } } \ No newline at end of file Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoTransport.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoTransport.cs?rev=886940&r1=886939&r2=886940&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoTransport.cs (original) +++ qpid/trunk/qpid/dotnet/client-010/client/transport/network/io/IoTransport.cs Thu Dec 3 22:03:51 2009 @@ -1,143 +1,143 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ -using System; -using System.IO; -using System.Net.Sockets; -using org.apache.qpid.transport.util; - -namespace org.apache.qpid.transport.network.io -{ - /// - /// This class provides a socket based transport using sync io classes. - /// - /// The following params are configurable via JVM arguments - /// TCP_NO_DELAY - qpid.tcpNoDelay - /// SO_RCVBUF - qpid.readBufferSize - /// SO_SNDBUF - qpid.writeBufferSize - /// - public sealed class IoTransport : IIoTransport - { - // constants - private const int DEFAULT_READ_WRITE_BUFFER_SIZE = 64*1024; - private const int TIMEOUT = 60000; - private const int QUEUE_SIZE = 1000; - // props - private static readonly Logger log = Logger.get(typeof (IoTransport)); - private Stream m_stream; - private IoSender m_sender; - private Receiver> m_receiver; - private TcpClient m_socket; - private Connection m_con; - - public static Connection connect(String host, int port, ConnectionDelegate conndel) - { - IoTransport transport = new IoTransport(host, port, conndel); - return transport.Connection; - } - - public IoTransport(String host, int port, ConnectionDelegate conndel) - { - createSocket(host, port); - Sender = new IoSender(this, QUEUE_SIZE, TIMEOUT); - Receiver = new IoReceiver(Stream, Socket.ReceiveBufferSize * 2, TIMEOUT); - Assembler assembler = new Assembler(); - InputHandler inputHandler = new InputHandler(InputHandler.State.PROTO_HDR); - Connection = new Connection(assembler, new Disassembler(Sender, 64 * 1024 - 1), conndel); - // Input handler listen to Receiver events - Receiver.Received += inputHandler.On_ReceivedBuffer; - // Assembler listen to inputhandler events - inputHandler.ReceivedEvent += assembler.On_ReceivedEvent; - // Connection listen to asembler protocol event - Receiver.Closed += Connection.On_ReceivedClosed; - Receiver.Exception += Connection.On_ReceivedException; - inputHandler.HandlerClosed += Connection.On_ReceivedClosed; - inputHandler.ExceptionProcessing += Connection.On_ReceivedException; - assembler.HandlerClosed += Connection.On_ReceivedClosed; - assembler.ExceptionProcessing += Connection.On_ReceivedException; - assembler.ReceivedEvent += Connection.On_ReceivedEvent; - } - - public Connection Connection - { - get { return m_con; } - set { m_con = value; } - } - - public Receiver> Receiver - { - get { return m_receiver; } - set { m_receiver = value; } - } - - public IoSender Sender - { - get { return m_sender; } - set { m_sender = value; } - } - - - public Stream Stream - { - get { return m_stream; } - set { m_stream = value; } - } - - public TcpClient Socket - { - get { return m_socket; } - set { m_socket = value; } - } - - #region Private Support Functions - - private void createSocket(String host, int port) - { - try - { - TcpClient socket = new TcpClient(); - String noDelay = Environment.GetEnvironmentVariable("qpid.tcpNoDelay"); - String writeBufferSize = Environment.GetEnvironmentVariable("qpid.writeBufferSize"); - String readBufferSize = Environment.GetEnvironmentVariable("qpid.readBufferSize"); - socket.NoDelay = noDelay != null && bool.Parse(noDelay); - socket.ReceiveBufferSize = readBufferSize == null ? DEFAULT_READ_WRITE_BUFFER_SIZE : int.Parse(readBufferSize); - socket.SendBufferSize = writeBufferSize == null ? DEFAULT_READ_WRITE_BUFFER_SIZE : int.Parse(writeBufferSize); - - log.debug("NoDelay : {0}", socket.NoDelay); - log.debug("ReceiveBufferSize : {0}", socket.ReceiveBufferSize); - log.debug("SendBufferSize : {0}", socket.SendBufferSize); - log.debug("Openning connection with host : {0}; port: {1}", host, port); - - socket.Connect(host, port); - Socket = socket; - Stream = socket.GetStream(); - } - catch (SocketException e) - { - Console.WriteLine(e.StackTrace); - throw new TransportException("Error connecting to broker", e); - } - catch (IOException e) - { - throw new TransportException("Error connecting to broker", e); - } - } - - #endregion - } +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +using System; +using System.IO; +using System.Net.Sockets; +using org.apache.qpid.transport.util; + +namespace org.apache.qpid.transport.network.io +{ + /// + /// This class provides a socket based transport using sync io classes. + /// + /// The following params are configurable via JVM arguments + /// TCP_NO_DELAY - qpid.tcpNoDelay + /// SO_RCVBUF - qpid.readBufferSize + /// SO_SNDBUF - qpid.writeBufferSize + /// + public sealed class IoTransport : IIoTransport + { + // constants + private const int DEFAULT_READ_WRITE_BUFFER_SIZE = 64*1024; + private const int TIMEOUT = 60000; + private const int QUEUE_SIZE = 1000; + // props + private static readonly Logger log = Logger.get(typeof (IoTransport)); + private Stream m_stream; + private IoSender m_sender; + private Receiver> m_receiver; + private TcpClient m_socket; + private Connection m_con; + + public static Connection connect(String host, int port, ConnectionDelegate conndel) + { + IoTransport transport = new IoTransport(host, port, conndel); + return transport.Connection; + } + + public IoTransport(String host, int port, ConnectionDelegate conndel) + { + createSocket(host, port); + Sender = new IoSender(this, QUEUE_SIZE, TIMEOUT); + Receiver = new IoReceiver(Stream, Socket.ReceiveBufferSize * 2, TIMEOUT); + Assembler assembler = new Assembler(); + InputHandler inputHandler = new InputHandler(InputHandler.State.PROTO_HDR); + Connection = new Connection(assembler, new Disassembler(Sender, 64 * 1024 - 1), conndel); + // Input handler listen to Receiver events + Receiver.Received += inputHandler.On_ReceivedBuffer; + // Assembler listen to inputhandler events + inputHandler.ReceivedEvent += assembler.On_ReceivedEvent; + // Connection listen to asembler protocol event + Receiver.Closed += Connection.On_ReceivedClosed; + Receiver.Exception += Connection.On_ReceivedException; + inputHandler.HandlerClosed += Connection.On_ReceivedClosed; + inputHandler.ExceptionProcessing += Connection.On_ReceivedException; + assembler.HandlerClosed += Connection.On_ReceivedClosed; + assembler.ExceptionProcessing += Connection.On_ReceivedException; + assembler.ReceivedEvent += Connection.On_ReceivedEvent; + } + + public Connection Connection + { + get { return m_con; } + set { m_con = value; } + } + + public Receiver> Receiver + { + get { return m_receiver; } + set { m_receiver = value; } + } + + public IoSender Sender + { + get { return m_sender; } + set { m_sender = value; } + } + + + public Stream Stream + { + get { return m_stream; } + set { m_stream = value; } + } + + public TcpClient Socket + { + get { return m_socket; } + set { m_socket = value; } + } + + #region Private Support Functions + + private void createSocket(String host, int port) + { + try + { + TcpClient socket = new TcpClient(); + String noDelay = Environment.GetEnvironmentVariable("qpid.tcpNoDelay"); + String writeBufferSize = Environment.GetEnvironmentVariable("qpid.writeBufferSize"); + String readBufferSize = Environment.GetEnvironmentVariable("qpid.readBufferSize"); + socket.NoDelay = noDelay != null && bool.Parse(noDelay); + socket.ReceiveBufferSize = readBufferSize == null ? DEFAULT_READ_WRITE_BUFFER_SIZE : int.Parse(readBufferSize); + socket.SendBufferSize = writeBufferSize == null ? DEFAULT_READ_WRITE_BUFFER_SIZE : int.Parse(writeBufferSize); + + log.debug("NoDelay : {0}", socket.NoDelay); + log.debug("ReceiveBufferSize : {0}", socket.ReceiveBufferSize); + log.debug("SendBufferSize : {0}", socket.SendBufferSize); + log.debug("Openning connection with host : {0}; port: {1}", host, port); + + socket.Connect(host, port); + Socket = socket; + Stream = socket.GetStream(); + } + catch (SocketException e) + { + Console.WriteLine(e.StackTrace); + throw new TransportException("Error connecting to broker", e); + } + catch (IOException e) + { + throw new TransportException("Error connecting to broker", e); + } + } + + #endregion + } } \ No newline at end of file Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs?rev=886940&r1=886939&r2=886940&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs (original) +++ qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs Thu Dec 3 22:03:51 2009 @@ -1,218 +1,218 @@ -/* -* -* 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.qpid.transport.util -{ - public static class ByteEncoder - { - #region Endian conversion helper routines - /// - /// Returns the value encoded in Big Endian (PPC, XDR) format. - /// - /// Value to encode. - /// Big-endian encoded value. - public static Int32 GetBigEndian(Int32 value) - { - if (BitConverter.IsLittleEndian) - { - return swapByteOrder(value); - } - return value; - } - - /// - /// Returns the value encoded in Big Endian (PPC, XDR) format. - /// - /// Value to encode. - /// Big-endian encoded value. - public static UInt16 GetBigEndian(UInt16 value) - { - if (BitConverter.IsLittleEndian) - { - return swapByteOrder(value); - } - return value; - } - - /// - /// Returns the value encoded in Big Endian (PPC, XDR) format. - /// - /// Value to encode. - /// Big-endian encoded value. - public static UInt32 GetBigEndian(UInt32 value) - { - if (BitConverter.IsLittleEndian) - { - return swapByteOrder(value); - } - return value; - } - - /// - /// Returns the value encoded in Big Endian (PPC, XDR) format. - /// - /// Value to encode. - /// Big-endian encoded value. - public static long GetBigEndian(long value) - { - if (BitConverter.IsLittleEndian) - { - return swapByteOrder(value); - } - return value; - } - - public static double GetBigEndian(double value) - { - if (BitConverter.IsLittleEndian) - { - return swapByteOrder(value); - } - return value; - } - - /// - /// Returns the value encoded in Little Endian (x86, NDR) format. - /// - /// Value to encode. - /// Little-endian encoded value. - public static Int32 GetLittleEndian(Int32 value) - { - if (BitConverter.IsLittleEndian) - { - return value; - } - return swapByteOrder(value); - } - - /// - /// Returns the value encoded in Little Endian (x86, NDR) format. - /// - /// Value to encode. - /// Little-endian encoded value. - public static UInt32 GetLittleEndian(UInt32 value) - { - if (BitConverter.IsLittleEndian) - { - return value; - } - return swapByteOrder(value); - } - - /// - /// Returns the value encoded in Little Endian (x86, NDR) format. - /// - /// Value to encode. - /// Little-endian encoded value. - public static UInt16 GetLittleEndian(UInt16 value) - { - if (BitConverter.IsLittleEndian) - { - return value; - } - return swapByteOrder(value); - } - - /// - /// Returns the value encoded in Little Endian (x86, NDR) format. - /// - /// Value to encode. - /// Little-endian encoded value. - public static long GetLittleEndian(long value) - { - if (BitConverter.IsLittleEndian) - { - return value; - } - return swapByteOrder(value); - } - - public static double GetLittleEndian(double value) - { - if (BitConverter.IsLittleEndian) - { - return value; - } - return swapByteOrder(value); - } - - /// - /// Swaps the Byte order of an . - /// - /// to swap the bytes of. - /// Byte order swapped . - private static Int32 swapByteOrder(Int32 value) - { - Int32 swapped = (Int32)((0x000000FF) & (value >> 24) - | (0x0000FF00) & (value >> 8) - | (0x00FF0000) & (value << 8) - | (0xFF000000) & (value << 24)); - return swapped; - } - - /// - /// Swaps the byte order of a . - /// - /// to swap the bytes of. - /// Byte order swapped . - private static UInt16 swapByteOrder(UInt16 value) - { - return (UInt16)((0x00FF & (value >> 8)) - | (0xFF00 & (value << 8))); - } - - /// - /// Swaps the byte order of a . - /// - /// to swap the bytes of. - /// Byte order swapped . - private static UInt32 swapByteOrder(UInt32 value) - { - UInt32 swapped = ((0x000000FF) & (value >> 24) - | (0x0000FF00) & (value >> 8) - | (0x00FF0000) & (value << 8) - | (0xFF000000) & (value << 24)); - return swapped; - } - - /// - /// Swaps the byte order of a (double precision IEEE 754) - /// - /// to swap. - /// Byte order swapped value. - private static long swapByteOrder(long value) - { - Byte[] buffer = BitConverter.GetBytes(value); - Array.Reverse(buffer, 0, buffer.Length); - return BitConverter.ToInt64(buffer, 0); - } - - private static double swapByteOrder(double value) - { - Byte[] buffer = BitConverter.GetBytes(value); - Array.Reverse(buffer, 0, buffer.Length); - return BitConverter.ToDouble(buffer,0) ; - } - #endregion - } - -} +/* +* +* 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.qpid.transport.util +{ + public static class ByteEncoder + { + #region Endian conversion helper routines + /// + /// Returns the value encoded in Big Endian (PPC, XDR) format. + /// + /// Value to encode. + /// Big-endian encoded value. + public static Int32 GetBigEndian(Int32 value) + { + if (BitConverter.IsLittleEndian) + { + return swapByteOrder(value); + } + return value; + } + + /// + /// Returns the value encoded in Big Endian (PPC, XDR) format. + /// + /// Value to encode. + /// Big-endian encoded value. + public static UInt16 GetBigEndian(UInt16 value) + { + if (BitConverter.IsLittleEndian) + { + return swapByteOrder(value); + } + return value; + } + + /// + /// Returns the value encoded in Big Endian (PPC, XDR) format. + /// + /// Value to encode. + /// Big-endian encoded value. + public static UInt32 GetBigEndian(UInt32 value) + { + if (BitConverter.IsLittleEndian) + { + return swapByteOrder(value); + } + return value; + } + + /// + /// Returns the value encoded in Big Endian (PPC, XDR) format. + /// + /// Value to encode. + /// Big-endian encoded value. + public static long GetBigEndian(long value) + { + if (BitConverter.IsLittleEndian) + { + return swapByteOrder(value); + } + return value; + } + + public static double GetBigEndian(double value) + { + if (BitConverter.IsLittleEndian) + { + return swapByteOrder(value); + } + return value; + } + + /// + /// Returns the value encoded in Little Endian (x86, NDR) format. + /// + /// Value to encode. + /// Little-endian encoded value. + public static Int32 GetLittleEndian(Int32 value) + { + if (BitConverter.IsLittleEndian) + { + return value; + } + return swapByteOrder(value); + } + + /// + /// Returns the value encoded in Little Endian (x86, NDR) format. + /// + /// Value to encode. + /// Little-endian encoded value. + public static UInt32 GetLittleEndian(UInt32 value) + { + if (BitConverter.IsLittleEndian) + { + return value; + } + return swapByteOrder(value); + } + + /// + /// Returns the value encoded in Little Endian (x86, NDR) format. + /// + /// Value to encode. + /// Little-endian encoded value. + public static UInt16 GetLittleEndian(UInt16 value) + { + if (BitConverter.IsLittleEndian) + { + return value; + } + return swapByteOrder(value); + } + + /// + /// Returns the value encoded in Little Endian (x86, NDR) format. + /// + /// Value to encode. + /// Little-endian encoded value. + public static long GetLittleEndian(long value) + { + if (BitConverter.IsLittleEndian) + { + return value; + } + return swapByteOrder(value); + } + + public static double GetLittleEndian(double value) + { + if (BitConverter.IsLittleEndian) + { + return value; + } + return swapByteOrder(value); + } + + /// + /// Swaps the Byte order of an . + /// + /// to swap the bytes of. + /// Byte order swapped . + private static Int32 swapByteOrder(Int32 value) + { + Int32 swapped = (Int32)((0x000000FF) & (value >> 24) + | (0x0000FF00) & (value >> 8) + | (0x00FF0000) & (value << 8) + | (0xFF000000) & (value << 24)); + return swapped; + } + + /// + /// Swaps the byte order of a . + /// + /// to swap the bytes of. + /// Byte order swapped . + private static UInt16 swapByteOrder(UInt16 value) + { + return (UInt16)((0x00FF & (value >> 8)) + | (0xFF00 & (value << 8))); + } + + /// + /// Swaps the byte order of a . + /// + /// to swap the bytes of. + /// Byte order swapped . + private static UInt32 swapByteOrder(UInt32 value) + { + UInt32 swapped = ((0x000000FF) & (value >> 24) + | (0x0000FF00) & (value >> 8) + | (0x00FF0000) & (value << 8) + | (0xFF000000) & (value << 24)); + return swapped; + } + + /// + /// Swaps the byte order of a (double precision IEEE 754) + /// + /// to swap. + /// Byte order swapped value. + private static long swapByteOrder(long value) + { + Byte[] buffer = BitConverter.GetBytes(value); + Array.Reverse(buffer, 0, buffer.Length); + return BitConverter.ToInt64(buffer, 0); + } + + private static double swapByteOrder(double value) + { + Byte[] buffer = BitConverter.GetBytes(value); + Array.Reverse(buffer, 0, buffer.Length); + return BitConverter.ToDouble(buffer,0) ; + } + #endregion + } + +} Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs?rev=886940&r1=886939&r2=886940&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs (original) +++ qpid/trunk/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs Thu Dec 3 22:03:51 2009 @@ -1,132 +1,132 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -* -*/ - -using System; -using System.Threading; - -namespace common.org.apache.qpid.transport.util -{ - public class CircularBuffer - { - private readonly T[] buffer; - private Int32 nrp, nwp; - private readonly Int32 len; - private Int32 countValue; - private readonly Int32 add; - - - /// - /// Constructor creates N=len element - /// Circular Buffer that olds MemoryStream - /// - public CircularBuffer(Int32 len) - { - buffer = new T[len]; - this.len = len; - add = 1 - len; - nrp = 0; - nwp = 0; - countValue = 0; - } - - - public void Enqueue(T t) - { - lock (this) - { - if (countValue >= (len - 1)) - { - // wait for room to be available - Monitor.Wait(this); - } - bool notifyDequeue = countValue <= 0; - load(t); - if (notifyDequeue) //notifyDequeue) - { - Monitor.PulseAll(this); - } - } - } - - - public T Dequeue() - { - lock (this) - { - if (countValue <= 0) - { - Monitor.Wait(this); - } - bool notifyEnqueue = countValue >= (len - 1); - T temp = get(); - if (notifyEnqueue) //notifyEnqueue) - { - Monitor.PulseAll(this); - } - return temp; - } - } - - public void close() - { - nrp = 0; - nwp = 0; - countValue = 0; - Array.Clear(buffer, 0, len); - lock (this) - { - Monitor.PulseAll(this); - } - } - - #region Private Support Functions - - private void load(T t) - { - Int32 i = nwp; - buffer[i] = t; - i += add; - if (i < 0) i += len; - nwp = i; - updateCount(); - } - - private void updateCount() - { - countValue = nwp - nrp; - if (countValue <= 0 ) - countValue += len; // modulo buffer size - } - - private T get() - { - Int32 i = nrp; - T temp = buffer[i]; - i += add; - if (i < 0) i += len; - nrp = i; - countValue--; - return (temp); - } - - #endregion - } -} +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ + +using System; +using System.Threading; + +namespace common.org.apache.qpid.transport.util +{ + public class CircularBuffer + { + private readonly T[] buffer; + private Int32 nrp, nwp; + private readonly Int32 len; + private Int32 countValue; + private readonly Int32 add; + + + /// + /// Constructor creates N=len element + /// Circular Buffer that olds MemoryStream + /// + public CircularBuffer(Int32 len) + { + buffer = new T[len]; + this.len = len; + add = 1 - len; + nrp = 0; + nwp = 0; + countValue = 0; + } + + + public void Enqueue(T t) + { + lock (this) + { + if (countValue >= (len - 1)) + { + // wait for room to be available + Monitor.Wait(this); + } + bool notifyDequeue = countValue <= 0; + load(t); + if (notifyDequeue) //notifyDequeue) + { + Monitor.PulseAll(this); + } + } + } + + + public T Dequeue() + { + lock (this) + { + if (countValue <= 0) + { + Monitor.Wait(this); + } + bool notifyEnqueue = countValue >= (len - 1); + T temp = get(); + if (notifyEnqueue) //notifyEnqueue) + { + Monitor.PulseAll(this); + } + return temp; + } + } + + public void close() + { + nrp = 0; + nwp = 0; + countValue = 0; + Array.Clear(buffer, 0, len); + lock (this) + { + Monitor.PulseAll(this); + } + } + + #region Private Support Functions + + private void load(T t) + { + Int32 i = nwp; + buffer[i] = t; + i += add; + if (i < 0) i += len; + nwp = i; + updateCount(); + } + + private void updateCount() + { + countValue = nwp - nrp; + if (countValue <= 0 ) + countValue += len; // modulo buffer size + } + + private T get() + { + Int32 i = nrp; + T temp = buffer[i]; + i += add; + if (i < 0) i += len; + nrp = i; + countValue--; + return (temp); + } + + #endregion + } +} Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/util/Functions.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/util/Functions.cs?rev=886940&r1=886939&r2=886940&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/client-010/client/transport/util/Functions.cs (original) +++ qpid/trunk/qpid/dotnet/client-010/client/transport/util/Functions.cs Thu Dec 3 22:03:51 2009 @@ -1,41 +1,41 @@ -/* -* -* 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. -* -*/ - -namespace org.apache.qpid.transport.util -{ - - /// - /// Functions - /// - - public class Functions - { - public static sbyte lsb(int i) - { - return (sbyte) (0xFF & i); - } - - public static sbyte lsb(long l) - { - return (sbyte) (0xFF & l); - } - } +/* +* +* 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. +* +*/ + +namespace org.apache.qpid.transport.util +{ + + /// + /// Functions + /// + + public class Functions + { + public static sbyte lsb(int i) + { + return (sbyte) (0xFF & i); + } + + public static sbyte lsb(long l) + { + return (sbyte) (0xFF & l); + } + } } \ No newline at end of file Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/util/Logger.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/util/Logger.cs?rev=886940&r1=886939&r2=886940&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/client-010/client/transport/util/Logger.cs (original) +++ qpid/trunk/qpid/dotnet/client-010/client/transport/util/Logger.cs Thu Dec 3 22:03:51 2009 @@ -1,114 +1,114 @@ -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -* -*/ -using System; -using log4net; - -namespace org.apache.qpid.transport.util -{ - - /// Logger - /// - /// - - public sealed class Logger - { - private readonly ILog log; - - public static Logger get(Type type) - { - return new Logger(LogManager.GetLogger(type)); - } - - private Logger(ILog log) - { - this.log = log; - } - - public bool isDebugEnabled() - { - return log.IsDebugEnabled; - } - - public void debug(String message, params Object[] args) - { - if (log.IsDebugEnabled) - { - log.Debug(String.Format(message, args)); - } - } - - public void debug(Exception t, String message, params Object[] args) - { - if (log.IsDebugEnabled) - { - log.Debug(String.Format(message, args), t); - } - } - - public void error(String message, params Object[] args) - { - if (log.IsErrorEnabled) - { - log.Error(String.Format(message, args)); - } - } - - public void error(Exception t, String message, params Object[] args) - { - if (log.IsErrorEnabled) - { - log.Error(String.Format(message, args), t); - } - } - - public void warn(String message, params Object[] args) - { - if (log.IsWarnEnabled) - { - log.Warn(String.Format(message, args)); - } - } - - public void warn(Exception t, String message, params Object[] args) - { - if (log.IsWarnEnabled) - { - log.Warn(String.Format(message, args), t); - } - } - - public void info(String message, params Object[] args) - { - if (log.IsInfoEnabled) - { - log.Info(String.Format(message, args)); - } - } - - public void info(Exception t, String message, params Object[] args) - { - if (log.IsInfoEnabled) - { - log.Info(String.Format(message, args), t); - } - } - } +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ +using System; +using log4net; + +namespace org.apache.qpid.transport.util +{ + + /// Logger + /// + /// + + public sealed class Logger + { + private readonly ILog log; + + public static Logger get(Type type) + { + return new Logger(LogManager.GetLogger(type)); + } + + private Logger(ILog log) + { + this.log = log; + } + + public bool isDebugEnabled() + { + return log.IsDebugEnabled; + } + + public void debug(String message, params Object[] args) + { + if (log.IsDebugEnabled) + { + log.Debug(String.Format(message, args)); + } + } + + public void debug(Exception t, String message, params Object[] args) + { + if (log.IsDebugEnabled) + { + log.Debug(String.Format(message, args), t); + } + } + + public void error(String message, params Object[] args) + { + if (log.IsErrorEnabled) + { + log.Error(String.Format(message, args)); + } + } + + public void error(Exception t, String message, params Object[] args) + { + if (log.IsErrorEnabled) + { + log.Error(String.Format(message, args), t); + } + } + + public void warn(String message, params Object[] args) + { + if (log.IsWarnEnabled) + { + log.Warn(String.Format(message, args)); + } + } + + public void warn(Exception t, String message, params Object[] args) + { + if (log.IsWarnEnabled) + { + log.Warn(String.Format(message, args), t); + } + } + + public void info(String message, params Object[] args) + { + if (log.IsInfoEnabled) + { + log.Info(String.Format(message, args)); + } + } + + public void info(Exception t, String message, params Object[] args) + { + if (log.IsInfoEnabled) + { + log.Info(String.Format(message, args), t); + } + } + } } \ No newline at end of file Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/util/Serial.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/util/Serial.cs?rev=886940&r1=886939&r2=886940&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/client-010/client/transport/util/Serial.cs (original) +++ qpid/trunk/qpid/dotnet/client-010/client/transport/util/Serial.cs Thu Dec 3 22:03:51 2009 @@ -1,94 +1,94 @@ -/* -* -* 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. -* -*/ -namespace org.apache.qpid.transport.util -{ - /// - /// This class provides basic serial number comparisons as defined in - /// RFC 1982. - /// - public class Serial - { - /// - /// - ///Compares two numbers using serial arithmetic. - /// - /// param s1 the first serial number - /// param s2 the second serial number - /// - /// return a negative integer, zero, or a positive integer as the - /// first argument is less than, equal to, or greater than the - /// second - /// - public static int compare(int s1, int s2) - { - return s1 - s2; - } - - public static bool lt(int s1, int s2) - { - return compare(s1, s2) < 0; - } - - public static bool le(int s1, int s2) - { - return compare(s1, s2) <= 0; - } - - public static bool gt(int s1, int s2) - { - return compare(s1, s2) > 0; - } - - public static bool ge(int s1, int s2) - { - return compare(s1, s2) >= 0; - } - - public static bool eq(int s1, int s2) - { - return s1 == s2; - } - - public static int min(int s1, int s2) - { - if (lt(s1, s2)) - { - return s1; - } - else - { - return s2; - } - } - - public static int max(int s1, int s2) - { - if (gt(s1, s2)) - { - return s1; - } - else - { - return s2; - } - } - } +/* +* +* 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. +* +*/ +namespace org.apache.qpid.transport.util +{ + /// + /// This class provides basic serial number comparisons as defined in + /// RFC 1982. + /// + public class Serial + { + /// + /// + ///Compares two numbers using serial arithmetic. + /// + /// param s1 the first serial number + /// param s2 the second serial number + /// + /// return a negative integer, zero, or a positive integer as the + /// first argument is less than, equal to, or greater than the + /// second + /// + public static int compare(int s1, int s2) + { + return s1 - s2; + } + + public static bool lt(int s1, int s2) + { + return compare(s1, s2) < 0; + } + + public static bool le(int s1, int s2) + { + return compare(s1, s2) <= 0; + } + + public static bool gt(int s1, int s2) + { + return compare(s1, s2) > 0; + } + + public static bool ge(int s1, int s2) + { + return compare(s1, s2) >= 0; + } + + public static bool eq(int s1, int s2) + { + return s1 == s2; + } + + public static int min(int s1, int s2) + { + if (lt(s1, s2)) + { + return s1; + } + else + { + return s2; + } + } + + public static int max(int s1, int s2) + { + if (gt(s1, s2)) + { + return s1; + } + else + { + return s2; + } + } + } } \ No newline at end of file Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/util/UUID.cs URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/util/UUID.cs?rev=886940&r1=886939&r2=886940&view=diff ============================================================================== --- qpid/trunk/qpid/dotnet/client-010/client/transport/util/UUID.cs (original) +++ qpid/trunk/qpid/dotnet/client-010/client/transport/util/UUID.cs Thu Dec 3 22:03:51 2009 @@ -1,123 +1,123 @@ -/* -* -* 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.qpid.transport.util -{ - public class UUID - { - private long _mostSigBits; - - private long _leastSigBits; - private static readonly Random _random = new Random(); - - - public UUID(long mostSigBits, long leastSigBits) - { - _mostSigBits = mostSigBits; - _leastSigBits = leastSigBits; - } - - public long MostSignificantBits - { - get { return _mostSigBits; } - set { _mostSigBits = value; } - } - - public long LeastSignificantBits - { - get { return _leastSigBits; } - set { _leastSigBits = value; } - } - - private UUID(byte[] r) - { - MostSignificantBits = 0; - LeastSignificantBits = 0; - for (int i = 0; i < 8; i++) - MostSignificantBits = (MostSignificantBits << 8) | (r[i] & 0xff); - for (int i = 8; i < 16; i++) - LeastSignificantBits = (LeastSignificantBits << 8) | (r[i] & 0xff); - } - - public static UUID randomUUID() - { - byte[] randomBytes = new byte[16]; - _random.NextBytes(randomBytes); - randomBytes[6] &= 0x0f; - randomBytes[6] |= 0x40; - randomBytes[8] &= 0x3f; - randomBytes[8] |= 0x80; - return new UUID(randomBytes); - } - - public override String ToString() - { - return (digits(_mostSigBits >> 32, 8) + "-" + - digits(_mostSigBits >> 16, 4) + "-" + - digits(_mostSigBits, 4) + "-" + - digits(_leastSigBits >> 48, 4) + "-" + - digits(_leastSigBits, 12)); - } - - private static String digits(long val, int digits) - { - long hi = 1L << (digits * 4); - return Convert.ToString((hi | (val & (hi - 1))), 16); - } - - #region equality - public bool Equals(UUID other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - return other._mostSigBits == _mostSigBits && other._leastSigBits == _leastSigBits; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != typeof (UUID)) return false; - return Equals((UUID) obj); - } - - public override int GetHashCode() - { - unchecked - { - return (_mostSigBits.GetHashCode()*397) ^ _leastSigBits.GetHashCode(); - } - } - - public static bool operator ==(UUID left, UUID right) - { - return Equals(left, right); - } - - public static bool operator !=(UUID left, UUID right) - { - return !Equals(left, right); - } - #endregion - } -} +/* +* +* 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.qpid.transport.util +{ + public class UUID + { + private long _mostSigBits; + + private long _leastSigBits; + private static readonly Random _random = new Random(); + + + public UUID(long mostSigBits, long leastSigBits) + { + _mostSigBits = mostSigBits; + _leastSigBits = leastSigBits; + } + + public long MostSignificantBits + { + get { return _mostSigBits; } + set { _mostSigBits = value; } + } + + public long LeastSignificantBits + { + get { return _leastSigBits; } + set { _leastSigBits = value; } + } + + private UUID(byte[] r) + { + MostSignificantBits = 0; + LeastSignificantBits = 0; + for (int i = 0; i < 8; i++) + MostSignificantBits = (MostSignificantBits << 8) | (r[i] & 0xff); + for (int i = 8; i < 16; i++) + LeastSignificantBits = (LeastSignificantBits << 8) | (r[i] & 0xff); + } + + public static UUID randomUUID() + { + byte[] randomBytes = new byte[16]; + _random.NextBytes(randomBytes); + randomBytes[6] &= 0x0f; + randomBytes[6] |= 0x40; + randomBytes[8] &= 0x3f; + randomBytes[8] |= 0x80; + return new UUID(randomBytes); + } + + public override String ToString() + { + return (digits(_mostSigBits >> 32, 8) + "-" + + digits(_mostSigBits >> 16, 4) + "-" + + digits(_mostSigBits, 4) + "-" + + digits(_leastSigBits >> 48, 4) + "-" + + digits(_leastSigBits, 12)); + } + + private static String digits(long val, int digits) + { + long hi = 1L << (digits * 4); + return Convert.ToString((hi | (val & (hi - 1))), 16); + } + + #region equality + public bool Equals(UUID other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return other._mostSigBits == _mostSigBits && other._leastSigBits == _leastSigBits; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (UUID)) return false; + return Equals((UUID) obj); + } + + public override int GetHashCode() + { + unchecked + { + return (_mostSigBits.GetHashCode()*397) ^ _leastSigBits.GetHashCode(); + } + } + + public static bool operator ==(UUID left, UUID right) + { + return Equals(left, right); + } + + public static bool operator !=(UUID left, UUID right) + { + return !Equals(left, right); + } + #endregion + } +} --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscribe@qpid.apache.org