Author: tabish
Date: Thu Apr 22 13:45:50 2010
New Revision: 936841
URL: http://svn.apache.org/viewvc?rev=936841&view=rev
Log:
Add some more tests to the ServerSocket test suite and implement some more of
the options in TcpSocket
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.h
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp?rev=936841&r1=936840&r2=936841&view=diff
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp
(original)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp
Thu Apr 22 13:45:50 2010
@@ -478,11 +478,22 @@ int TcpSocket::getOption( int option ) c
apr_interval_time_t tvalue = 0;
checkResult( apr_socket_timeout_get( socketHandle, &tvalue ) );
return (int)( tvalue / 1000 );
+ }
+ if( option == SocketOptions::SOCKET_OPTION_REUSEADDR ) {
+ aprId = APR_SO_REUSEADDR;
+ } else if( option == SocketOptions::SOCKET_OPTION_SNDBUF ) {
+ aprId = APR_SO_SNDBUF;
+ } else if( option == SocketOptions::SOCKET_OPTION_RCVBUF ) {
+ aprId = APR_SO_RCVBUF;
} else {
- checkResult( apr_socket_opt_get( socketHandle, aprId, &value ) );
+ throw IOException(
+ __FILE__, __LINE__,
+ "Socket Option is not valid for this Socket type." );
}
+ checkResult( apr_socket_opt_get( socketHandle, aprId, &value ) );
+
return (int)value;
}
DECAF_CATCH_RETHROW( IOException )
@@ -502,12 +513,24 @@ void TcpSocket::setOption( int option, i
apr_int32_t aprId = 0;
if( option == SocketOptions::SOCKET_OPTION_TIMEOUT ) {
-
// Time in APR for sockets is in microseconds so multiply by 1000.
checkResult( apr_socket_timeout_set( socketHandle, value * 1000 )
);
+ return;
+ }
+
+ if( option == SocketOptions::SOCKET_OPTION_REUSEADDR ) {
+ aprId = APR_SO_REUSEADDR;
+ } else if( option == SocketOptions::SOCKET_OPTION_SNDBUF ) {
+ aprId = APR_SO_SNDBUF;
+ } else if( option == SocketOptions::SOCKET_OPTION_RCVBUF ) {
+ aprId = APR_SO_RCVBUF;
} else {
- checkResult( apr_socket_opt_set( socketHandle, aprId,
(apr_int32_t)value ) );
+ throw IOException(
+ __FILE__, __LINE__,
+ "Socket Option is not valid for this Socket type." );
}
+
+ checkResult( apr_socket_opt_set( socketHandle, aprId,
(apr_int32_t)value ) );
}
DECAF_CATCH_RETHROW( IOException )
DECAF_CATCHALL_THROW( IOException )
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.cpp?rev=936841&r1=936840&r2=936841&view=diff
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.cpp
(original)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.cpp
Thu Apr 22 13:45:50 2010
@@ -176,6 +176,34 @@ void ServerSocketTest::testGetSoTimeout(
}
////////////////////////////////////////////////////////////////////////////////
+void ServerSocketTest::testGetReuseAddress() {
+
+ try{
+ ServerSocket s;
+ s.setReuseAddress( true );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Reuse Address doesnt match what was
set.", true, s.getReuseAddress() );
+ s.setReuseAddress( false );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Reuse Address doesnt match what was
set.", false, s.getReuseAddress() );
+ } catch( Exception& ex ) {
+ ex.printStackTrace();
+ throw ex;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServerSocketTest::testGetReceiveBufferSize() {
+
+ try{
+ ServerSocket s;
+ //CPPUNIT_ASSERT_MESSAGE( "Receive Buffer should never be zero.", 0 !=
s.getReceiveBufferSize() );
+ //CPPUNIT_ASSERT_MESSAGE( "Receive Buffer should never be negative.",
0 < s.getReceiveBufferSize() );
+ } catch( Exception& ex ) {
+ ex.printStackTrace();
+ throw ex;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
void ServerSocketTest::startClient( int port ) {
client = new SocketClient( port );
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.h?rev=936841&r1=936840&r2=936841&view=diff
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.h
(original)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/ServerSocketTest.h
Thu Apr 22 13:45:50 2010
@@ -35,6 +35,8 @@ namespace net {
CPPUNIT_TEST( testClose );
CPPUNIT_TEST( testGetLocalPort );
CPPUNIT_TEST( testGetSoTimeout );
+ CPPUNIT_TEST( testGetReuseAddress );
+ CPPUNIT_TEST( testGetReceiveBufferSize );
CPPUNIT_TEST_SUITE_END();
private:
@@ -55,6 +57,8 @@ namespace net {
void testClose();
void testGetLocalPort();
void testGetSoTimeout();
+ void testGetReuseAddress();
+ void testGetReceiveBufferSize();
protected: