You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2008/04/29 22:52:37 UTC

svn commit: r652104 [12/29] - in /activemq/activemq-cpp/trunk: ./ m4/ src/examples/ src/examples/consumers/ src/main/ src/main/decaf/ src/main/decaf/internal/ src/main/decaf/internal/net/ src/main/decaf/internal/nio/ src/main/decaf/internal/util/ src/m...

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/BindException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/BindException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/BindException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/BindException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_NET_BINDEXCEPTION_H_
+#define _DECAF_NET_BINDEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/net/SocketException.h>
+
+namespace decaf{
+namespace net{
+
+    class DECAF_API BindException : public SocketException {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        BindException() throw() {}
+
+        /**
+         * Conversion Constructor from some other Exception
+         * @param An exception that should become this type of Exception
+         */
+        BindException( const Exception& ex ) throw()
+        : SocketException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         */
+        BindException( const BindException& ex ) throw()
+        : SocketException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param message to report
+         * @param list of primitives that are formatted into the message
+         */
+        BindException( const char* file, const int lineNumber,
+                            const char* msg, ... ) throw ()
+        : SocketException()
+        {
+            va_list vargs ;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         */
+        virtual BindException* clone() const {
+            return new BindException( *this );
+        }
+
+        /**
+         * Destructor
+         */
+        virtual ~BindException() throw() {}
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_BINDEXCEPTION_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/BufferedSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/BufferedSocket.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/BufferedSocket.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/BufferedSocket.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +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.
+ */
+
+#include "BufferedSocket.h"
+
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedSocket::BufferedSocket( Socket* socket,
+                                int inputBufferSize,
+                                int outputBufferSize,
+                                bool own ) :
+    socket( NULL ),
+    own( false ),
+    inputStream( NULL ),
+    outputStream( NULL ),
+    inputBufferSize( 0 ),
+    outputBufferSize( 0 ) {
+
+    if( inputBufferSize < 0 || outputBufferSize < 0 ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__,
+            "BufferedSocket::BufferedSocket - buffer sizes must be >=0! "
+            "Given input buffer size: %d, Given output buffer size: %d",
+            inputBufferSize,
+            outputBufferSize );
+    }
+
+    if( socket == NULL ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__,
+            "BufferedSocket::BufferedSocket - Constructed with NULL Socket");
+    }
+
+    this->socket = socket;
+    this->inputBufferSize = inputBufferSize;
+    this->outputBufferSize = outputBufferSize;
+    this->own = own;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedSocket::~BufferedSocket() {
+    try {
+
+        close();
+
+        // delete the streams first as they may try and close or flush the
+        // contained streams when destoryed.
+        if( outputStream != NULL ) {
+            delete outputStream;
+            outputStream = NULL;
+        }
+
+        if( inputStream != NULL ){
+            delete inputStream;
+            inputStream = NULL;
+        }
+
+        // if we own it, delete it.
+        if( own ) {
+            delete socket;
+        }
+        socket = NULL;
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedSocket::connect( const char* host, int port )
+    throw( SocketException ) {
+
+    try {
+
+        if( socket->isConnected() ) {
+            throw SocketException( __FILE__, __LINE__,
+                 "BufferedSocket::connect() - socket already connected" );
+        }
+
+        // Connect the socket.
+        socket->connect( host, port );
+
+        // Now create the buffered streams that wrap around the socket.
+        inputStream = new BufferedInputStream(
+            socket->getInputStream(), (std::size_t)inputBufferSize );
+        outputStream = new BufferedOutputStream(
+            socket->getOutputStream(), (std::size_t)outputBufferSize );
+    }
+    DECAF_CATCH_RETHROW( SocketException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, SocketException )
+    DECAF_CATCHALL_THROW( SocketException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedSocket::close() throw( lang::Exception ) {
+
+    try {
+
+        // We close and flush streams here but do not delete as there may be
+        // others classes ( and threads ) using them and we don't want to pull
+        // the rug out from under them, we delete the streams in the dtor and
+        // and that point its the users responsibility to ensure that they have
+        // removed all referenced to the streams provided by Sokcet.
+
+        if( outputStream != NULL ) {
+            outputStream->close();
+        }
+
+        if( inputStream != NULL ){
+            inputStream->close();
+        }
+
+        if( socket != NULL ){
+            // Close the socket
+            try{
+                socket->close();
+            } catch( lang::Exception& ex ){ /* Absorb */ }
+        }
+    }
+    DECAF_CATCH_RETHROW( SocketException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, SocketException )
+    DECAF_CATCHALL_THROW( SocketException )
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/BufferedSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/BufferedSocket.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/BufferedSocket.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/BufferedSocket.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,246 @@
+/*
+ * 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.
+ */
+#ifndef _DECAF_NET_BUFFEREDSOCKET_H_
+#define _DECAF_NET_BUFFEREDSOCKET_H_
+
+#include <decaf/net/Socket.h>
+#include <decaf/net/SocketException.h>
+#include <decaf/io/BufferedInputStream.h>
+#include <decaf/io/BufferedOutputStream.h>
+
+namespace decaf{
+namespace net{
+
+    /**
+     * Buffered Socket class that wraps a <code>Socket</code> derived
+     * object and provides Buffered input and Output Streams to improce
+     * the efficiency of the reads and writes.
+     */
+    class DECAF_API BufferedSocket : public Socket
+    {
+    private:
+
+        // Socket that this class wraps to provide buffering
+        Socket* socket;
+
+        // Indicates if the lifetime of the Socket is controlled by this
+        // class.  If true Socket is deleted at destruction.
+        bool own;
+
+        // Buffered Input stream to wrap the Socket input stream
+        io::BufferedInputStream* inputStream;
+
+        // Buffered Output stream to wrap the Socket input stream
+        io::BufferedOutputStream* outputStream;
+
+        // Sizes for the Buffered Streams
+        int inputBufferSize;
+        int outputBufferSize;
+
+    public:
+
+        /**
+         * Constructs a new Buffered socket object
+         * @param socket the socket to buffer
+         * @param inputBufferSize size of the input buffer
+         * @param outputBufferSize size of the output buffer
+         * @param own does this object own the passed socket
+         */
+        BufferedSocket( Socket* socket,
+                        int inputBufferSize = 1000,
+                        int outputBufferSize = 1000,
+                        bool own = true );
+
+        virtual ~BufferedSocket();
+
+        /**
+         * Connects to the specified destination. Closes this socket if
+         * connected to another destination.
+         * @param host The host of the server to connect to.
+         * @param port The port of the server to connect to.
+         * @throws IOException Thrown if a failure occurred in the connect.
+         */
+        virtual void connect( const char* host, int port )
+            throw( SocketException );
+
+        /**
+         * Closes this object and deallocates the appropriate resources.
+         * @throws CMSException
+         */
+        virtual void close() throw( lang::Exception );
+
+        /**
+         * Indicates whether or not this socket is connected to a destination.
+         * @return true if connected
+         */
+        virtual bool isConnected() const{
+            if( socket == NULL ){
+                return false;
+            }
+
+            return socket->isConnected();
+        }
+
+        /**
+         * Gets the InputStream for this socket.
+         * @return The InputStream for this socket. NULL if not connected.
+         */
+        virtual io::InputStream* getInputStream(){
+            return inputStream;
+        }
+
+        /**
+         * Gets the OutputStream for this socket.
+         * @return the OutputStream for this socket.  NULL if not connected.
+         */
+        virtual io::OutputStream* getOutputStream(){
+            return outputStream;
+        }
+
+        /**
+         * Gets the linger time.
+         * @return The linger time in seconds.
+         * @throws SocketException if the operation fails.
+         */
+        virtual int getSoLinger() const throw( SocketException ){
+            checkSocket();
+            return socket->getSoLinger();
+        }
+
+        /**
+         * Sets the linger time.
+         * @param linger The linger time in seconds.  If 0, linger is off.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setSoLinger( int linger ) throw( SocketException ){
+            checkSocket();
+            socket->setSoLinger( linger );
+        }
+
+        /**
+         * Gets the keep alive flag.
+         * @return True if keep alive is enabled.
+         * @throws SocketException if the operation fails.
+         */
+        virtual bool getKeepAlive() const throw( SocketException ){
+            checkSocket();
+            return socket->getKeepAlive();
+        }
+
+        /**
+         * Enables/disables the keep alive flag.
+         * @param keepAlive If true, enables the flag.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setKeepAlive( bool keepAlive ) throw( SocketException ){
+            checkSocket();
+            socket->setKeepAlive( keepAlive );
+        }
+
+        /**
+         * Gets the receive buffer size.
+         * @return the receive buffer size in bytes.
+         * @throws SocketException if the operation fails.
+         */
+        virtual int getReceiveBufferSize() const throw( SocketException ){
+            checkSocket();
+            return socket->getReceiveBufferSize();
+        }
+
+        /**
+         * Sets the recieve buffer size.
+         * @param size Number of bytes to set the receive buffer to.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setReceiveBufferSize( int size ) throw( SocketException ){
+            checkSocket();
+            socket->setReceiveBufferSize( size );
+        }
+
+        /**
+         * Gets the reuse address flag.
+         * @return True if the address can be reused.
+         * @throws SocketException if the operation fails.
+         */
+        virtual bool getReuseAddress() const throw( SocketException ){
+            checkSocket();
+            return socket->getReuseAddress();
+        }
+
+        /**
+         * Sets the reuse address flag.
+         * @param reuse If true, sets the flag.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setReuseAddress( bool reuse ) throw( SocketException ){
+            checkSocket();
+            socket->setReuseAddress( reuse );
+        }
+
+        /**
+         * Gets the send buffer size.
+         * @return the size in bytes of the send buffer.
+         * @throws SocketException if the operation fails.
+         */
+        virtual int getSendBufferSize() const throw( SocketException ){
+            checkSocket();
+            return socket->getSendBufferSize();
+        }
+
+        /**
+         * Sets the send buffer size.
+         * @param size The number of bytes to set the send buffer to.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setSendBufferSize( int size ) throw( SocketException ){
+            checkSocket();
+            socket->setSendBufferSize( size );
+        }
+
+        /**
+         * Gets the timeout for socket operations.
+         * @return The timeout in milliseconds for socket operations.
+         * @throws SocketException Thrown if unable to retrieve the information.
+         */
+        virtual int getSoTimeout() const throw( SocketException ){
+            checkSocket();
+            return socket->getSoTimeout();
+        }
+
+        /**
+         * Sets the timeout for socket operations.
+         * @param timeout The timeout in milliseconds for socket operations.<p>
+         * @throws SocketException Thrown if unable to set the information.
+         */
+        virtual void setSoTimeout( int timeout ) throw( SocketException ){
+            checkSocket();
+            socket->setSoTimeout( timeout );
+        }
+
+    private:
+
+        void checkSocket() const throw ( SocketException ) {
+            if( socket == NULL ) {
+                throw SocketException( __FILE__, __LINE__, "socket is NULL" );
+            }
+        }
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_BUFFEREDSOCKET_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/ConnectException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/ConnectException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/ConnectException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/ConnectException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_NET_CONNECTEXCEPTION_H_
+#define _DECAF_NET_CONNECTEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/net/SocketException.h>
+
+namespace decaf{
+namespace net{
+
+    class DECAF_API ConnectException : public SocketException {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        ConnectException() throw() {}
+
+        /**
+         * Conversion Constructor from some other Exception
+         * @param An exception that should become this type of Exception
+         */
+        ConnectException( const Exception& ex ) throw()
+        : SocketException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         */
+        ConnectException( const ConnectException& ex ) throw()
+        : SocketException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param message to report
+         * @param list of primitives that are formatted into the message
+         */
+        ConnectException( const char* file, const int lineNumber,
+                            const char* msg, ... ) throw ()
+        : SocketException()
+        {
+            va_list vargs ;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         */
+        virtual ConnectException* clone() const {
+            return new ConnectException( *this );
+        }
+
+        /**
+         * Destructor
+         */
+        virtual ~ConnectException() throw() {}
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_CONNECTEXCEPTION_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/HttpRetryException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/HttpRetryException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/HttpRetryException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/HttpRetryException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_NET_HTTPRETRYEXCEPTION_H_
+#define _DECAF_NET_HTTPRETRYEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/IOException.h>
+
+namespace decaf{
+namespace net{
+
+    class DECAF_API HttpRetryException : public io::IOException {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        HttpRetryException() throw() {}
+
+        /**
+         * Conversion Constructor from some other Exception
+         * @param An exception that should become this type of Exception
+         */
+        HttpRetryException( const Exception& ex ) throw()
+        : io::IOException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         */
+        HttpRetryException( const HttpRetryException& ex ) throw()
+        : io::IOException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param message to report
+         * @param list of primitives that are formatted into the message
+         */
+        HttpRetryException( const char* file, const int lineNumber,
+                            const char* msg, ... ) throw ()
+        : io::IOException()
+        {
+            va_list vargs ;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         */
+        virtual HttpRetryException* clone() const {
+            return new HttpRetryException( *this );
+        }
+
+        /**
+         * Destructor
+         */
+        virtual ~HttpRetryException() throw() {}
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_HTTPRETRYEXCEPTION_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/MalformedURLException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/MalformedURLException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/MalformedURLException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/MalformedURLException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_NET_MALFORMEDURLEXCEPTION_H_
+#define _DECAF_NET_MALFORMEDURLEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/IOException.h>
+
+namespace decaf{
+namespace net{
+
+    class DECAF_API MalformedURLException  : public io::IOException {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        MalformedURLException() throw() {}
+
+        /**
+         * Conversion Constructor from some other Exception
+         * @param An exception that should become this type of Exception
+         */
+        MalformedURLException( const Exception& ex ) throw()
+        : io::IOException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         */
+        MalformedURLException( const MalformedURLException& ex ) throw()
+        : io::IOException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param message to report
+         * @param list of primitives that are formatted into the message
+         */
+        MalformedURLException( const char* file, const int lineNumber,
+                               const char* msg, ... ) throw ()
+        : io::IOException()
+        {
+            va_list vargs ;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         */
+        virtual MalformedURLException* clone() const {
+            return new MalformedURLException( *this );
+        }
+
+        /**
+         * Destructor
+         */
+        virtual ~MalformedURLException() throw() {}
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_MALFORMEDURLEXCEPTION_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/NoRouteToHostException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/NoRouteToHostException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/NoRouteToHostException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/NoRouteToHostException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_NET_NOROUTETOHOSTEXCEPTION_H_
+#define _DECAF_NET_NOROUTETOHOSTEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/net/SocketException.h>
+
+namespace decaf{
+namespace net{
+
+    class DECAF_API NoRouteToHostException : public SocketException {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        NoRouteToHostException() throw() {}
+
+        /**
+         * Conversion Constructor from some other Exception
+         * @param An exception that should become this type of Exception
+         */
+        NoRouteToHostException( const Exception& ex ) throw()
+        : SocketException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         */
+        NoRouteToHostException( const NoRouteToHostException& ex ) throw()
+        : SocketException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param message to report
+         * @param list of primitives that are formatted into the message
+         */
+        NoRouteToHostException( const char* file, const int lineNumber,
+                            const char* msg, ... ) throw ()
+        : SocketException()
+        {
+            va_list vargs ;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         */
+        virtual NoRouteToHostException* clone() const {
+            return new NoRouteToHostException( *this );
+        }
+
+        /**
+         * Destructor
+         */
+        virtual ~NoRouteToHostException() throw() {}
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_NOROUTETOHOSTEXCEPTION_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/PortUnreachableException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/PortUnreachableException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/PortUnreachableException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/PortUnreachableException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_NET_PORTUNREACHABLEEXCEPTION_H_
+#define _DECAF_NET_PORTUNREACHABLEEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/net/SocketException.h>
+
+namespace decaf{
+namespace net{
+
+    class DECAF_API PortUnreachableException : public SocketException {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        PortUnreachableException() throw() {}
+
+        /**
+         * Conversion Constructor from some other Exception
+         * @param An exception that should become this type of Exception
+         */
+        PortUnreachableException( const Exception& ex ) throw()
+        : SocketException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         */
+        PortUnreachableException( const PortUnreachableException& ex ) throw()
+        : SocketException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param message to report
+         * @param list of primitives that are formatted into the message
+         */
+        PortUnreachableException( const char* file, const int lineNumber,
+                            const char* msg, ... ) throw ()
+        : SocketException()
+        {
+            va_list vargs ;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         */
+        virtual PortUnreachableException* clone() const {
+            return new PortUnreachableException( *this );
+        }
+
+        /**
+         * Destructor
+         */
+        virtual ~PortUnreachableException() throw() {}
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_PORTUNREACHABLEEXCEPTION_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/ProtocolException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/ProtocolException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/ProtocolException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/ProtocolException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_NET_PROTOCOLEXCEPTION_H_
+#define _DECAF_NET_PROTOCOLEXCEPTION_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/IOException.h>
+
+namespace decaf{
+namespace net{
+
+    class DECAF_API ProtocolException : public io::IOException {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        ProtocolException() throw() {}
+
+        /**
+         * Conversion Constructor from some other Exception
+         * @param An exception that should become this type of Exception
+         */
+        ProtocolException( const Exception& ex ) throw()
+        : io::IOException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         */
+        ProtocolException( const ProtocolException& ex ) throw()
+        : io::IOException()
+        {
+            *(Exception*)this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param message to report
+         * @param list of primitives that are formatted into the message
+         */
+        ProtocolException( const char* file, const int lineNumber,
+                            const char* msg, ... ) throw ()
+        : io::IOException()
+        {
+            va_list vargs ;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         */
+        virtual ProtocolException* clone() const {
+            return new ProtocolException( *this );
+        }
+
+        /**
+         * Destructor
+         */
+        virtual ~ProtocolException() throw() {}
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_PROTOCOLEXCEPTION_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/ServerSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/ServerSocket.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/ServerSocket.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/ServerSocket.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+
+#include "ServerSocket.h"
+#include "SocketError.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <assert.h>
+#include <string>
+
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+ServerSocket::ServerSocket() {
+    socketHandle = (apr_socket_t*)Socket::INVALID_SOCKET_HANDLE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ServerSocket::~ServerSocket() {
+    // No shutdown, just close - dont want blocking destructor.
+    close();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServerSocket::bind( const char* host, int port ) throw ( SocketException ) {
+    this->bind( host, port, SOMAXCONN );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServerSocket::bind( const char* host,
+                         int port,
+                         int backlog ) throw ( SocketException ) {
+
+    apr_status_t result = APR_SUCCESS;
+
+    if( isBound() ) {
+        throw SocketException ( __FILE__, __LINE__,
+            "ServerSocket::bind - Socket already bound" );
+    }
+
+    // Verify the port value.
+    if( port <= 0 || port > 65535 ) {
+        throw SocketException(
+            __FILE__, __LINE__,
+            "ServerSocket::bind - Port out of range: %d", port );
+    }
+
+    // Create the Address Info for the Socket
+    result = apr_sockaddr_info_get(
+        &socketAddress, host, APR_INET, port, 0, apr_pool.getAprPool() );
+
+    if( result != APR_SUCCESS ) {
+        socketHandle = (apr_socket_t*)Socket::INVALID_SOCKET_HANDLE;
+        throw SocketException(
+              __FILE__, __LINE__,
+              SocketError::getErrorString().c_str() );
+    }
+
+    // Create the socket.
+    result = apr_socket_create(
+        &socketHandle, APR_INET, SOCK_STREAM, APR_PROTO_TCP, apr_pool.getAprPool() );
+
+    if( result != APR_SUCCESS ) {
+        socketHandle = (apr_socket_t*)Socket::INVALID_SOCKET_HANDLE;
+        throw SocketException(
+              __FILE__, __LINE__,
+              SocketError::getErrorString().c_str() );
+    }
+
+    // Set the socket to reuse the address and default as blocking
+    apr_socket_opt_set( socketHandle, APR_SO_REUSEADDR, 1 );
+    apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, 0);
+    apr_socket_timeout_set( socketHandle, -1 );
+
+    // Bind to the Socket, this may be where we find out if the port is in use.
+    result = apr_socket_bind( socketHandle, socketAddress );
+
+    if( result != APR_SUCCESS ) {
+        close();
+        throw SocketException(
+              __FILE__, __LINE__,
+              "ServerSocket::bind - %s",
+              SocketError::getErrorString().c_str() );
+    }
+
+    // Setup the listen for incoming connection requests
+    result = apr_socket_listen( socketHandle, backlog );
+
+    if( result != APR_SUCCESS ) {
+        close();
+        throw SocketException(
+              __FILE__, __LINE__,
+              "ServerSocket::bind - %s",
+              SocketError::getErrorString().c_str() );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServerSocket::close() throw ( lang::Exception ){
+
+    if( isBound() ) {
+        apr_socket_close( socketHandle );
+        socketHandle = (apr_socket_t*)Socket::INVALID_SOCKET_HANDLE;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ServerSocket::isBound() const {
+    return this->socketHandle != (apr_socket_t*)Socket::INVALID_SOCKET_HANDLE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* ServerSocket::accept() throw (SocketException)
+{
+    SocketHandle incoming = NULL;
+    apr_status_t result = APR_SUCCESS;
+
+    // Loop to ignore any signal interruptions that occur during the operation.
+    do {
+        result = apr_socket_accept( &incoming, socketHandle, apr_pool.getAprPool() );
+    } while( result == APR_EINTR );
+
+    if( result != APR_SUCCESS ) {
+        std::cout << "Failed to accept New Connection:" << std::endl;
+        throw SocketException(
+              __FILE__, __LINE__,
+              "ServerSocket::accept - %s",
+              SocketError::getErrorString().c_str() );
+    }
+
+    return new TcpSocket( incoming );
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/ServerSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/ServerSocket.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/ServerSocket.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/ServerSocket.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+#ifndef _DECAF_NET_SERVERSOCKETIMPL_H_
+#define _DECAF_NET_SERVERSOCKETIMPL_H_
+
+#include <decaf/net/TcpSocket.h>
+#include <decaf/net/SocketException.h>
+#include <decaf/util/Config.h>
+#include <decaf/internal/AprPool.h>
+
+#include <apr_network_io.h>
+
+namespace decaf{
+namespace net{
+
+    /**
+     * A server socket class (for testing purposes).
+     */
+    class DECAF_API ServerSocket
+    {
+    public:
+
+        typedef apr_socket_t* SocketHandle;
+        typedef apr_sockaddr_t* SocketAddress;
+
+    private:
+
+        SocketHandle socketHandle;
+        SocketAddress socketAddress;
+        decaf::internal::AprPool apr_pool;
+
+    public:
+
+        /**
+         * Constructor.
+         * Creates a non-bound server socket.
+         */
+        ServerSocket();
+
+        /**
+         * Destructor.
+         * Releases socket handle if close() hasn't been called.
+         */
+        virtual ~ServerSocket();
+
+    public:
+
+        /**
+         * Bind and listen to given IP/dns and port.
+         * @param host IP address or host name.
+         * @param port TCP port between 1..655535
+         */
+        virtual void bind( const char* host, int port ) throw ( SocketException );
+
+        /**
+         * Bind and listen to given IP/dns and port.
+         * @param host IP address or host name.
+         * @param port TCP port between 1..655535
+         * @param backlog Size of listen backlog.
+         */
+        virtual void bind( const char* host,
+                           int port,
+                           int backlog ) throw ( SocketException );
+
+        /**
+         * Blocks until a client connects to the bound socket.
+         * @return new socket. Never returns NULL.
+         */
+        virtual Socket* accept () throw ( SocketException );
+
+        /**
+         * Closes the server socket.
+         */
+        virtual void close() throw( lang::Exception );
+
+        /**
+         * @return true of the server socket is bound.
+         */
+        virtual bool isBound() const;
+
+   };
+
+}}
+
+#endif // _DECAF_NET_SERVERSOCKETIMPL_H_
+

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/Socket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/Socket.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/Socket.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/Socket.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,170 @@
+/*
+ * 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.
+ */
+#ifndef _DECAF_NET_SOCKET_H_
+#define _DECAF_NET_SOCKET_H_
+
+#include <decaf/net/SocketException.h>
+#include <decaf/io/InputStream.h>
+#include <decaf/io/OutputStream.h>
+#include <decaf/io/Closeable.h>
+#include <decaf/util/Config.h>
+
+#include <apr_network_io.h>
+
+namespace decaf{
+namespace net{
+
+    class DECAF_API Socket : public decaf::io::Closeable
+    {
+    public:
+
+        /**
+         * Define the SocketHandle type.
+         */
+        typedef apr_socket_t* SocketHandle;
+
+        /**
+         * Define the SocketAddress type
+         */
+        typedef apr_sockaddr_t* SocketAddress;
+
+        /**
+         * Defines a constant for an invalid socket handle.
+         */
+        static const int INVALID_SOCKET_HANDLE = 0;
+
+    public:
+
+        virtual ~Socket() {}
+
+        /**
+         * Connects to the specified destination. Closes this socket if
+         * connected to another destination.
+         * @param host The host of the server to connect to.
+         * @param port The port of the server to connect to.
+         * @throws IOException Thrown if a failure occurred in the connect.
+         */
+        virtual void connect( const char* host, int port )
+            throw(SocketException) = 0;
+
+        /**
+         * Indicates whether or not this socket is connected to a destination.
+         * @returns true if connected
+         */
+        virtual bool isConnected() const = 0;
+
+        /**
+         * Gets the InputStream for this socket.
+         * @return The InputStream for this socket. NULL if not connected.
+         */
+        virtual io::InputStream* getInputStream() = 0;
+
+        /**
+         * Gets the OutputStream for this socket.
+         * @return the OutputStream for this socket.  NULL if not connected.
+         */
+        virtual io::OutputStream* getOutputStream() = 0;
+
+        /**
+         * Gets the linger time.
+         * @return The linger time in seconds.
+         * @throws SocketException if the operation fails.
+         */
+        virtual int getSoLinger() const throw( SocketException ) = 0;
+
+        /**
+         * Sets the linger time.
+         * @param linger The linger time in seconds.  If 0, linger is off.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setSoLinger( int linger ) throw( SocketException ) = 0;
+
+        /**
+         * Gets the keep alive flag.
+         * @return True if keep alive is enabled.
+         * @throws SocketException if the operation fails.
+         */
+        virtual bool getKeepAlive() const throw( SocketException ) = 0;
+
+        /**
+         * Enables/disables the keep alive flag.
+         * @param keepAlive If true, enables the flag.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setKeepAlive( bool keepAlive ) throw( SocketException ) = 0;
+
+        /**
+         * Gets the receive buffer size.
+         * @return the receive buffer size in bytes.
+         * @throws SocketException if the operation fails.
+         */
+        virtual int getReceiveBufferSize() const throw( SocketException ) = 0;
+
+        /**
+         * Sets the recieve buffer size.
+         * @param size Number of bytes to set the receive buffer to.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setReceiveBufferSize( int size ) throw( SocketException ) = 0;
+
+        /**
+         * Gets the reuse address flag.
+         * @return True if the address can be reused.
+         * @throws SocketException if the operation fails.
+         */
+        virtual bool getReuseAddress() const throw( SocketException ) = 0;
+
+        /**
+         * Sets the reuse address flag.
+         * @param reuse If true, sets the flag.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setReuseAddress( bool reuse ) throw( SocketException ) = 0;
+
+        /**
+         * Gets the send buffer size.
+         * @return the size in bytes of the send buffer.
+         * @throws SocketException if the operation fails.
+         */
+        virtual int getSendBufferSize() const throw( SocketException ) = 0;
+
+        /**
+         * Sets the send buffer size.
+         * @param size The number of bytes to set the send buffer to.
+         * @throws SocketException if the operation fails.
+         */
+        virtual void setSendBufferSize( int size ) throw( SocketException ) = 0;
+
+        /**
+         * Gets the timeout for socket operations.
+         * @return The timeout in milliseconds for socket operations.
+         * @throws SocketException Thrown if unable to retrieve the information.
+         */
+        virtual int getSoTimeout() const throw( SocketException ) = 0;
+
+        /**
+         * Sets the timeout for socket operations.
+         * @param timeout The timeout in milliseconds for socket operations.<p>
+         * @throws SocketException Thrown if unable to set the information.
+         */
+        virtual void setSoTimeout( int timeout ) throw( SocketException ) = 0;
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_SOCKET_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketError.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketError.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketError.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketError.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+#include "SocketError.h"
+#include <decaf/util/Config.h>
+
+#include <apr.h>
+#include <apr_general.h>
+
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+int SocketError::getErrorCode() {
+    return apr_get_netos_error();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string SocketError::getErrorString() {
+
+    std::string returnValue;
+
+    // Get the error code.
+    apr_status_t errorCode = apr_get_netos_error();
+
+    // Create a buffer and get the error
+    char buffer[256];
+    return apr_strerror( errorCode, buffer, sizeof( buffer ) );
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketError.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketError.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketError.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketError.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_NET_SOCKETERROR_H_
+#define _DECAF_NET_SOCKETERROR_H_
+
+#include <string>
+#include <decaf/util/Config.h>
+
+namespace decaf{
+namespace net{
+
+    /**
+     * Static utility class to simplify handling of error codes
+     * for socket operations.
+     */
+    class DECAF_API SocketError {
+    public:
+
+        /**
+         * Gets the last error appropriate for the platform.
+         */
+        static int getErrorCode();
+
+        /**
+         * Gets the string description for the last error.
+         */
+        static std::string getErrorString();
+    };
+
+}}
+
+#endif /*_DECAF_NET_SOCKETERROR_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketException.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketException.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketException.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+#ifndef _DECAF_NET_SOCKETEXCEPTION_H_
+#define _DECAF_NET_SOCKETEXCEPTION_H_
+
+#include <decaf/io/IOException.h>
+
+namespace decaf{
+namespace net{
+
+    /**
+     * Exception for errors when manipulating sockets.
+     */
+    class DECAF_API SocketException : public io::IOException
+    {
+    public:
+
+        SocketException() throw() {}
+
+        SocketException( const lang::Exception& ex ) throw()
+        : io::IOException() {
+            *(lang::Exception*)this = ex;
+        }
+
+        SocketException( const SocketException& ex ) throw()
+        : io::IOException() {
+            *(lang::Exception*)this = ex;
+        }
+
+        SocketException( const char* file, const int lineNumber,
+                         const char* msg, ...) throw()
+        : io::IOException() {
+            va_list vargs;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         */
+        virtual SocketException* clone() const {
+            return new SocketException( *this );
+        }
+
+        virtual ~SocketException() throw() {}
+
+    };
+
+}}
+
+
+#endif // _DECAF_NET_SOCKETEXCEPTION_H_
+

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketFactory.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketFactory.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketFactory.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ */
+#include <decaf/net/SocketFactory.h>
+#include <decaf/net/BufferedSocket.h>
+#include <decaf/net/TcpSocket.h>
+#include <decaf/util/Properties.h>
+#include <stdio.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::util;
+using namespace decaf::net;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+Socket* SocketFactory::createSocket(
+    const std::string& uri,
+    const Properties& properties)
+        throw ( SocketException ) {
+
+    try {
+
+        // Ensure something is actually passed in for the URI
+        if( uri == "" ) {
+            throw SocketException( __FILE__, __LINE__,
+                "SocketTransport::start() - uri not provided" );
+        }
+
+        string dummy = uri;
+
+        // Extract the port.
+        std::size_t portIx = dummy.find( ':' );
+        if( portIx == string::npos ) {
+            throw SocketException( __FILE__, __LINE__,
+                "SocketTransport::start() - uri malformed - port not specified: %s", uri.c_str() );
+        }
+        string host = dummy.substr( 0, portIx );
+        string portString = dummy.substr( portIx + 1 );
+        int port;
+        if( sscanf( portString.c_str(), "%d", &port) != 1 ) {
+            throw SocketException( __FILE__, __LINE__,
+               "SocketTransport::start() - unable to extract port from uri: %s", uri.c_str() );
+        }
+
+        // Get the read buffer size.
+        int inputBufferSize = 10000;
+        dummy = properties.getProperty( "inputBufferSize", "10000" );
+        sscanf( dummy.c_str(), "%d", &inputBufferSize );
+
+        // Get the write buffer size.
+        int outputBufferSize = 10000;
+        dummy = properties.getProperty( "outputBufferSize", "10000" );
+        sscanf( dummy.c_str(), "%d", &outputBufferSize );
+
+        // Get the linger flag.
+        int soLinger = 0;
+        dummy = properties.getProperty( "soLinger", "0" );
+        sscanf( dummy.c_str(), "%d", &soLinger );
+
+        // Get the keepAlive flag.
+        bool soKeepAlive =
+            properties.getProperty( "soKeepAlive", "false" ) == "true";
+
+        // Get the socket receive buffer size.
+        int soReceiveBufferSize = -1;
+        dummy = properties.getProperty( "soReceiveBufferSize", "-1" );
+        sscanf( dummy.c_str(), "%d", &soReceiveBufferSize );
+
+        // Get the socket send buffer size.
+        int soSendBufferSize = -1;
+        dummy = properties.getProperty( "soSendBufferSize", "-1" );
+        sscanf( dummy.c_str(), "%d", &soSendBufferSize );
+
+        // Get the socket TCP_NODELAY flag.
+        bool tcpNoDelay =
+            properties.getProperty( "tcpNoDelay", "true" ) == "true";
+
+        // Get the socket connect timeout in microseconds.
+        int connectTimeout = -1;
+        dummy = properties.getProperty( "soConnectTimeout", "-1" );
+        sscanf( dummy.c_str(), "%d", &connectTimeout );
+
+        // Now that we have all the elements that we wanted - let's do it!
+        // Create a TCP Socket and then Wrap it in a buffered socket
+        // so that users get the benefit of buffered reads and writes.
+        // The buffered socket will own the TcpSocket instance, and will
+        // clean it up when it is cleaned up.
+        TcpSocket* tcpSocket = new TcpSocket();
+
+        try {
+
+            // Connect the socket.
+            tcpSocket->connect( host.c_str(), port, connectTimeout );
+
+            // Set the socket options.
+            tcpSocket->setSoLinger( soLinger );
+            tcpSocket->setKeepAlive( soKeepAlive );
+            tcpSocket->setTcpNoDelay( tcpNoDelay );
+
+            if( soReceiveBufferSize > 0 ){
+                tcpSocket->setReceiveBufferSize( soReceiveBufferSize );
+            }
+
+            if( soSendBufferSize > 0 ){
+                tcpSocket->setSendBufferSize( soSendBufferSize );
+            }
+        } catch ( SocketException& ex ) {
+            ex.setMark( __FILE__, __LINE__ );
+            try{
+                delete tcpSocket;
+            } catch( SocketException& ex2 ){ /* Absorb */ }
+
+            throw ex;
+        }
+
+        return tcpSocket;
+    }
+    DECAF_CATCH_RETHROW( SocketException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, SocketException )
+    DECAF_CATCHALL_THROW( SocketException )
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketFactory.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketFactory.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketFactory.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+#ifndef _DECAF_NET_SOCKETFACTORY_H_
+#define _DECAF_NET_SOCKETFACTORY_H_
+
+#include <decaf/net/SocketException.h>
+#include <decaf/util/Properties.h>
+#include <decaf/util/Config.h>
+
+namespace decaf{
+namespace net{
+
+    class Socket;
+
+    /**
+     * Socket Factory implementation for use in Creating Sockets
+     * <p>
+     * <p>
+     * Property Options: <p>
+     * Name                  Value <p>
+     * ------------------------------------- <p>
+     * inputBufferSize       size in bytes of the buffered input stream buffer.  Defaults to 10000.<p>
+     * outputBufferSize      size in bytes of the buffered output stream buffer. Defaults to 10000.<p>
+     * soLinger              linger time for the socket (in microseconds). Defaults to 0.<p>
+     * soKeepAlive           keep alive flag for the socket (true/false). Defaults to false.<p>
+     * soReceiveBufferSize   The size of the socket receive buffer (in bytes). Defaults to 2MB.<p>
+     * soSendBufferSize      The size of the socket send buffer (in bytes). Defaults to 2MB.<p>
+     * soTimeout             The timeout of socket IO operations (in microseconds). Defaults to 10000<p>
+     *
+     * @see <code>Socket</code>
+     */
+    class DECAF_API SocketFactory
+    {
+    public:
+
+        virtual ~SocketFactory() {}
+
+        /**
+         * Creates and returns a Socket dervied Object based on the values
+         * defined in the Properties Object that is passed in.
+         * @param the URI for the Socket Connection.
+         * @param properties a IProperties pointer.
+         * @throws SocketException.
+         */
+        static Socket* createSocket( const std::string& uri,
+                                     const util::Properties& properties )
+            throw ( SocketException );
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_SOCKETFACTORY_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketInputStream.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketInputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketInputStream.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,192 @@
+/*
+ * 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.
+ */
+
+#include <decaf/util/Config.h>
+
+#if !defined(HAVE_WINSOCK2_H)
+    #include <sys/select.h>
+    #include <sys/socket.h>
+#else
+    #include <Winsock2.h>
+#endif
+
+#ifdef HAVE_SYS_IOCTL_H
+#define BSD_COMP /* Get FIONREAD on Solaris2. */
+#include <sys/ioctl.h>
+#endif
+
+// Pick up FIONREAD on Solaris 2.5.
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
+
+#include <decaf/net/SocketInputStream.h>
+#include <decaf/net/SocketError.h>
+#include <decaf/io/IOException.h>
+#include <decaf/lang/Character.h>
+#include <decaf/lang/exceptions/UnsupportedOperationException.h>
+#include <stdlib.h>
+#include <string>
+#include <stdio.h>
+#include <iostream>
+
+#include <apr_portable.h>
+
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::io;
+using namespace decaf::util;
+using namespace decaf::lang;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+SocketInputStream::SocketInputStream( net::Socket::SocketHandle socket ) {
+    this->socket = socket;
+    this->closed = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SocketInputStream::~SocketInputStream(){}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketInputStream::close() throw( lang::Exception ){
+    this->closed = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t SocketInputStream::available() const throw ( io::IOException ){
+
+    // Convert to an OS level socket.
+    apr_os_sock_t oss;
+    apr_os_sock_get( (apr_os_sock_t*)&oss, socket );
+
+// The windows version
+#if defined(HAVE_WINSOCK2_H)
+
+    unsigned long numBytes = 0;
+
+    if( ::ioctlsocket( oss, FIONREAD, &numBytes ) == SOCKET_ERROR ){
+        throw SocketException( __FILE__, __LINE__, "ioctlsocket failed" );
+    }
+
+    return (std::size_t)numBytes;
+
+#else // !defined(HAVE_WINSOCK2_H)
+
+    // If FIONREAD is defined - use ioctl to find out how many bytes
+    // are available.
+    #if defined(FIONREAD)
+
+        std::size_t numBytes = 0;
+        if( ::ioctl( oss, FIONREAD, &numBytes ) != -1 ){
+            return numBytes;
+        }
+
+    #endif
+
+    // If we didn't get anything we can use select.  This is a little
+    // less functional.  We will poll on the socket - if there is data
+    // available, we'll return 1, otherwise we'll return zero.
+    #if defined(HAVE_SELECT)
+
+        fd_set rd;
+        FD_ZERO(&rd);
+        FD_SET( oss, &rd );
+        struct timeval tv;
+        tv.tv_sec = 0;
+        tv.tv_usec = 0;
+        int returnCode = ::select( oss+1, &rd, NULL, NULL, &tv );
+        if( returnCode == -1 ){
+            throw IOException(
+                __FILE__, __LINE__,
+                SocketError::getErrorString().c_str() );
+        }
+        return (returnCode == 0) ? 0 : 1;
+
+    #else
+
+        return 0;
+
+    #endif /* HAVE_SELECT */
+
+#endif // !defined(HAVE_WINSOCK2_H)
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char SocketInputStream::read() throw ( IOException ){
+
+    apr_status_t result = APR_SUCCESS;
+    char c;
+    apr_size_t size = 1;
+
+    result = apr_socket_recv( socket, &c, &size );
+
+    if( ( size != sizeof(c) && !closed ) || result != APR_SUCCESS ){
+        throw IOException( __FILE__, __LINE__,
+            "activemq::io::SocketInputStream::read - failed reading a byte");
+    }
+
+    return c;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int SocketInputStream::read( unsigned char* buffer,
+                             std::size_t offset,
+                             std::size_t bufferSize )
+    throw ( IOException, lang::exceptions::NullPointerException ) {
+
+    apr_size_t size = (apr_size_t)bufferSize;
+    apr_status_t result = APR_SUCCESS;
+
+    // Read data from the socket, size on input is size of buffer, when done
+    // size is the number of bytes actually read, can be <= bufferSize.
+    result = apr_socket_recv( socket, (char*)buffer + offset, &size );
+
+    // Check for EOF, on windows we only get size==0 so check that to, if we
+    // were closed though then we throw an IOException so the caller knows we
+    // aren't usable anymore.
+    if( ( APR_STATUS_IS_EOF( result ) || size == 0 ) && !closed ) {
+        return -1;
+    }
+
+    // Check for a closed call from socket class, if closed then this read fails.
+    if( closed ){
+        throw IOException(
+            __FILE__, __LINE__,
+            "activemq::io::SocketInputStream::read - The connection is broken" );
+    }
+
+    // Check for error.
+    if( result != APR_SUCCESS ){
+        throw IOException(
+            __FILE__, __LINE__,
+            "decaf::net::SocketInputStream::read - %s",
+            SocketError::getErrorString().c_str() );
+    }
+
+    return (int)size;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t SocketInputStream::skip( std::size_t num DECAF_UNUSED )
+    throw ( io::IOException, lang::exceptions::UnsupportedOperationException ) {
+
+    throw lang::exceptions::UnsupportedOperationException(
+        __FILE__, __LINE__,
+        "SocketInputStream::skip() method is not supported");
+}
+

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketInputStream.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketInputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketInputStream.h Tue Apr 29 13:52:30 2008
@@ -0,0 +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.
+ */
+
+#ifndef _DECAF_NET_SOCKETINPUTSTREAM_H_
+#define _DECAF_NET_SOCKETINPUTSTREAM_H_
+
+#include <decaf/io/InputStream.h>
+#include <decaf/net/Socket.h>
+#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/lang/Exception.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+
+namespace decaf{
+namespace net{
+
+    /**
+     * Input stream for performing reads on a socket.  This
+     * class will only work properly for blocking sockets.
+     */
+    class DECAF_API SocketInputStream : public io::InputStream {
+    private:
+
+        // The socket handle.
+        Socket::SocketHandle socket;
+        util::concurrent::Mutex mutex;
+        bool closed;
+
+    public:
+
+        /**
+         * Constructor.
+         * @param socket the socket handle.
+         */
+        SocketInputStream( Socket::SocketHandle socket );
+
+        /**
+         * Destructor.
+         */
+        virtual ~SocketInputStream();
+
+        /**
+         * Returns the number of bytes available on the socket to
+         * be read right now.
+         * @return The number of bytes currently available to
+         * be read on the socket.
+         */
+        virtual std::size_t available() const throw ( io::IOException );
+
+        /**
+         * Reads a single byte from the buffer.  If no data
+         * is available, blocks until their is.
+         * @return The next byte.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual unsigned char read() throw ( io::IOException );
+
+        /**
+         * Reads an array of bytes from the buffer.  If the desired amount
+         * of data is not currently available, this operation
+         * will block until the appropriate amount of data is available.
+         * @param buffer (out) the target buffer
+         * @param offset the position in the buffer to start from.
+         * @param bufferSize the size of the output buffer.
+         * @return the number of bytes read. or -1 if EOF
+         * @throws IOException f an error occurs.
+         */
+        virtual int read( unsigned char* buffer,
+                          std::size_t offset,
+                          std::size_t bufferSize )
+            throw ( io::IOException, lang::exceptions::NullPointerException );
+
+        /**
+         * Close - does nothing.  It is the responsibility of the owner
+         * of the socket object to close it.
+         * @throws CMSException
+         */
+        virtual void close() throw( lang::Exception );
+
+        /**
+         * Not supported.
+         * @throws an UnsupportedOperationException.
+         */
+        virtual std::size_t skip( std::size_t num )
+            throw ( io::IOException,
+                    lang::exceptions::UnsupportedOperationException );
+
+        /**
+         * Marks the current position in the stream A subsequent call to the
+         * reset method repositions this stream at the last marked position so
+         * that subsequent reads re-read the same bytes.
+         *
+         * If a stream instance reports that marks are supported then the stream
+         * will ensure that the same bytes can be read again after the reset method
+         * is called so long the readLimit is not reached.
+         * @param readLimit - max bytes read before marked position is invalid.
+         */
+        virtual void mark( int readLimit DECAF_UNUSED ) {}
+
+        /**
+         * Repositions this stream to the position at the time the mark method was
+         * last called on this input stream.
+         *
+         * If the method markSupported returns true, then:
+         *   * If the method mark has not been called since the stream was created,
+         *     or the number of bytes read from the stream since mark was last called
+         * 	   is larger than the argument to mark at that last call, then an
+         *     IOException might be thrown.
+         *   * If such an IOException is not thrown, then the stream is reset to a
+         *     state such that all the bytes read since the most recent call to mark
+         *     (or since the start of the file, if mark has not been called) will be
+         *     resupplied to subsequent callers of the read method, followed by any
+         *     bytes that otherwise would have been the next input data as of the
+         *     time of the call to reset.
+         * If the method markSupported returns false, then:
+         *   * The call to reset may throw an IOException.
+         *   * If an IOException is not thrown, then the stream is reset to a fixed
+         *     state that depends on the particular type of the input stream and how
+         *     it was created. The bytes that will be supplied to subsequent callers
+         *     of the read method depend on the particular type of the input stream.
+         * @throws IOException
+         */
+        virtual void reset() throw ( io::IOException ) {
+            throw io::IOException(
+                __FILE__, __LINE__,
+                "SocketInputStream::reset - Mark is not supported" );
+        }
+
+        /**
+         * Determines if this input stream supports the mark and reset methods.
+         * Whether or not mark and reset are supported is an invariant property of
+         * a particular input stream instance.
+         * @returns true if this stream instance supports marks
+         */
+        virtual bool markSupported() const {
+            return false;
+        }
+
+    public:
+
+        /**
+         * Locks the object.
+         * @throws Exception
+         */
+        virtual void lock() throw( lang::Exception ){
+            mutex.lock();
+        }
+
+        /**
+         * Unlocks the object.
+         * @throws Exception
+         */
+        virtual void unlock() throw( lang::Exception ){
+            mutex.unlock();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void wait() throw( lang::Exception ){
+            mutex.wait();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.  This wait will timeout after the specified time
+         * interval.
+         * @param millisecs time in millisecsonds to wait, or WAIT_INIFINITE
+         * @throws Exception
+         */
+        virtual void wait( unsigned long millisecs )
+            throw( lang::Exception ) {
+
+            mutex.wait( millisecs );
+        }
+
+        /**
+         * Signals a waiter on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notify() throw( lang::Exception ){
+            mutex.notify();
+        }
+
+        /**
+         * Signals the waiters on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notifyAll() throw( lang::Exception ){
+            mutex.notifyAll();
+        }
+
+    };
+
+}}
+
+#endif /*_DECAF_NET_SOCKETINPUTSTREAM_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/net/SocketOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/net/SocketOutputStream.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/net/SocketOutputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/net/SocketOutputStream.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+
+#include "SocketOutputStream.h"
+#include <decaf/util/Config.h>
+#include <decaf/lang/Character.h>
+#include "SocketError.h"
+
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::io;
+using namespace decaf::util;
+using namespace decaf::lang::exceptions;
+using namespace std;
+
+////////////////////////////////////////////////////////////////////////////////
+SocketOutputStream::SocketOutputStream( Socket::SocketHandle socket ) {
+    this->socket = socket;
+    this->closed = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SocketOutputStream::~SocketOutputStream() {
+    close();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketOutputStream::close() throw( lang::Exception ) {
+    this->closed = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketOutputStream::write( unsigned char c ) throw ( IOException ) {
+    write( &c, 0, 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketOutputStream::write( const std::vector<unsigned char>& buffer )
+    throw ( IOException ) {
+
+    try{
+
+        if( buffer.empty() ) {
+            return;
+        }
+
+        this->write( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketOutputStream::write( const unsigned char* buffer,
+                                std::size_t offset, std::size_t len )
+    throw ( IOException, lang::exceptions::NullPointerException ) {
+
+    if( len == 0 ) {
+        return;
+    }
+
+    if( buffer == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__,
+            "SocketOutputStream::write - passed buffer is null" );
+    }
+
+    apr_size_t remaining = (apr_size_t)len;
+    apr_status_t result = APR_SUCCESS;
+
+    const unsigned char* lbuffer = buffer + offset;
+
+    while( remaining > 0 && !closed ) {
+        // On input remaining is the bytes to send, after return remaining
+        // is the amount actually sent.
+        result = apr_socket_send( socket, (const char*)lbuffer, &remaining );
+
+        if( result != APR_SUCCESS || closed ) {
+            throw IOException(
+                __FILE__, __LINE__,
+                "decaf::net::SocketOutputStream::write - %s",
+                SocketError::getErrorString().c_str() );
+        }
+
+        // move us to next position to write, or maybe end.
+        lbuffer += remaining;
+        remaining = len - remaining;
+    }
+}