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 2013/02/22 00:38:03 UTC
svn commit: r1448855 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp:
TcpSocket.cpp TcpSocket.h TcpSocketInputStream.cpp TcpSocketInputStream.h
TcpSocketOutputStream.cpp TcpSocketOutputStream.h
Author: tabish
Date: Thu Feb 21 23:38:03 2013
New Revision: 1448855
URL: http://svn.apache.org/r1448855
Log:
Clean up and internalize all the APR bits into the TcpSocket class.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.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=1448855&r1=1448854&r2=1448855&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 Feb 21 23:38:03 2013
@@ -31,6 +31,7 @@
#include <iostream>
#include <apr_portable.h>
+#include <apr_network_io.h>
#if !defined(HAVE_WINSOCK2_H)
#include <sys/select.h>
@@ -60,364 +61,390 @@ using namespace decaf::lang;
using namespace decaf::lang::exceptions;
////////////////////////////////////////////////////////////////////////////////
-TcpSocket::TcpSocket() : apr_pool(),
- socketHandle( NULL ),
- localAddress( NULL ),
- remoteAddress( NULL ),
- inputStream( NULL ),
- outputStream( NULL ),
- inputShutdown( false ),
- outputShutdown( false ),
- closed( false ),
- trafficClass( 0 ),
- soTimeout( -1 ),
- soLinger( -1 ) {
+namespace decaf {
+namespace internal {
+namespace net {
+namespace tcp {
+
+ class TcpSocketImpl {
+ public:
+
+ decaf::internal::AprPool apr_pool;
+ apr_socket_t* socketHandle;
+ apr_sockaddr_t* localAddress;
+ apr_sockaddr_t* remoteAddress;
+ TcpSocketInputStream* inputStream;
+ TcpSocketOutputStream* outputStream;
+ bool inputShutdown;
+ bool outputShutdown;
+ volatile bool closed;
+ int trafficClass;
+ int soTimeout;
+ int soLinger;
+
+ TcpSocketImpl() : apr_pool(),
+ socketHandle(NULL),
+ localAddress(NULL),
+ remoteAddress(NULL),
+ inputStream(NULL),
+ outputStream(NULL),
+ inputShutdown(false),
+ outputShutdown(false),
+ closed(false),
+ trafficClass(0),
+ soTimeout(-1),
+ soLinger(-1) {
+ }
+ };
+
+}}}}
+
+////////////////////////////////////////////////////////////////////////////////
+TcpSocket::TcpSocket() : impl(new TcpSocketImpl) {
}
////////////////////////////////////////////////////////////////////////////////
TcpSocket::~TcpSocket() {
- try{
-
- // No shutdown, just close - don't want a blocking destructor.
+ try {
close();
+ }
+ DECAF_CATCHALL_NOTHROW()
- // Destroy the input stream.
- if( inputStream != NULL ){
- delete inputStream;
- inputStream = NULL;
+ try {
+ if (this->impl->inputStream != NULL) {
+ delete this->impl->inputStream;
+ this->impl->inputStream = NULL;
}
+ }
+ DECAF_CATCHALL_NOTHROW()
- // Destroy the output stream.
- if( outputStream != NULL ){
- delete outputStream;
- outputStream = NULL;
+ try {
+ if (this->impl->outputStream != NULL) {
+ delete this->impl->outputStream;
+ this->impl->outputStream = NULL;
}
}
- DECAF_CATCH_NOTHROW( Exception )
+ DECAF_CATCHALL_NOTHROW()
+
+ try {
+ delete this->impl;
+ }
DECAF_CATCHALL_NOTHROW()
}
////////////////////////////////////////////////////////////////////////////////
void TcpSocket::create() {
- try{
+ try {
- if( this->socketHandle != NULL ) {
- throw IOException(
- __FILE__, __LINE__, "The System level socket has already been created." );
+ if (this->impl->socketHandle != NULL) {
+ throw IOException(__FILE__, __LINE__, "The System level socket has already been created.");
}
// Create the actual socket.
- checkResult( apr_socket_create( &socketHandle, AF_INET, SOCK_STREAM,
- APR_PROTO_TCP, apr_pool.getAprPool() ) );
+ checkResult(apr_socket_create(&this->impl->socketHandle,
+ AF_INET, SOCK_STREAM, APR_PROTO_TCP, this->impl->apr_pool.getAprPool()));
// Initialize the Socket's FileDescriptor
apr_os_sock_t osSocket = -1;
- apr_os_sock_get( &osSocket, socketHandle );
- this->fd = new SocketFileDescriptor( osSocket );
+ apr_os_sock_get(&osSocket, this->impl->socketHandle);
+ this->fd = new SocketFileDescriptor(osSocket);
}
- DECAF_CATCH_RETHROW( decaf::io::IOException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )
- DECAF_CATCHALL_THROW( decaf::io::IOException )
+ DECAF_CATCH_RETHROW(decaf::io::IOException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, decaf::io::IOException)
+ DECAF_CATCHALL_THROW(decaf::io::IOException)
}
////////////////////////////////////////////////////////////////////////////////
-void TcpSocket::accept( SocketImpl* socket ) {
+void TcpSocket::accept(SocketImpl* socket) {
- try{
+ try {
- if( socket == NULL ) {
- throw IOException(
- __FILE__, __LINE__, "SocketImpl instance passed was null." );
+ if (socket == NULL) {
+ throw IOException(__FILE__, __LINE__, "SocketImpl instance passed was null.");
}
- TcpSocket* impl = dynamic_cast<TcpSocket*>( socket );
- if( impl == NULL ) {
- throw IOException(
- __FILE__, __LINE__, "SocketImpl instance passed was not a TcpSocket." );
+ TcpSocket* impl = dynamic_cast<TcpSocket*>(socket);
+ if (impl == NULL) {
+ throw IOException(__FILE__, __LINE__, "SocketImpl instance passed was not a TcpSocket.");
}
apr_status_t result = APR_SUCCESS;
// Loop to ignore any signal interruptions that occur during the operation.
do {
- result = apr_socket_accept( &impl->socketHandle, socketHandle, apr_pool.getAprPool() );
- } while( result == APR_EINTR );
-
- if( result != APR_SUCCESS ) {
- throw SocketException(
- __FILE__, __LINE__,
- "ServerSocket::accept - %s",
- SocketError::getErrorString().c_str() );
+ result = apr_socket_accept(&impl->impl->socketHandle,
+ this->impl->socketHandle,
+ this->impl->apr_pool.getAprPool());
+ } while (result == APR_EINTR);
+
+ if (result != APR_SUCCESS) {
+ throw SocketException(__FILE__, __LINE__,
+ "ServerSocket::accept - %s", SocketError::getErrorString().c_str());
}
}
- DECAF_CATCH_RETHROW( decaf::io::IOException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )
- DECAF_CATCHALL_THROW( decaf::io::IOException )
+ DECAF_CATCH_RETHROW(decaf::io::IOException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, decaf::io::IOException)
+ DECAF_CATCHALL_THROW(decaf::io::IOException)
}
////////////////////////////////////////////////////////////////////////////////
InputStream* TcpSocket::getInputStream() {
- if( this->socketHandle == NULL || this->closed ) {
- throw IOException( __FILE__, __LINE__, "The Socket is not Connected." );
+ if (this->impl->socketHandle == NULL || this->impl->closed) {
+ throw IOException(__FILE__, __LINE__, "The Socket is not Connected.");
}
- if( this->inputShutdown ) {
- throw IOException( __FILE__, __LINE__, "Input has been shut down on this Socket." );
+ if (this->impl->inputShutdown) {
+ throw IOException(__FILE__, __LINE__, "Input has been shut down on this Socket.");
}
- try{
+ try {
- if( this->inputStream == NULL ) {
- this->inputStream = new TcpSocketInputStream( this );
+ if (this->impl->inputStream == NULL) {
+ this->impl->inputStream = new TcpSocketInputStream(this);
}
- return inputStream;
+ return impl->inputStream;
}
- DECAF_CATCH_RETHROW( decaf::io::IOException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )
- DECAF_CATCHALL_THROW( decaf::io::IOException )
+ DECAF_CATCH_RETHROW(decaf::io::IOException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, decaf::io::IOException)
+ DECAF_CATCHALL_THROW(decaf::io::IOException)
}
////////////////////////////////////////////////////////////////////////////////
OutputStream* TcpSocket::getOutputStream() {
- if( this->socketHandle == NULL || this->closed ) {
- throw IOException( __FILE__, __LINE__, "The Socket is not Connected." );
+ if (this->impl->socketHandle == NULL || this->impl->closed) {
+ throw IOException(__FILE__, __LINE__, "The Socket is not Connected.");
}
- if( this->outputShutdown ) {
- throw IOException( __FILE__, __LINE__, "Output has been shut down on this Socket." );
+ if (this->impl->outputShutdown) {
+ throw IOException(__FILE__, __LINE__, "Output has been shut down on this Socket.");
}
- try{
+ try {
- if( this->outputStream == NULL ) {
- this->outputStream = new TcpSocketOutputStream( this );
+ if (this->impl->outputStream == NULL) {
+ this->impl->outputStream = new TcpSocketOutputStream(this);
}
- return outputStream;
+ return impl->outputStream;
}
- DECAF_CATCH_RETHROW( decaf::io::IOException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )
- DECAF_CATCHALL_THROW( decaf::io::IOException )
+ DECAF_CATCH_RETHROW(decaf::io::IOException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, decaf::io::IOException)
+ DECAF_CATCHALL_THROW(decaf::io::IOException)
}
////////////////////////////////////////////////////////////////////////////////
-void TcpSocket::bind( const std::string& ipaddress, int port ) {
+void TcpSocket::bind(const std::string& ipaddress, int port) {
- try{
+ try {
const char* host = ipaddress.empty() ? NULL : ipaddress.c_str();
// Create the Address Info for the Socket
apr_status_t result = apr_sockaddr_info_get(
- &localAddress, host, APR_INET, (apr_port_t)port, 0, apr_pool.getAprPool() );
+ &impl->localAddress, host, APR_INET, (apr_port_t) port, 0, impl->apr_pool.getAprPool());
- if( result != APR_SUCCESS ) {
- socketHandle = NULL;
- throw SocketException(
- __FILE__, __LINE__,
- SocketError::getErrorString().c_str() );
+ if (result != APR_SUCCESS) {
+ impl->socketHandle = NULL;
+ throw SocketException(__FILE__, __LINE__, SocketError::getErrorString().c_str());
}
// Set the socket to reuse the address and default as blocking with no timeout.
- apr_socket_opt_set( socketHandle, APR_SO_REUSEADDR, 1 );
- apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, 0 );
- apr_socket_timeout_set( socketHandle, -1 );
+ apr_socket_opt_set(impl->socketHandle, APR_SO_REUSEADDR, 1);
+ apr_socket_opt_set(impl->socketHandle, APR_SO_NONBLOCK, 0);
+ apr_socket_timeout_set(impl->socketHandle, -1);
// Bind to the Socket, this may be where we find out if the port is in use.
- result = apr_socket_bind( socketHandle, localAddress );
+ result = apr_socket_bind(impl->socketHandle, impl->localAddress);
- if( result != APR_SUCCESS ) {
+ if (result != APR_SUCCESS) {
close();
- throw SocketException(
- __FILE__, __LINE__,
- "ServerSocket::bind - %s",
- SocketError::getErrorString().c_str() );
+ throw SocketException(__FILE__, __LINE__, "ServerSocket::bind - %s", SocketError::getErrorString().c_str());
}
// Only incur the overhead of a lookup if we don't already know the local port.
- if( port != 0 ) {
+ if (port != 0) {
this->localPort = port;
} else {
apr_sockaddr_t* localAddress;
- checkResult( apr_socket_addr_get( &localAddress, APR_LOCAL, socketHandle ) );
+ checkResult(apr_socket_addr_get(&localAddress, APR_LOCAL, impl->socketHandle));
this->localPort = localAddress->port;
}
}
- DECAF_CATCH_RETHROW( decaf::io::IOException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )
- DECAF_CATCHALL_THROW( decaf::io::IOException )
+ DECAF_CATCH_RETHROW(decaf::io::IOException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, decaf::io::IOException)
+ DECAF_CATCHALL_THROW(decaf::io::IOException)
}
////////////////////////////////////////////////////////////////////////////////
-void TcpSocket::connect( const std::string& hostname, int port, int timeout ) {
+void TcpSocket::connect(const std::string& hostname, int port, int timeout) {
- try{
+ try {
- if( port < 0 || port > 65535 ) {
- throw IllegalArgumentException(
- __FILE__, __LINE__, "Given port is out of range: %d", port );
+ if (port < 0 || port > 65535) {
+ throw IllegalArgumentException(__FILE__, __LINE__, "Given port is out of range: %d", port);
}
- if( this->socketHandle == NULL ) {
- throw IOException(
- __FILE__, __LINE__, "The socket was not yet created." );
+ if (this->impl->socketHandle == NULL) {
+ throw IOException(__FILE__, __LINE__, "The socket was not yet created.");
}
// Create the Address data
- checkResult( apr_sockaddr_info_get(
- &remoteAddress, hostname.c_str(), APR_INET, (apr_port_t)port, 0, apr_pool.getAprPool() ) );
+ checkResult(apr_sockaddr_info_get(&impl->remoteAddress, hostname.c_str(), APR_INET, (apr_port_t) port, 0, impl->apr_pool.getAprPool()));
int oldNonblockSetting = 0;
apr_interval_time_t oldTimeoutSetting = 0;
// Record the old settings.
- apr_socket_opt_get( socketHandle, APR_SO_NONBLOCK, &oldNonblockSetting );
- apr_socket_timeout_get( socketHandle, &oldTimeoutSetting );
+ apr_socket_opt_get(impl->socketHandle, APR_SO_NONBLOCK, &oldNonblockSetting);
+ apr_socket_timeout_get(impl->socketHandle, &oldTimeoutSetting);
// Temporarily make it what we want, blocking.
- apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, 0 );
+ apr_socket_opt_set(impl->socketHandle, APR_SO_NONBLOCK, 0);
// Timeout and non-timeout case require very different logic.
- if( timeout <= 0 ) {
- apr_socket_timeout_set( socketHandle, -1 );
+ if (timeout <= 0) {
+ apr_socket_timeout_set(impl->socketHandle, -1);
} else {
- apr_socket_timeout_set( socketHandle, timeout * 1000 );
+ apr_socket_timeout_set(impl->socketHandle, timeout * 1000);
}
// try to Connect to the provided address.
- checkResult( apr_socket_connect( socketHandle, remoteAddress ) );
+ checkResult (apr_socket_connect(impl->socketHandle, impl->remoteAddress) );
// Now that we are connected, we want to go back to old settings.
- apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, oldNonblockSetting );
- apr_socket_timeout_set( socketHandle, oldTimeoutSetting );
+ apr_socket_opt_set(impl->socketHandle, APR_SO_NONBLOCK, oldNonblockSetting);
+ apr_socket_timeout_set(impl->socketHandle, oldTimeoutSetting);
// Now that we connected, cache the port value for later lookups.
this->port = port;
- } catch( IOException& ex ) {
- ex.setMark( __FILE__, __LINE__);
- try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
- throw ex;
- } catch( IllegalArgumentException& ex ) {
- ex.setMark( __FILE__, __LINE__);
- try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
- throw ex;
- } catch( Exception& ex ) {
- try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
- throw SocketException( &ex );
- } catch( ... ) {
- try{ close(); } catch( lang::Exception& cx){ /* Absorb */ }
- throw SocketException(
- __FILE__, __LINE__,
- "TcpSocket::connect() - caught unknown exception" );
+ } catch (IOException& ex) {
+ ex.setMark(__FILE__, __LINE__);
+ try {
+ close();
+ } catch (lang::Exception& cx) { /* Absorb */
+ }
+ throw;
+ } catch (IllegalArgumentException& ex) {
+ ex.setMark(__FILE__, __LINE__);
+ try {
+ close();
+ } catch (lang::Exception& cx) { /* Absorb */
+ }
+ throw;
+ } catch (Exception& ex) {
+ try {
+ close();
+ } catch (lang::Exception& cx) { /* Absorb */
+ }
+ throw SocketException(&ex);
+ } catch (...) {
+ try {
+ close();
+ } catch (lang::Exception& cx) { /* Absorb */
+ }
+ throw SocketException(__FILE__, __LINE__, "TcpSocket::connect() - caught unknown exception");
}
}
////////////////////////////////////////////////////////////////////////////////
std::string TcpSocket::getLocalAddress() const {
- if( !isClosed() ) {
- SocketAddress addr;
- checkResult( apr_socket_addr_get( &addr, APR_LOCAL, this->socketHandle ) );
- char ipStr[20] = {0};
- checkResult( apr_sockaddr_ip_getbuf( ipStr, 20, addr ) );
+ if (!isClosed()) {
+ apr_sockaddr_t* addr;
+ checkResult(apr_socket_addr_get(&addr, APR_LOCAL, this->impl->socketHandle));
+ char ipStr[20] = { 0 };
+ checkResult(apr_sockaddr_ip_getbuf(ipStr, 20, addr));
- return std::string( ipStr, 20 );
+ return std::string(ipStr, 20);
}
return "0.0.0.0";
}
////////////////////////////////////////////////////////////////////////////////
-void TcpSocket::listen( int backlog ) {
+void TcpSocket::listen(int backlog) {
- try{
+ try {
- if( isClosed() ){
- throw IOException(
- __FILE__, __LINE__, "The stream is closed" );
+ if (isClosed()) {
+ throw IOException(__FILE__, __LINE__, "The stream is closed");
}
// Setup the listen for incoming connection requests
- apr_status_t result = apr_socket_listen( socketHandle, backlog );
+ apr_status_t result = apr_socket_listen(impl->socketHandle, backlog);
- if( result != APR_SUCCESS ) {
+ if (result != APR_SUCCESS) {
close();
- throw SocketException(
- __FILE__, __LINE__, "Error on Bind - %s",
- SocketError::getErrorString().c_str() );
+ throw SocketException(__FILE__, __LINE__, "Error on Bind - %s", SocketError::getErrorString().c_str());
}
}
- DECAF_CATCH_RETHROW( decaf::io::IOException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )
- DECAF_CATCHALL_THROW( decaf::io::IOException )
+ DECAF_CATCH_RETHROW(decaf::io::IOException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, decaf::io::IOException)
+ DECAF_CATCHALL_THROW(decaf::io::IOException)
}
////////////////////////////////////////////////////////////////////////////////
int TcpSocket::available() {
- if( isClosed() ){
- throw IOException(
- __FILE__, __LINE__, "The stream is closed" );
+ if (isClosed()) {
+ throw IOException(__FILE__, __LINE__, "The stream is closed");
}
// Convert to an OS level socket.
apr_os_sock_t oss;
- apr_os_sock_get( (apr_os_sock_t*)&oss, socketHandle );
+ apr_os_sock_get((apr_os_sock_t*) &oss, impl->socketHandle);
// The windows version
#if defined(HAVE_WINSOCK2_H)
unsigned long numBytes = 0;
- if( ::ioctlsocket( oss, FIONREAD, &numBytes ) == SOCKET_ERROR ){
+ if( ::ioctlsocket( oss, FIONREAD, &numBytes ) == SOCKET_ERROR ) {
throw SocketException( __FILE__, __LINE__, "ioctlsocket failed" );
}
return numBytes;
#else // !defined(HAVE_WINSOCK2_H)
-
// If FIONREAD is defined - use ioctl to find out how many bytes
// are available.
- #if defined(FIONREAD)
+#if defined(FIONREAD)
- int numBytes = 0;
- if( ::ioctl( oss, FIONREAD, &numBytes ) != -1 ){
- return numBytes;
- }
+ int numBytes = 0;
+ if (::ioctl(oss, FIONREAD, &numBytes) != -1) {
+ return numBytes;
+ }
- #endif
+#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)
+#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;
+ 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
+#else
- return 0;
+ return 0;
- #endif /* HAVE_SELECT */
+#endif /* HAVE_SELECT */
#endif // !defined(HAVE_WINSOCK2_H)
}
@@ -425,309 +452,289 @@ int TcpSocket::available() {
////////////////////////////////////////////////////////////////////////////////
void TcpSocket::close() {
- try{
+ try {
- if( this->closed ) {
+ if (this->impl->closed) {
return;
}
- this->closed = true;
+ this->impl->closed = true;
// Destroy the input stream.
- if( inputStream != NULL ){
- inputStream->close();
+ if (impl->inputStream != NULL) {
+ impl->inputStream->close();
}
// Destroy the output stream.
- if( outputStream != NULL ){
- outputStream->close();
+ if (impl->outputStream != NULL) {
+ impl->outputStream->close();
}
// When connected we first shutdown, which breaks our reads and writes
// then we close to free APR resources.
- if( isConnected() ) {
- // Destory the allocated resources.
- apr_socket_shutdown( socketHandle, APR_SHUTDOWN_READWRITE );
- apr_socket_close( socketHandle );
+ if (isConnected()) {
+ apr_socket_shutdown(impl->socketHandle, APR_SHUTDOWN_READWRITE);
+ apr_socket_close(this->impl->socketHandle);
delete this->fd;
// Clear out the member data.
- this->socketHandle = NULL;
+ this->impl->socketHandle = NULL;
this->port = 0;
this->localPort = 0;
}
}
- DECAF_CATCH_RETHROW( decaf::io::IOException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::io::IOException )
- DECAF_CATCHALL_THROW( decaf::io::IOException )
+ DECAF_CATCH_RETHROW(decaf::io::IOException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, decaf::io::IOException)
+ DECAF_CATCHALL_THROW(decaf::io::IOException)
}
////////////////////////////////////////////////////////////////////////////////
void TcpSocket::shutdownInput() {
- if( isClosed() ){
- throw IOException(
- __FILE__, __LINE__, "The stream is closed" );
+ if (isClosed()) {
+ throw IOException(__FILE__, __LINE__, "The stream is closed");
}
- this->inputShutdown = true;
- apr_socket_shutdown( socketHandle, APR_SHUTDOWN_READ );
+ this->impl->inputShutdown = true;
+ apr_socket_shutdown(impl->socketHandle, APR_SHUTDOWN_READ);
}
////////////////////////////////////////////////////////////////////////////////
void TcpSocket::shutdownOutput() {
- if( isClosed() ){
- throw IOException(
- __FILE__, __LINE__, "The stream is closed" );
+ if (isClosed()) {
+ throw IOException(__FILE__, __LINE__, "The stream is closed");
}
- this->outputShutdown = true;
- apr_socket_shutdown( socketHandle, APR_SHUTDOWN_WRITE );
+ this->impl->outputShutdown = true;
+ apr_socket_shutdown(impl->socketHandle, APR_SHUTDOWN_WRITE);
}
////////////////////////////////////////////////////////////////////////////////
-int TcpSocket::getOption( int option ) const {
+int TcpSocket::getOption(int option) const {
- try{
+ try {
- if( isClosed() ) {
- throw IOException(
- __FILE__, __LINE__, "The Socket is closed." );
+ if (isClosed()) {
+ throw IOException(__FILE__, __LINE__, "The Socket is closed.");
}
apr_int32_t aprId = 0;
apr_int32_t value = 0;
- if( option == SocketOptions::SOCKET_OPTION_TIMEOUT ) {
+ if (option == SocketOptions::SOCKET_OPTION_TIMEOUT) {
// Time in APR on socket is stored in microseconds.
apr_interval_time_t tvalue = 0;
- checkResult( apr_socket_timeout_get( socketHandle, &tvalue ) );
- return (int)( tvalue / 1000 );
- } else if( option == SocketOptions::SOCKET_OPTION_LINGER ) {
+ checkResult(apr_socket_timeout_get(impl->socketHandle, &tvalue));
+ return (int) (tvalue / 1000);
+ } else if (option == SocketOptions::SOCKET_OPTION_LINGER) {
- checkResult( apr_socket_opt_get( socketHandle, APR_SO_LINGER, &value ) );
+ checkResult(apr_socket_opt_get(impl->socketHandle, APR_SO_LINGER, &value));
// In case the socket linger is on by default we reset to match,
// we just use one since we really don't know what the linger time is
// with APR.
- if( value == 1 && this->soLinger == -1 ) {
- this->soLinger = 1;
+ if (value == 1 && this->impl->soLinger == -1) {
+ this->impl->soLinger = 1;
}
- return this->soLinger;
+ return this->impl->soLinger;
}
- if( option == SocketOptions::SOCKET_OPTION_REUSEADDR ) {
+ if (option == SocketOptions::SOCKET_OPTION_REUSEADDR) {
aprId = APR_SO_REUSEADDR;
- } else if( option == SocketOptions::SOCKET_OPTION_SNDBUF ) {
+ } else if (option == SocketOptions::SOCKET_OPTION_SNDBUF) {
aprId = APR_SO_SNDBUF;
- } else if( option == SocketOptions::SOCKET_OPTION_RCVBUF ) {
+ } else if (option == SocketOptions::SOCKET_OPTION_RCVBUF) {
aprId = APR_SO_RCVBUF;
- } else if( option == SocketOptions::SOCKET_OPTION_TCP_NODELAY ) {
+ } else if (option == SocketOptions::SOCKET_OPTION_TCP_NODELAY) {
aprId = APR_TCP_NODELAY;
- } else if( option == SocketOptions::SOCKET_OPTION_KEEPALIVE ) {
+ } else if (option == SocketOptions::SOCKET_OPTION_KEEPALIVE) {
aprId = APR_SO_KEEPALIVE;
} else {
- throw IOException(
- __FILE__, __LINE__,
- "Socket Option is not valid for this Socket type." );
+ throw IOException(__FILE__, __LINE__, "Socket Option is not valid for this Socket type.");
}
- checkResult( apr_socket_opt_get( socketHandle, aprId, &value ) );
+ checkResult(apr_socket_opt_get(impl->socketHandle, aprId, &value));
- return (int)value;
+ return (int) value;
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCHALL_THROW(IOException)
}
////////////////////////////////////////////////////////////////////////////////
-void TcpSocket::setOption( int option, int value ) {
+void TcpSocket::setOption(int option, int value) {
- try{
+ try {
- if( isClosed() ) {
- throw IOException(
- __FILE__, __LINE__, "The Socket is closed." );
+ if (isClosed()) {
+ throw IOException(__FILE__, __LINE__, "The Socket is closed.");
}
apr_int32_t aprId = 0;
- if( option == SocketOptions::SOCKET_OPTION_TIMEOUT ) {
- checkResult( apr_socket_opt_set( socketHandle, APR_SO_NONBLOCK, 0 ) );
+ if (option == SocketOptions::SOCKET_OPTION_TIMEOUT) {
+ checkResult(apr_socket_opt_set(impl->socketHandle, APR_SO_NONBLOCK, 0));
// Time in APR for sockets is in microseconds so multiply by 1000.
- checkResult( apr_socket_timeout_set( socketHandle, value * 1000 ) );
- this->soTimeout = value;
+ checkResult(apr_socket_timeout_set(impl->socketHandle, value * 1000));
+ this->impl->soTimeout = value;
return;
- } else if( option == SocketOptions::SOCKET_OPTION_LINGER ) {
+ } else if (option == SocketOptions::SOCKET_OPTION_LINGER) {
// Store the real setting for later.
- this->soLinger = value;
+ this->impl->soLinger = value;
// Now use the APR API to set it to the boolean state that APR expects
value = value <= 0 ? 0 : 1;
- checkResult( apr_socket_opt_set( socketHandle, APR_SO_LINGER, (apr_int32_t)value ) );
+ checkResult(apr_socket_opt_set(impl->socketHandle, APR_SO_LINGER, (apr_int32_t) value));
return;
}
- if( option == SocketOptions::SOCKET_OPTION_REUSEADDR ) {
+ if (option == SocketOptions::SOCKET_OPTION_REUSEADDR) {
aprId = APR_SO_REUSEADDR;
- } else if( option == SocketOptions::SOCKET_OPTION_SNDBUF ) {
+ } else if (option == SocketOptions::SOCKET_OPTION_SNDBUF) {
aprId = APR_SO_SNDBUF;
- } else if( option == SocketOptions::SOCKET_OPTION_RCVBUF ) {
+ } else if (option == SocketOptions::SOCKET_OPTION_RCVBUF) {
aprId = APR_SO_RCVBUF;
- } else if( option == SocketOptions::SOCKET_OPTION_TCP_NODELAY ) {
+ } else if (option == SocketOptions::SOCKET_OPTION_TCP_NODELAY) {
aprId = APR_TCP_NODELAY;
- } else if( option == SocketOptions::SOCKET_OPTION_KEEPALIVE ) {
+ } else if (option == SocketOptions::SOCKET_OPTION_KEEPALIVE) {
aprId = APR_SO_KEEPALIVE;
} else {
- throw IOException(
- __FILE__, __LINE__,
- "Socket Option is not valid for this Socket type." );
+ throw IOException(__FILE__, __LINE__, "Socket Option is not valid for this Socket type.");
}
- checkResult( apr_socket_opt_set( socketHandle, aprId, (apr_int32_t)value ) );
+ checkResult(apr_socket_opt_set(impl->socketHandle, aprId, (apr_int32_t) value));
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCHALL_THROW(IOException)
}
////////////////////////////////////////////////////////////////////////////////
-void TcpSocket::checkResult( apr_status_t value ) const {
+void TcpSocket::checkResult(apr_status_t value) const {
- if( value != APR_SUCCESS ){
- throw SocketException(
- __FILE__, __LINE__,
- SocketError::getErrorString().c_str() );
+ if (value != APR_SUCCESS) {
+ throw SocketException(__FILE__, __LINE__, SocketError::getErrorString().c_str());
}
}
////////////////////////////////////////////////////////////////////////////////
-int TcpSocket::read( unsigned char* buffer, int size, int offset, int length ) {
+int TcpSocket::read(unsigned char* buffer, int size, int offset, int length) {
- try{
- if( this->isClosed() ){
- throw IOException(
- __FILE__, __LINE__, "The Stream has been closed" );
+ try {
+ if (this->isClosed()) {
+ throw IOException(__FILE__, __LINE__, "The Stream has been closed");
}
- if( this->inputShutdown == true ) {
+ if (this->impl->inputShutdown == true) {
return -1;
}
- if( length == 0 ) {
+ if (length == 0) {
return 0;
}
- if( buffer == NULL ) {
- throw NullPointerException(
- __FILE__, __LINE__, "Buffer passed is Null" );
+ if (buffer == NULL) {
+ throw NullPointerException(__FILE__, __LINE__, "Buffer passed is Null");
}
- if( size < 0 ) {
- throw IndexOutOfBoundsException(
- __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+ if (size < 0) {
+ throw IndexOutOfBoundsException(__FILE__, __LINE__,
+ "size parameter out of Bounds: %d.", size);
}
- if( offset > size || offset < 0 ) {
- throw IndexOutOfBoundsException(
- __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+ if (offset > size || offset < 0) {
+ throw IndexOutOfBoundsException(__FILE__, __LINE__,
+ "offset parameter out of Bounds: %d.", offset);
}
- if( length < 0 || length > size - offset ) {
- throw IndexOutOfBoundsException(
- __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+ if (length < 0 || length > size - offset) {
+ throw IndexOutOfBoundsException(__FILE__, __LINE__,
+ "length parameter out of Bounds: %d.", length);
}
- apr_size_t aprSize = (apr_size_t)length;
+ apr_size_t aprSize = (apr_size_t) length;
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( socketHandle, (char*)buffer + offset, &aprSize );
+ result = apr_socket_recv(impl->socketHandle, (char*) buffer + offset, &aprSize);
// 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 ) || aprSize == 0 ) && !closed ) {
- this->inputShutdown = true;
+ if ((APR_STATUS_IS_EOF( result ) || aprSize == 0) && !impl->closed) {
+ this->impl->inputShutdown = true;
return -1;
}
- if( isClosed() ){
- throw IOException(
- __FILE__, __LINE__, "The connection is closed" );
+ if (isClosed()) {
+ throw IOException(__FILE__, __LINE__, "The connection is closed");
}
- if( result != APR_SUCCESS ){
- throw IOException(
- __FILE__, __LINE__,
- "Socket Read Error - %s",
- SocketError::getErrorString().c_str() );
+ if (result != APR_SUCCESS) {
+ throw IOException(__FILE__, __LINE__,
+ "Socket Read Error - %s", SocketError::getErrorString().c_str());
}
- return (int)aprSize;
+ return (int) aprSize;
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCH_RETHROW( NullPointerException )
- DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCH_RETHROW(NullPointerException)
+ DECAF_CATCH_RETHROW(IndexOutOfBoundsException)
+ DECAF_CATCHALL_THROW(IOException)
}
////////////////////////////////////////////////////////////////////////////////
-void TcpSocket::write( const unsigned char* buffer, int size, int offset, int length ) {
+void TcpSocket::write(const unsigned char* buffer, int size, int offset, int length) {
- try{
+ try {
- if( length == 0 ) {
+ if (length == 0) {
return;
}
- if( buffer == NULL ) {
- throw NullPointerException(
- __FILE__, __LINE__,
- "TcpSocketOutputStream::write - passed buffer is null" );
+ if (buffer == NULL) {
+ throw NullPointerException(__FILE__, __LINE__,
+ "TcpSocket::write - passed buffer is null");
}
- if( closed ) {
- throw IOException(
- __FILE__, __LINE__,
- "TcpSocketOutputStream::write - This Stream has been closed." );
+ if (this->impl->closed) {
+ throw IOException(__FILE__, __LINE__,
+ "TcpSocket::write - This Stream has been closed.");
}
- if( size < 0 ) {
- throw IndexOutOfBoundsException(
- __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+ if (size < 0) {
+ throw IndexOutOfBoundsException(__FILE__, __LINE__,
+ "size parameter out of Bounds: %d.", size);
}
- if( offset > size || offset < 0 ) {
- throw IndexOutOfBoundsException(
- __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+ if (offset > size || offset < 0) {
+ throw IndexOutOfBoundsException(__FILE__, __LINE__,
+ "offset parameter out of Bounds: %d.", offset);
}
- if( length < 0 || length > size - offset ) {
- throw IndexOutOfBoundsException(
- __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+ if (length < 0 || length > size - offset) {
+ throw IndexOutOfBoundsException(__FILE__, __LINE__,
+ "length parameter out of Bounds: %d.", length);
}
- apr_size_t remaining = (apr_size_t)length;
+ apr_size_t remaining = (apr_size_t) length;
apr_status_t result = APR_SUCCESS;
const unsigned char* lbuffer = buffer + offset;
- while( remaining > 0 && !closed ) {
+ while (remaining > 0 && !this->impl->closed) {
// On input remaining is the bytes to send, after return remaining
// is the amount actually sent.
- result = apr_socket_send( socketHandle, (const char*)lbuffer, &remaining );
+ result = apr_socket_send(this->impl->socketHandle, (const char*) lbuffer, &remaining);
- if( result != APR_SUCCESS || closed ) {
- throw IOException(
- __FILE__, __LINE__,
- "decaf::net::TcpSocketOutputStream::write - %s",
- SocketError::getErrorString().c_str() );
+ if (result != APR_SUCCESS || this->impl->closed) {
+ throw IOException(__FILE__, __LINE__,
+ "TcpSocketOutputStream::write - %s", SocketError::getErrorString().c_str());
}
// move us to next position to write, or maybe end.
@@ -735,8 +742,18 @@ void TcpSocket::write( const unsigned ch
remaining = length - remaining;
}
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCH_RETHROW( NullPointerException )
- DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCH_RETHROW(NullPointerException)
+ DECAF_CATCH_RETHROW(IndexOutOfBoundsException)
+ DECAF_CATCHALL_THROW(IOException)
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool TcpSocket::isConnected() const {
+ return this->impl->socketHandle != NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool TcpSocket::isClosed() const {
+ return this->impl->closed;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.h?rev=1448855&r1=1448854&r2=1448855&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocket.h Thu Feb 21 23:38:03 2013
@@ -23,9 +23,6 @@
#include <decaf/io/OutputStream.h>
#include <decaf/util/Config.h>
#include <decaf/internal/AprPool.h>
-
-#include <apr_network_io.h>
-
#include <decaf/io/IOException.h>
#include <decaf/net/SocketTimeoutException.h>
#include <decaf/lang/exceptions/NullPointerException.h>
@@ -36,93 +33,22 @@ namespace internal {
namespace net {
namespace tcp {
- // Forward declarations
class TcpSocketInputStream;
class TcpSocketOutputStream;
+ class TcpSocketImpl;
/**
* Platform-independent implementation of the socket interface.
*/
- class DECAF_API TcpSocket : public decaf::net::SocketImpl {
- private:
-
- /**
- * Define the SocketHandle type.
- */
- typedef apr_socket_t* SocketHandle;
-
- /**
- * Define the SocketAddress type
- */
- typedef apr_sockaddr_t* SocketAddress;
-
+ class DECAF_API TcpSocket: public decaf::net::SocketImpl {
private:
- TcpSocket( const TcpSocket& );
- TcpSocket& operator= ( const TcpSocket& );
+ TcpSocketImpl* impl;
private:
- /**
- * APR Socket Pool to allocate from
- */
- decaf::internal::AprPool apr_pool;
-
- /**
- * The handle for this socket.
- */
- SocketHandle socketHandle;
-
- /**
- * Address of the locally bound portion of the Socket.
- */
- SocketAddress localAddress;
-
- /**
- * Address of the remoute connection portion of the Socket.
- */
- SocketAddress remoteAddress;
-
- /**
- * The input stream for reading this socket.
- */
- TcpSocketInputStream* inputStream;
-
- /**
- * The output stream for writing to this socket.
- */
- TcpSocketOutputStream* outputStream;
-
- /**
- * Was input already shutdown on this Socket.
- */
- bool inputShutdown;
-
- /**
- * Was output already shutdown on this Socket.
- */
- bool outputShutdown;
-
- /**
- * Was the Socket closed.
- */
- volatile bool closed;
-
- /**
- * Current Traffic class setting.
- */
- int trafficClass;
-
- /**
- * value of soTimeout used to handle timeout on accept calls.
- */
- int soTimeout;
-
- /**
- * value of soLinger, used to return a meaningful answer since APR
- * only returns the on / off state.
- */
- mutable int soLinger;
+ TcpSocket(const TcpSocket&);
+ TcpSocket& operator=(const TcpSocket&);
public:
@@ -139,26 +65,14 @@ namespace tcp {
virtual ~TcpSocket();
/**
- * Gets the handle for the socket.
- * @return SocketHabler for this Socket, can be NULL
- */
- SocketHandle getSocketHandle () {
- return socketHandle;
- }
-
- /**
* @returns true if the socketHandle is not in a disconnected state.
*/
- bool isConnected() const {
- return socketHandle != NULL;
- }
+ bool isConnected() const;
/**
* @returns true if the close method has been called on this Socket.
*/
- bool isClosed() const {
- return this->closed;
- }
+ bool isClosed() const;
/**
* {@inheritDoc}
@@ -173,22 +87,22 @@ namespace tcp {
/**
* {@inheritDoc}
*/
- virtual void accept( SocketImpl* socket );
+ virtual void accept(SocketImpl* socket);
/**
* {@inheritDoc}
*/
- virtual void bind( const std::string& ipaddress, int port );
+ virtual void bind(const std::string& ipaddress, int port);
/**
* {@inheritDoc}
*/
- virtual void connect( const std::string& hostname, int port, int timeout );
+ virtual void connect(const std::string& hostname, int port, int timeout);
/**
* {@inheritDoc}
*/
- virtual void listen( int backlog );
+ virtual void listen(int backlog);
/**
* {@inheritDoc}
@@ -223,12 +137,12 @@ namespace tcp {
/**
* {@inheritDoc}
*/
- virtual int getOption( int option ) const;
+ virtual int getOption(int option) const;
/**
* {@inheritDoc}
*/
- virtual void setOption( int option, int value );
+ virtual void setOption(int option, int value);
public:
@@ -250,7 +164,7 @@ namespace tcp {
* @throw NullPointerException if buffer is Null.
* @throw IndexOutOfBoundsException if offset + length is greater than buffer size.
*/
- int read( unsigned char* buffer, int size, int offset, int length );
+ int read(unsigned char* buffer, int size, int offset, int length);
/**
* Writes the specified data in the passed in buffer to the Socket.
@@ -268,11 +182,11 @@ namespace tcp {
* @throw NullPointerException if buffer is Null.
* @throw IndexOutOfBoundsException if offset + length is greater than buffer size.
*/
- void write( const unsigned char* buffer, int size, int offset, int length );
+ void write(const unsigned char* buffer, int size, int offset, int length);
protected:
- void checkResult( apr_status_t value ) const;
+ void checkResult(apr_status_t value) const;
};
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.cpp?rev=1448855&r1=1448854&r2=1448855&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.cpp Thu Feb 21 23:38:03 2013
@@ -33,12 +33,11 @@ using namespace decaf::lang::exceptions;
using namespace std;
////////////////////////////////////////////////////////////////////////////////
-TcpSocketInputStream::TcpSocketInputStream( TcpSocket* socket ) :
- InputStream(), socket( socket ), closed( false ) {
+TcpSocketInputStream::TcpSocketInputStream(TcpSocket* socket) :
+ InputStream(), socket(socket), closed(false) {
- if( socket == NULL ) {
- throw NullPointerException(
- __FILE__, __LINE__, "TcpSocket instance passed was NULL." );
+ if (socket == NULL) {
+ throw NullPointerException(__FILE__, __LINE__, "TcpSocket instance passed was NULL.");
}
}
@@ -49,24 +48,23 @@ TcpSocketInputStream::~TcpSocketInputStr
////////////////////////////////////////////////////////////////////////////////
void TcpSocketInputStream::close() {
- if( this->closed ) {
+ if (this->closed) {
return;
}
- try{
+ try {
this->closed = true;
this->socket->close();
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCHALL_THROW(IOException)
}
////////////////////////////////////////////////////////////////////////////////
int TcpSocketInputStream::available() const {
- if( this->closed ){
- throw IOException(
- __FILE__, __LINE__, "The stream is closed" );
+ if (this->closed) {
+ throw IOException(__FILE__, __LINE__, "The stream is closed");
}
return this->socket->available();
@@ -75,58 +73,55 @@ int TcpSocketInputStream::available() co
////////////////////////////////////////////////////////////////////////////////
int TcpSocketInputStream::doReadByte() {
- if( this->closed ){
- throw IOException(
- __FILE__, __LINE__, "The stream is closed" );
+ if (this->closed) {
+ throw IOException(__FILE__, __LINE__, "The stream is closed");
}
- try{
+ try {
unsigned char buffer[1];
- int result = this->socket->read( buffer, 1, 0, 1 );
+ int result = this->socket->read(buffer, 1, 0, 1);
return result == -1 ? result : buffer[0];
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, IOException)
+ DECAF_CATCHALL_THROW(IOException)
}
////////////////////////////////////////////////////////////////////////////////
-int TcpSocketInputStream::doReadArrayBounded( unsigned char* buffer, int size, int offset, int length ) {
+int TcpSocketInputStream::doReadArrayBounded(unsigned char* buffer, int size, int offset, int length) {
- if( closed ){
- throw IOException(
- __FILE__, __LINE__, "The stream is closed" );
+ if (closed) {
+ throw IOException(__FILE__, __LINE__, "The stream is closed");
}
- if( buffer == NULL ) {
- throw NullPointerException(
- __FILE__, __LINE__, "Buffer passed was NULL." );
+ if (buffer == NULL) {
+ throw NullPointerException(__FILE__, __LINE__, "Buffer passed was NULL.");
}
- try{
- return this->socket->read( buffer, size, offset, length );
+ try {
+ return this->socket->read(buffer, size, offset, length);
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
- DECAF_CATCH_RETHROW( NullPointerException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCH_RETHROW(IndexOutOfBoundsException)
+ DECAF_CATCH_RETHROW(NullPointerException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, IOException)
+ DECAF_CATCHALL_THROW(IOException)
}
////////////////////////////////////////////////////////////////////////////////
-long long TcpSocketInputStream::skip( long long num ) {
+long long TcpSocketInputStream::skip(long long num) {
- try{
+ try {
- if( num == 0 ) {
+ if (num == 0) {
return 0;
}
- return InputStream::skip( num );
+ return InputStream::skip(num);
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCH_RETHROW( UnsupportedOperationException )
- DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCH_RETHROW(UnsupportedOperationException)
+ DECAF_CATCH_EXCEPTION_CONVERT(Exception, IOException)
+ DECAF_CATCHALL_THROW(IOException)
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h?rev=1448855&r1=1448854&r2=1448855&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketInputStream.h Thu Feb 21 23:38:03 2013
@@ -38,7 +38,7 @@ namespace tcp {
*
* @since 1.0
*/
- class DECAF_API TcpSocketInputStream : public decaf::io::InputStream {
+ class DECAF_API TcpSocketInputStream: public decaf::io::InputStream {
private:
TcpSocket* socket;
@@ -47,8 +47,8 @@ namespace tcp {
private:
- TcpSocketInputStream( const TcpSocketInputStream& );
- TcpSocketInputStream& operator= ( const TcpSocketInputStream& );
+ TcpSocketInputStream(const TcpSocketInputStream&);
+ TcpSocketInputStream& operator=(const TcpSocketInputStream&);
public:
@@ -58,7 +58,7 @@ namespace tcp {
* @param socket
* The parent SocketImpl for this stream.
*/
- TcpSocketInputStream( TcpSocket* socket );
+ TcpSocketInputStream(TcpSocket* socket);
virtual ~TcpSocketInputStream();
@@ -80,13 +80,13 @@ namespace tcp {
*
* {@inheritDoc}
*/
- virtual long long skip( long long num );
+ virtual long long skip(long long num);
protected:
virtual int doReadByte();
- virtual int doReadArrayBounded( unsigned char* buffer, int size, int offset, int length );
+ virtual int doReadArrayBounded(unsigned char* buffer, int size, int offset, int length);
};
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.cpp?rev=1448855&r1=1448854&r2=1448855&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.cpp Thu Feb 21 23:38:03 2013
@@ -35,12 +35,11 @@ using namespace decaf::lang::exceptions;
using namespace std;
////////////////////////////////////////////////////////////////////////////////
-TcpSocketOutputStream::TcpSocketOutputStream( TcpSocket* socket ) :
- OutputStream(), socket( socket ), closed( false ) {
+TcpSocketOutputStream::TcpSocketOutputStream(TcpSocket* socket) :
+ OutputStream(), socket(socket), closed(false) {
- if( socket == NULL ) {
- throw NullPointerException(
- __FILE__, __LINE__, "TcpSocket instance passed was NULL." );
+ if (socket == NULL) {
+ throw NullPointerException(__FILE__, __LINE__, "TcpSocket instance passed was NULL.");
}
}
@@ -51,55 +50,53 @@ TcpSocketOutputStream::~TcpSocketOutputS
////////////////////////////////////////////////////////////////////////////////
void TcpSocketOutputStream::close() {
- if( this->closed ) {
+ if (this->closed) {
return;
}
- try{
+ try {
this->closed = true;
this->socket->close();
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCHALL_THROW(IOException)
}
////////////////////////////////////////////////////////////////////////////////
-void TcpSocketOutputStream::doWriteByte( unsigned char c ) {
+void TcpSocketOutputStream::doWriteByte(unsigned char c) {
- try{
+ try {
// Treat the single byte case the same as an array.
- this->doWriteArrayBounded( &c, 1, 0, 1 );
+ this->doWriteArrayBounded(&c, 1, 0, 1);
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCHALL_THROW(IOException)
}
////////////////////////////////////////////////////////////////////////////////
-void TcpSocketOutputStream::doWriteArrayBounded( const unsigned char* buffer, int size, int offset, int length ) {
+void TcpSocketOutputStream::doWriteArrayBounded(const unsigned char* buffer, int size, int offset, int length) {
- try{
+ try {
- if( length == 0 ) {
+ if (length == 0) {
return;
}
- if( buffer == NULL ) {
- throw NullPointerException(
- __FILE__, __LINE__,
- "TcpSocketOutputStream::write - passed buffer is null" );
+ if (buffer == NULL) {
+ throw NullPointerException(__FILE__, __LINE__,
+ "TcpSocketOutputStream::write - passed buffer is null");
}
- if( closed ) {
- throw IOException(
- __FILE__, __LINE__,
- "TcpSocketOutputStream::write - This Stream has been closed." );
+ if (closed) {
+ throw IOException(__FILE__, __LINE__,
+ "TcpSocketOutputStream::write - This Stream has been closed.");
}
- this->socket->write( buffer, size, offset, length );
+ this->socket->write(buffer, size, offset, length);
}
- DECAF_CATCH_RETHROW( IOException )
- DECAF_CATCH_RETHROW( NullPointerException )
- DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
- DECAF_CATCHALL_THROW( IOException )
+ DECAF_CATCH_RETHROW(IOException)
+ DECAF_CATCH_RETHROW(NullPointerException)
+ DECAF_CATCH_RETHROW(IndexOutOfBoundsException)
+ DECAF_CATCHALL_THROW(IOException)
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.h?rev=1448855&r1=1448854&r2=1448855&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/tcp/TcpSocketOutputStream.h Thu Feb 21 23:38:03 2013
@@ -34,7 +34,7 @@ namespace tcp {
*
* @since 1.0
*/
- class DECAF_API TcpSocketOutputStream : public decaf::io::OutputStream {
+ class DECAF_API TcpSocketOutputStream: public decaf::io::OutputStream {
private:
TcpSocket* socket;
@@ -42,8 +42,8 @@ namespace tcp {
private:
- TcpSocketOutputStream( const TcpSocketOutputStream& );
- TcpSocketOutputStream& operator= ( const TcpSocketOutputStream& );
+ TcpSocketOutputStream(const TcpSocketOutputStream&);
+ TcpSocketOutputStream& operator=(const TcpSocketOutputStream&);
public:
@@ -53,7 +53,7 @@ namespace tcp {
* @param socket
* The socket to use to write out the data.
*/
- TcpSocketOutputStream( TcpSocket* socket );
+ TcpSocketOutputStream(TcpSocket* socket);
virtual ~TcpSocketOutputStream();
@@ -61,9 +61,9 @@ namespace tcp {
protected:
- virtual void doWriteByte( unsigned char c );
+ virtual void doWriteByte(unsigned char c);
- virtual void doWriteArrayBounded( const unsigned char* buffer, int size, int offset, int length );
+ virtual void doWriteArrayBounded(const unsigned char* buffer, int size, int offset, int length);
};