Author: nmittler
Date: Mon Feb 12 17:07:03 2007
New Revision: 506787
URL: http://svn.apache.org/viewvc?view=rev&rev=506787
Log:
[AMQCPP-30] changing socket tracing to use logger. Enabled with url property "tcpTracingEnabled=true"
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.h
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterInputStream.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterOutputStream.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketFactory.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Mon Feb 12 17:07:03 2007
@@ -36,6 +36,8 @@
activemq/io/DataOutputStream.cpp \
activemq/io/BufferedOutputStream.cpp \
activemq/io/ByteArrayOutputStream.cpp \
+ activemq/io/LoggingInputStream.cpp \
+ activemq/io/LoggingOutputStream.cpp \
activemq/concurrent/PooledThread.cpp \
activemq/concurrent/ThreadPool.cpp \
activemq/concurrent/Mutex.cpp \
@@ -128,6 +130,8 @@
activemq/io/DataInputStream.h \
activemq/io/Writer.h \
activemq/io/ByteArrayOutputStream.h \
+ activemq/io/LoggingInputStream.h \
+ activemq/io/LoggingOutputStream.h \
activemq/io/OutputStream.h \
activemq/io/IOException.h \
activemq/io/FilterInputStream.h \
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterInputStream.h?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterInputStream.h Mon
Feb 12 17:07:03 2007
@@ -130,6 +130,31 @@
AMQ_CATCH_RETHROW( IOException )
AMQ_CATCHALL_THROW( IOException )
}
+
+ /**
+ * Skips over and discards n bytes of data from this input stream. The
+ * skip method may, for a variety of reasons, end up skipping over some
+ * smaller number of bytes, possibly 0. This may result from any of a
+ * number of conditions; reaching end of file before n bytes have been
+ * skipped is only one possibility. The actual number of bytes skipped
+ * is returned. If n is negative, no bytes are skipped.
+ * <p>
+ * The skip method of InputStream creates a byte array and then
+ * repeatedly reads into it until n bytes have been read or the end
+ * of the stream has been reached. Subclasses are encouraged to
+ * provide a more efficient implementation of this method.
+ * @param num - the number of bytes to skip
+ * @returns total butes skipped
+ * @throws IOException if an error occurs
+ */
+ virtual std::size_t skip( std::size_t num ) throw ( io::IOException, exceptions::UnsupportedOperationException
) {
+ try {
+ return inputStream->skip(num);
+ }
+ AMQ_CATCH_RETHROW( exceptions::UnsupportedOperationException )
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCHALL_THROW( IOException )
+ }
public: // Synchronizable
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterOutputStream.h?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterOutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/FilterOutputStream.h Mon
Feb 12 17:07:03 2007
@@ -63,6 +63,8 @@
/**
* Constructor, creates a wrapped output stream
* @param outputStream the OutputStream to wrap
+ * @param own If true, this object will control the lifetime of the
+ * output stream that it encapsulates.
*/
FilterOutputStream( OutputStream* outputStream, bool own = false ){
this->outputStream = outputStream;
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.cpp?view=auto&rev=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.cpp Mon
Feb 12 17:07:03 2007
@@ -0,0 +1,86 @@
+/*
+ * 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 "LoggingInputStream.h"
+#include <sstream>
+#include <iomanip>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::io;
+
+LOGCMS_INITIALIZE( logger, LoggingInputStream, "activemq.io.LoggingInputStream")
+
+////////////////////////////////////////////////////////////////////////////////
+LoggingInputStream::LoggingInputStream( InputStream* inputStream, bool own )
+ : FilterInputStream( inputStream, own )
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LoggingInputStream::~LoggingInputStream()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char LoggingInputStream::read() throw ( IOException ) {
+ try {
+ unsigned char c = FilterInputStream::read();
+
+ log( &c, 1 );
+
+ return c;
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t LoggingInputStream::read( unsigned char* buffer, std::size_t bufferSize )
+ throw ( IOException )
+{
+ try {
+ std::size_t numRead = FilterInputStream::read( buffer, bufferSize );
+
+ log( buffer, numRead );
+
+ return numRead;
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LoggingInputStream::log( const unsigned char* buffer, size_t len ) {
+
+ ostringstream ostream;
+
+ ostream << "TCP Trace: Reading: " << endl << "[";
+
+ for( size_t ix=0; ix<len; ++ix ){
+ ostream << setw(2) << setfill('0') << std::hex << (int)buffer[ix];
+
+ if( ((ix+1) % 2) == 0 ){
+ ostream << ' ';
+ }
+ }
+
+ ostream << "] len: " << std::dec << len << " bytes";
+
+ // Log the data
+ LOGCMS_INFO( logger, ostream.str() )
+}
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.h?view=auto&rev=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingInputStream.h Mon
Feb 12 17:07:03 2007
@@ -0,0 +1,74 @@
+/*
+ * 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 _ACTIVEMQ_IO_LOGGINGINPUTSTREAM_H_
+#define _ACTIVEMQ_IO_LOGGINGINPUTSTREAM_H_
+
+#include <activemq/io/FilterInputStream.h>
+#include <activemq/logger/LoggerDefines.h>
+
+namespace activemq{
+namespace io{
+
+ class LoggingInputStream : public FilterInputStream
+ {
+ private:
+
+ LOGCMS_DECLARE(logger)
+
+ public:
+
+ /**
+ * Creates a DataInputStream that uses the specified underlying
+ * InputStream.
+ * @param inputStream the InputStream instance to wrap.
+ * @param own, indicates if this class owns the wrapped string
+ * defaults to false.
+ */
+ LoggingInputStream( InputStream* inputStream, bool own = false );
+
+ virtual ~LoggingInputStream();
+
+ /**
+ * Reads a single byte from the buffer. Blocks until
+ * data is available.
+ * @return The next byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual unsigned char read() throw ( IOException );
+
+ /**
+ * Reads an array of bytes from the buffer. Blocks until
+ * the requested number of bytes are available.
+ * @param buffer (out) the target buffer.
+ * @param bufferSize the size of the output buffer.
+ * @return The number of bytes read or -1 if EOF is detected
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual std::size_t read( unsigned char* buffer, std::size_t bufferSize )
+ throw ( IOException );
+
+ private:
+
+ /**
+ * Logs the data in the buffer.
+ */
+ void log( const unsigned char* buffer, std::size_t len );
+ };
+
+}}
+#endif /*_ACTIVEMQ_IO_LOGGINGINPUTSTREAM_H_*/
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.cpp?view=auto&rev=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.cpp
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.cpp
Mon Feb 12 17:07:03 2007
@@ -0,0 +1,83 @@
+/*
+ * 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 "LoggingOutputStream.h"
+#include <sstream>
+#include <iomanip>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::io;
+
+LOGCMS_INITIALIZE( logger, LoggingOutputStream, "activemq.io.LoggingOutputStream")
+
+////////////////////////////////////////////////////////////////////////////////
+LoggingOutputStream::LoggingOutputStream( OutputStream* outputStream, bool own )
+ : FilterOutputStream( outputStream, own )
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LoggingOutputStream::~LoggingOutputStream()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LoggingOutputStream::write( const unsigned char c ) throw ( IOException ) {
+ try {
+
+ log( &c, 1 );
+
+ FilterOutputStream::write( c );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LoggingOutputStream::write( const unsigned char* buffer, size_t len )
+ throw ( IOException ) {
+
+ try {
+ log( buffer, len );
+
+ FilterOutputStream::write( buffer, len );
+ }
+ AMQ_CATCH_RETHROW( IOException )
+ AMQ_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LoggingOutputStream::log( const unsigned char* buffer, size_t len ) {
+
+ // Write the buffer as hex to a string stream.
+ ostringstream ostream;
+ ostream << "TCP Trace: Writing:" << endl << '[';
+
+ for( size_t ix=0; ix<len; ++ix ){
+ ostream << setw(2) << setfill('0') << std::hex << (int)buffer[ix];
+
+ if( ((ix+1) % 2) == 0 ){
+ ostream << ' ';
+ }
+ }
+
+ ostream << "] len: " << std::dec << len << " bytes";
+
+ // Log the data
+ LOGCMS_INFO( logger, ostream.str() )
+}
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.h?view=auto&rev=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/LoggingOutputStream.h Mon
Feb 12 17:07:03 2007
@@ -0,0 +1,76 @@
+/*
+ * 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 ACTIVEMQ_IO_LOGGINGOUTPUTSTREAM_H_
+#define ACTIVEMQ_IO_LOGGINGOUTPUTSTREAM_H_
+
+#include <activemq/io/FilterOutputStream.h>
+#include <activemq/logger/LoggerDefines.h>
+
+namespace activemq{
+namespace io{
+
+ /**
+ * OutputStream filter that just logs the data being
+ * written.
+ */
+ class LoggingOutputStream : public FilterOutputStream
+ {
+ private:
+
+ LOGCMS_DECLARE(logger)
+
+ public:
+
+ /**
+ * Constructor.
+ * @param outputStream the OutputStream to wrap
+ * @param own If true, this object will control the lifetime of the
+ * output stream that it encapsulates.
+ */
+ LoggingOutputStream( OutputStream* next, bool own = false );
+
+ virtual ~LoggingOutputStream();
+
+ /**
+ * Writes a single byte to the output stream.
+ * @param c the byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( unsigned char c ) throw ( IOException );
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer,
+ std::size_t len ) throw ( IOException );
+
+ private:
+
+ /**
+ * Logs the data in the buffer.
+ */
+ void log( const unsigned char* buffer, std::size_t len );
+
+ };
+
+}}
+
+#endif /*ACTIVEMQ_IO_LOGGINGOUTPUTSTREAM_H_*/
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketFactory.cpp?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketFactory.cpp Mon
Feb 12 17:07:03 2007
@@ -92,37 +92,37 @@
// The buffered socket will own the TcpSocket instance, and will
// clean it up when it is cleaned up.
TcpSocket* tcpSocket = new TcpSocket();
- BufferedSocket* bufferedSocket =
- new BufferedSocket(tcpSocket, inputBufferSize, outputBufferSize);
+ /*BufferedSocket* bufferedSocket =
+ new BufferedSocket(tcpSocket, inputBufferSize, outputBufferSize);*/
try
{
// Connect the socket.
- bufferedSocket->connect( host.c_str(), port );
+ tcpSocket->connect( host.c_str(), port );
// Set the socket options.
- bufferedSocket->setSoLinger( soLinger );
- bufferedSocket->setKeepAlive( soKeepAlive );
+ tcpSocket->setSoLinger( soLinger );
+ tcpSocket->setKeepAlive( soKeepAlive );
if( soReceiveBufferSize > 0 ){
- bufferedSocket->setReceiveBufferSize( soReceiveBufferSize );
+ tcpSocket->setReceiveBufferSize( soReceiveBufferSize );
}
if( soSendBufferSize > 0 ){
- bufferedSocket->setSendBufferSize( soSendBufferSize );
+ tcpSocket->setSendBufferSize( soSendBufferSize );
}
}
catch ( SocketException& ex )
{
ex.setMark( __FILE__, __LINE__ );
try{
- delete bufferedSocket;
+ delete tcpSocket;
} catch( SocketException& ex2 ){ /* Absorb */ }
throw ex;
}
- return bufferedSocket;
+ return tcpSocket;
}
AMQ_CATCH_RETHROW( SocketException )
AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, SocketException )
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp
Mon Feb 12 17:07:03 2007
@@ -37,14 +37,17 @@
#include <activemq/network/SocketInputStream.h>
#include <activemq/network/SocketError.h>
#include <activemq/io/IOException.h>
+#include <activemq/util/Character.h>
#include <activemq/exceptions/UnsupportedOperationException.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
+#include <iostream>
using namespace activemq;
using namespace activemq::network;
using namespace activemq::io;
+using namespace activemq::util;
using namespace activemq::exceptions;
using namespace std;
@@ -52,7 +55,7 @@
SocketInputStream::SocketInputStream( network::Socket::SocketHandle socket )
{
this->socket = socket;
- debug = false;
+ //debug = true;
}
////////////////////////////////////////////////////////////////////////////////
@@ -147,16 +150,18 @@
"activemq::io::SocketInputStream::read - %s", SocketError::getErrorString().c_str()
);
}
- if( debug ){
+ /*if( debug ){
printf("SocketInputStream:read(), numbytes:%d -", len);
for( int ix=0; ix<len; ++ix ){
- if( buffer[ix] > 20 )
- printf("%c", buffer[ix] );
+ char c = buffer[ix];
+ if( Character::isLetterOrDigit(c) || Character::isWhitespace(c) )
+ cout << c;
else
- printf("[%d]", buffer[ix] );
+ cout << '[' << (int)(unsigned char)c << ']';
}
- printf("\n");
- }
+ cout << endl;
+ cout.flush();
+ }*/
return len;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.h?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.h
Mon Feb 12 17:07:03 2007
@@ -36,7 +36,7 @@
// The socket handle.
Socket::SocketHandle socket;
concurrent::Mutex mutex;
- bool debug;
+ //bool debug;
public:
@@ -55,9 +55,9 @@
* Enables socket level output of the recieved data
* @param debug true to turn on debugging
*/
- virtual void setDebug( bool debug ){
+ /*virtual void setDebug( bool debug ){
this->debug = debug;
- }
+ }*/
/**
* Locks the object.
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp
Mon Feb 12 17:07:03 2007
@@ -17,6 +17,7 @@
#include "SocketOutputStream.h"
#include <activemq/util/Config.h>
+#include <activemq/util/Character.h>
#include "SocketError.h"
#ifdef HAVE_WINSOCK2_H
@@ -40,13 +41,14 @@
using namespace activemq::network;
using namespace activemq::io;
+using namespace activemq::util;
using namespace std;
////////////////////////////////////////////////////////////////////////////////
SocketOutputStream::SocketOutputStream( Socket::SocketHandle socket )
{
this->socket = socket;
- this->debug = false;
+ //this->debug = true;
}
////////////////////////////////////////////////////////////////////////////////
@@ -67,17 +69,18 @@
std::size_t remaining = len;
int sendOpts = AMQ_SEND_OPTS;
- if( debug ){
+ /*if( debug ){
cout << "SocketOutputStream:write(), numbytes: " << len << " -
";
for( std::size_t ix=0; ix<len; ++ix ){
char c = buffer[ix];
- if( c > 20 ){
- cout << c;
+ if( Character::isLetterOrDigit(c) || Character::isWhitespace(c) ){
+ cout << (char)c;
}
- else cout << "[" << c << "]";
+ else cout << "[" << (int)(unsigned char)c << "]";
}
cout << endl;
- }
+ cout.flush();
+ }*/
while( remaining > 0 )
{
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.h?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.h
Mon Feb 12 17:07:03 2007
@@ -36,7 +36,7 @@
// The socket.
Socket::SocketHandle socket;
concurrent::Mutex mutex;
- bool debug;
+ //bool debug;
public:
@@ -52,9 +52,9 @@
* Enables Debugging of Socket Data
* @param debug true to enable
*/
- virtual void setDebug( bool debug ){
+ /*virtual void setDebug( bool debug ){
this->debug = debug;
- }
+ }*/
/**
* Locks the object.
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.cpp?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.cpp
Mon Feb 12 17:07:03 2007
@@ -24,6 +24,7 @@
using namespace std;
using namespace activemq;
+using namespace activemq::io;
using namespace activemq::transport;
using namespace activemq::network;
using namespace activemq::exceptions;
@@ -32,7 +33,13 @@
TcpTransport::TcpTransport( const activemq::util::Properties& properties,
Transport* next,
const bool own )
- : TransportFilter( next, own )
+:
+ TransportFilter( next, own ),
+ socket( NULL ),
+ loggingInputStream( NULL ),
+ loggingOutputStream( NULL ),
+ bufferedInputStream( NULL ),
+ bufferedOutputStream( NULL )
{
try
{
@@ -50,10 +57,26 @@
"TcpTransport::TcpTransport - "
"transport must be of type IOTransport");
}
+
+ InputStream* inputStream = socket->getInputStream();
+ OutputStream* outputStream = socket->getOutputStream();
+
+ // If tcp tracing was enabled, wrap the iostreams with logging streams
+ if( properties.getProperty( "tcpTracingEnabled", "false" ) == "true" ) {
+ loggingInputStream = new LoggingInputStream( inputStream );
+ loggingOutputStream = new LoggingOutputStream( outputStream );
+
+ inputStream = loggingInputStream;
+ outputStream = loggingOutputStream;
+ }
+
+ // Now wrap the input/output streams with buffered streams
+ bufferedInputStream = new BufferedInputStream(inputStream);
+ bufferedOutputStream = new BufferedOutputStream(outputStream);
- // Give the IOTransport the streams from out TCP socket.
- ioTransport->setInputStream( socket->getInputStream() );
- ioTransport->setOutputStream( socket->getOutputStream() );
+ // Give the IOTransport the streams.
+ ioTransport->setInputStream( bufferedInputStream );
+ ioTransport->setOutputStream( bufferedOutputStream );
}
AMQ_CATCH_RETHROW( ActiveMQException )
AMQ_CATCHALL_THROW( ActiveMQException )
@@ -65,12 +88,32 @@
try
{
try{
- close();
+ close();
} catch( cms::CMSException& ex ){ /* Absorb */ }
if( socket != NULL ) {
delete socket;
socket = NULL;
+ }
+
+ if( loggingInputStream != NULL ) {
+ delete loggingInputStream;
+ loggingInputStream = NULL;
+ }
+
+ if( loggingOutputStream != NULL ) {
+ delete loggingOutputStream;
+ loggingOutputStream = NULL;
+ }
+
+ if( bufferedInputStream != NULL ) {
+ delete bufferedInputStream;
+ bufferedInputStream = NULL;
+ }
+
+ if( bufferedOutputStream != NULL ) {
+ delete bufferedOutputStream;
+ bufferedOutputStream = NULL;
}
}
AMQ_CATCH_NOTHROW( ActiveMQException )
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.h?view=diff&rev=506787&r1=506786&r2=506787
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransport.h Mon
Feb 12 17:07:03 2007
@@ -21,6 +21,10 @@
#include <activemq/transport/TransportFilter.h>
#include <activemq/network/Socket.h>
#include <activemq/util/Properties.h>
+#include <activemq/io/LoggingInputStream.h>
+#include <activemq/io/LoggingOutputStream.h>
+#include <activemq/io/BufferedInputStream.h>
+#include <activemq/io/BufferedOutputStream.h>
namespace activemq{
namespace transport{
@@ -39,6 +43,12 @@
* Socket that this Transport Communicates with
*/
network::Socket* socket;
+
+ io::LoggingInputStream* loggingInputStream;
+ io::LoggingOutputStream* loggingOutputStream;
+
+ io::BufferedInputStream* bufferedInputStream;
+ io::BufferedOutputStream* bufferedOutputStream;
public:
|