Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 95937 invoked from network); 9 Apr 2010 22:18:02 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Apr 2010 22:18:02 -0000 Received: (qmail 57020 invoked by uid 500); 9 Apr 2010 22:18:02 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 56980 invoked by uid 500); 9 Apr 2010 22:18:02 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 56972 invoked by uid 99); 9 Apr 2010 22:18:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Apr 2010 22:18:02 +0000 X-ASF-Spam-Status: No, hits=-1203.7 required=10.0 tests=ALL_TRUSTED,AWL 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; Fri, 09 Apr 2010 22:17:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8142723889FA; Fri, 9 Apr 2010 22:17:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r932637 [3/3] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/activemq/transport/tcp/ main/decaf/internal/net/tcp/ main/decaf/net/ test/decaf/net/ Date: Fri, 09 Apr 2010 22:17:38 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100409221739.8142723889FA@eris.apache.org> Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h?rev=932637&r1=932636&r2=932637&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h Fri Apr 9 22:17:38 2010 @@ -41,7 +41,8 @@ namespace net { private: int port; - std::string hostname; + int localPort; + std::string address; public: @@ -49,7 +50,15 @@ namespace net { virtual ~SocketImpl(); - protected: + public: + + /** + * Creates the underlying platform Socket data structures which allows for + * Socket options to be applied. The created socket is in an unconnected state. + * + * @throws IOException if an I/O error occurs while attempting this operation. + */ + virtual void create() throw( decaf::io::IOException ) = 0; /** * Accepts a new connection on the given Socket. @@ -68,11 +77,15 @@ namespace net { * The name of the host to connect to, or IP address. * @param port * The port number on the host to connect to. + * @param timeout + * Time in milliseconds to wait for a connection, 0 indicates forever. * * @throws IOException if an I/O error occurs while attempting this operation. + * @throws IllegalArguementException if a parameter has an illegal value. */ - virtual void connect( const std::string& hostname, int port ) - throw( decaf::io::IOException ) = 0; + virtual void connect( const std::string& hostname, int port, int timeout ) + throw( decaf::io::IOException, + decaf::lang::exceptions::IllegalArgumentException ) = 0; /** * Binds this Socket instance to the local ip address and port number given. @@ -157,21 +170,89 @@ namespace net { virtual void shutdownOutput() throw( decaf::io::IOException ) = 0; /** + * Gets the specified Socket option. + * + * @param option + * The Socket options whose value is to be retrieved. + * + * @returns the value of the given socket option. + * + * @throws IOException if an I/O error occurs while performing this operation. + */ + virtual int getOption( int option ) const throw( decaf::io::IOException ) = 0; + + /** + * Sets the specified option on the Socket if supported. + * + * @param option + * The Socket option to set. + * @param value + * The value of the socket option to apply to the socket. + * + * @throws IOException if an I/O error occurs while performing this operation. + */ + virtual void setOption( int option, int value ) throw( decaf::io::IOException ) = 0; + + /** * Gets the port that this socket has been assigned. * * @return the Socket's port number. */ - int getPort() { + int getPort() const { return this->port; } /** + * Gets the value of this SocketImpl's local port field. + * + * @returns the value of localPort. + */ + int getLocalPort() const { + return this->localPort; + } + + /** + * Gets the value of this SocketImpl's address field. + * + * @returns the value of the address field. + */ + std::string getInetAddress() const { + return this->address; + } + + /** + * Gets the value of the local Inet address the Socket is bound to if bound, otherwise + * return the InetAddress ANY value "0.0.0.0". + * + * @returns the local address bound to, or ANY. + */ + virtual std::string getLocalAddress() const = 0; + + /** * Returns a string containing the address and port of this Socket instance. * * @returns a string containing the address and port of this socket. */ std::string toString() const; + /** + * @returns true if this SocketImpl supports sending Urgent Data. The default + * implementation always returns false. + */ + virtual bool supportsUrgentData() const { + return false; + } + + /** + * Sends on byte of urgent data to the Socket. + * + * @param data + * The value to write as urgent data, only the lower eight bits are sent. + * + * @throws IOException if an I/O error occurs while performing this operation. + */ + virtual void sendUrgentData( int data ) throw( decaf::io::IOException ); + }; }} Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImplFactory.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImplFactory.h?rev=932637&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImplFactory.h (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImplFactory.h Fri Apr 9 22:17:38 2010 @@ -0,0 +1,55 @@ +/* + * 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_SOCKETIMPLFACTORY_H_ +#define _DECAF_NET_SOCKETIMPLFACTORY_H_ + +#include + +namespace decaf { +namespace net { + + class SocketImpl; + + /** + * Factory class interface for a Factory that creates ScoketImpl objects. These + * factories can be used to create various types of Sockets, e.g. Streaming, Multicast, + * SSL, or platform specific variations of these types. + * + * @see decaf::net::Socket + * @see decaf::net::ServerSocket + * + * @since 1.0 + */ + class DECAF_API SocketImplFactory { + public: + + virtual ~SocketImplFactory() {} + + /** + * Creates a new SokcetImpl instance and returns it, the caller then owns the + * instance and must delete it when finished with the SocketImpl. + * + * @return new SocketImpl instance that is owned by the caller. + */ + virtual SocketImpl* createSocketImpl() = 0; + + }; + +}} + +#endif /* _DECAF_NET_SOCKETIMPLFACTORY_H_ */ Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImplFactory.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp?rev=932637&r1=932636&r2=932637&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp Fri Apr 9 22:17:38 2010 @@ -18,23 +18,23 @@ #include "SocketOptions.h" using namespace decaf; -using namespace net; +using namespace decaf::net; //////////////////////////////////////////////////////////////////////////////// -const int SocketOptions::IP_MULTICAST_IF = 16; -const int SocketOptions::IP_MULTICAST_IF2 = 31; -const int SocketOptions::IP_MULTICAST_LOOP = 18; -const int SocketOptions::IP_TOS = 3; -const int SocketOptions::SO_BINDADDR = 15; -const int SocketOptions::SO_BROADCAST = 32; -const int SocketOptions::SO_KEEPALIVE = 8; -const int SocketOptions::SO_LINGER = 128; -const int SocketOptions::SO_OOBINLINE = 4099; -const int SocketOptions::SO_RCVBUF = 4098; -const int SocketOptions::SO_REUSEADDR = 4; -const int SocketOptions::SO_SNDBUF = 4097; -const int SocketOptions::SO_TIMEOUT = 4102; -const int SocketOptions::TCP_NODELAY = 1; +const int SocketOptions::SOCKET_OPTION_TCP_NODELAY = 1; +const int SocketOptions::SOCKET_OPTION_BINDADDR = 2; +const int SocketOptions::SOCKET_OPTION_REUSEADDR = 3; +const int SocketOptions::SOCKET_OPTION_BROADCAST = 4; +const int SocketOptions::SOCKET_OPTION_IP_MULTICAST_IF = 5; +const int SocketOptions::SOCKET_OPTION_IP_MULTICAST_LOOP = 6; +const int SocketOptions::SOCKET_OPTION_IP_MULTICAST_IF2 = 7; +const int SocketOptions::SOCKET_OPTION_IP_TOS = 8; +const int SocketOptions::SOCKET_OPTION_LINGER = 9; +const int SocketOptions::SOCKET_OPTION_TIMEOUT = 10; +const int SocketOptions::SOCKET_OPTION_SNDBUF = 11; +const int SocketOptions::SOCKET_OPTION_RCVBUF = 12; +const int SocketOptions::SOCKET_OPTION_KEEPALIVE = 13; +const int SocketOptions::SOCKET_OPTION_OOBINLINE = 14; //////////////////////////////////////////////////////////////////////////////// SocketOptions::~SocketOptions() { Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h?rev=932637&r1=932636&r2=932637&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h Fri Apr 9 22:17:38 2010 @@ -34,7 +34,7 @@ namespace net { * Disable Nagle's algorithm for this connection. Written data to the network is not * buffered pending acknowledgment of previously written data. Valid for TCP sockets. */ - static const int TCP_NODELAY; + static const int SOCKET_OPTION_TCP_NODELAY; /** * Fetch the local address binding of a socket (this option cannot be "set" only "gotten", @@ -45,13 +45,13 @@ namespace net { * specify its return address to the peer (for a Socket or DatagramSocket). The parameter * of this option is an InetAddress. */ - static const int SO_BINDADDR; + static const int SOCKET_OPTION_BINDADDR; /** * Sets SO_REUSEADDR for a socket. This is used only for MulticastSockets in decaf, and it is * set by default for MulticastSockets. */ - static const int SO_REUSEADDR; + static const int SOCKET_OPTION_REUSEADDR; /** * Sets SO_BROADCAST for a socket. This option enables and disables the ability of the process @@ -59,7 +59,7 @@ namespace net { * that support the concept of a broadcast message (e.g. Ethernet, token ring, etc.), and it * is set by default for DatagramSockets. */ - static const int SO_BROADCAST; + static const int SOCKET_OPTION_BROADCAST; /** * Set which outgoing interface on which to send multicast packets. Useful on hosts with @@ -68,26 +68,26 @@ namespace net { * * Valid for Multicast: DatagramSocketImpl. */ - static const int IP_MULTICAST_IF; + static const int SOCKET_OPTION_IP_MULTICAST_IF; /** * Same as above. This option is introduced so that the behaviour with IP_MULTICAST_IF will * be kept the same as before, while this new option can support setting outgoing interfaces * with either IPv4 and IPv6 addresses. */ - static const int IP_MULTICAST_IF2; + static const int SOCKET_OPTION_IP_MULTICAST_IF2; /** * This option enables or disables local loopback of multicast datagrams. This option is enabled * by default for Multicast Sockets. */ - static const int IP_MULTICAST_LOOP; + static const int SOCKET_OPTION_IP_MULTICAST_LOOP; /** * This option sets the type-of-service or traffic class field in the IP header for a TCP or * UDP socket. */ - static const int IP_TOS; + static const int SOCKET_OPTION_IP_TOS; /** * Specify a linger-on-close timeout. This option disables/enables immediate return from a @@ -100,13 +100,13 @@ namespace net { * * Valid only for TCP: SocketImpl */ - static const int SO_LINGER; + static const int SOCKET_OPTION_LINGER; /** * Set a timeout on blocking Socket operations. The option must be set prior to entering a * blocking operation to take effect. */ - static const int SO_TIMEOUT; + static const int SOCKET_OPTION_TIMEOUT; /** * Set a hint the size of the underlying buffers used by the platform for outgoing network @@ -115,7 +115,7 @@ namespace net { * must return the size of the buffer actually used by the platform when sending out data * on this socket. Valid for all sockets: SocketImpl, DatagramSocketImpl */ - static const int SO_SNDBUF; + static const int SOCKET_OPTION_SNDBUF; /** * Set a hint the size of the underlying buffers used by the platform for incoming network @@ -124,7 +124,7 @@ namespace net { * this must return the size of the buffer actually used by the platform when receiving in * data on this socket. Valid for all sockets: SocketImpl, DatagramSocketImpl. */ - static const int SO_RCVBUF; + static const int SOCKET_OPTION_RCVBUF; /** * When the keepalive option is set for a TCP socket and no data has been exchanged across @@ -139,14 +139,14 @@ namespace net { * * Valid only for TCP socket: SocketImpl */ - static const int SO_KEEPALIVE; + static const int SOCKET_OPTION_KEEPALIVE; /** * When the OOBINLINE option is set, any TCP urgent data received on the socket will be * received through the socket input stream. When the option is disabled (which is the default) * urgent data is silently discarded. */ - static const int SO_OOBINLINE; + static const int SOCKET_OPTION_OOBINLINE; public: Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketFactoryTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketFactoryTest.cpp?rev=932637&r1=932636&r2=932637&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketFactoryTest.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketFactoryTest.cpp Fri Apr 9 22:17:38 2010 @@ -20,6 +20,10 @@ #include #include +#ifdef HAVE_STRING_H +#include +#endif + #include using namespace decaf; @@ -29,6 +33,104 @@ using namespace decaf::lang; using namespace decaf::util::concurrent; //////////////////////////////////////////////////////////////////////////////// +const int SocketFactoryTest::DEFAULT_PORT = 23232; + +//////////////////////////////////////////////////////////////////////////////// +namespace{ + + class MyServerThread : public lang::Thread{ + private: + + bool done; + int numClients; + std::string lastMessage; + + public: + + util::concurrent::Mutex mutex; + + public: + + MyServerThread(){ + done = false; + numClients = 0; + } + virtual ~MyServerThread(){ + stop(); + } + + std::string getLastMessage(){ + return lastMessage; + } + + int getNumClients(){ + return numClients; + } + + virtual void stop(){ + done = true; + } + + virtual void run(){ + try{ + unsigned char buf[1000]; + + ServerSocket server; + server.bind( "127.0.0.1", SocketFactoryTest::DEFAULT_PORT ); + + net::Socket* socket = server.accept(); + server.close(); + + socket->setSoLinger( false, 0 ); + + synchronized(&mutex) + { + numClients++; + mutex.notifyAll(); + } + + while( !done && socket != NULL ){ + + io::InputStream* stream = socket->getInputStream(); + memset( buf, 0, 1000 ); + try{ + if( stream->read( buf, 1000, 0, 1000 ) == -1 ) { + done = true; + continue; + } + + lastMessage = (char*)buf; + + if( strcmp( (char*)buf, "reply" ) == 0 ){ + io::OutputStream* output = socket->getOutputStream(); + output->write( (unsigned char*)"hello", (int)strlen("hello"), 0, (int)strlen("hello") ); + } + + }catch( io::IOException& ex ){ + done = true; + } + } + + socket->close(); + delete socket; + + numClients--; + + synchronized(&mutex) { + mutex.notifyAll(); + } + + }catch( io::IOException& ex ){ + printf("%s\n", ex.getMessage().c_str() ); + CPPUNIT_ASSERT( false ); + }catch( ... ){ + CPPUNIT_ASSERT( false ); + } + } + }; +} + +//////////////////////////////////////////////////////////////////////////////// void SocketFactoryTest::test() { try @@ -39,9 +141,9 @@ void SocketFactoryTest::test() Thread::sleep( 500 ); std::auto_ptr factory( SocketFactory::getDefault() ); - std::auto_ptr client( factory->createSocket( "127.0.0.1", port ) ); + std::auto_ptr client( factory->createSocket( "127.0.0.1", SocketFactoryTest::DEFAULT_PORT ) ); - client->setSoLinger( 0 ); + client->setSoLinger( false, 0 ); synchronized(&serverThread.mutex) { @@ -88,9 +190,9 @@ void SocketFactoryTest::testNoDelay() Thread::sleep( 40 ); std::auto_ptr factory( SocketFactory::getDefault() ); - std::auto_ptr client( factory->createSocket( "127.0.0.1", port ) ); + std::auto_ptr client( factory->createSocket( "127.0.0.1", SocketFactoryTest::DEFAULT_PORT ) ); - client->setSoLinger( 0 ); + client->setSoLinger( false, 0 ); client->setTcpNoDelay( true ); CPPUNIT_ASSERT( client->getTcpNoDelay() == true ); Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketFactoryTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketFactoryTest.h?rev=932637&r1=932636&r2=932637&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketFactoryTest.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketFactoryTest.h Fri Apr 9 22:17:38 2010 @@ -32,105 +32,16 @@ namespace decaf{ namespace net{ - class SocketFactoryTest : public CppUnit::TestFixture - { + class SocketFactoryTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE( SocketFactoryTest ); CPPUNIT_TEST( test ); CPPUNIT_TEST( testNoDelay ); CPPUNIT_TEST_SUITE_END(); - static const int port = 23232; - - class MyServerThread : public lang::Thread{ - private: + public: - bool done; - int numClients; - std::string lastMessage; - - public: - - util::concurrent::Mutex mutex; - - public: - - MyServerThread(){ - done = false; - numClients = 0; - } - virtual ~MyServerThread(){ - stop(); - } - - std::string getLastMessage(){ - return lastMessage; - } - - int getNumClients(){ - return numClients; - } - - virtual void stop(){ - done = true; - } - - virtual void run(){ - try{ - unsigned char buf[1000]; - - ServerSocket server; - server.bind( "127.0.0.1", port ); - - net::Socket* socket = server.accept(); - server.close(); - - socket->setSoLinger( false ); - - synchronized(&mutex) - { - numClients++; - mutex.notifyAll(); - } - - while( !done && socket != NULL ){ - - io::InputStream* stream = socket->getInputStream(); - memset( buf, 0, 1000 ); - try{ - if( stream->read( buf, 1000, 0, 1000 ) == -1 ) { - done = true; - continue; - } - - lastMessage = (char*)buf; - - if( strcmp( (char*)buf, "reply" ) == 0 ){ - io::OutputStream* output = socket->getOutputStream(); - output->write( (unsigned char*)"hello", (int)strlen("hello"), 0, (int)strlen("hello") ); - } - - }catch( io::IOException& ex ){ - done = true; - } - } - - socket->close(); - delete socket; - - numClients--; - - synchronized(&mutex) { - mutex.notifyAll(); - } - - }catch( io::IOException& ex ){ - printf("%s\n", ex.getMessage().c_str() ); - CPPUNIT_ASSERT( false ); - }catch( ... ){ - CPPUNIT_ASSERT( false ); - } - } - }; + static const int DEFAULT_PORT; public: Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketTest.cpp?rev=932637&r1=932636&r2=932637&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketTest.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/SocketTest.cpp Fri Apr 9 22:17:38 2010 @@ -80,7 +80,7 @@ namespace { server.close(); //socket->setSoTimeout( 10 ); - socket->setSoLinger( false ); + socket->setSoLinger( false, 0 ); numClients++; synchronized(&mutex) @@ -151,7 +151,7 @@ void SocketTest::testConnect() { std::auto_ptr client( factory->createSocket() ); client->connect( "127.0.0.1", port ); - client->setSoLinger( false ); + client->setSoLinger( false, 0 ); synchronized(&serverThread.mutex) { @@ -197,7 +197,7 @@ void SocketTest::testTx() { std::auto_ptr client( factory->createSocket() ); client->connect("127.0.0.1", port); - client->setSoLinger( false ); + client->setSoLinger( false, 0 ); synchronized(&serverThread.mutex) { @@ -252,7 +252,7 @@ void SocketTest::testTrx() { std::auto_ptr client( factory->createSocket() ); client->connect("127.0.0.1", port); - client->setSoLinger(false); + client->setSoLinger( false, 0 ); synchronized(&serverThread.mutex) { @@ -306,7 +306,7 @@ void SocketTest::testRxFail() { std::auto_ptr client( factory->createSocket() ); client->connect("127.0.0.1", port); - client->setSoLinger( false ); + client->setSoLinger( false, 0 ); synchronized(&serverThread.mutex) { @@ -355,7 +355,7 @@ void SocketTest::testTrxNoDelay() { std::auto_ptr client( factory->createSocket() ); client->connect("127.0.0.1", port); - client->setSoLinger(false); + client->setSoLinger( false, 0 ); client->setTcpNoDelay(true); CPPUNIT_ASSERT( client->getTcpNoDelay() == true );