summaryrefslogtreecommitdiff
path: root/cpp/common
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/common')
-rw-r--r--cpp/common/Makefile4
-rw-r--r--cpp/common/concurrent/inc/Runnable.h1
-rw-r--r--cpp/common/concurrent/src/APRBase.cpp3
-rw-r--r--cpp/common/concurrent/src/APRThread.cpp2
-rw-r--r--cpp/common/concurrent/src/APRThreadPool.cpp6
-rw-r--r--cpp/common/concurrent/src/Runnable.cpp19
-rw-r--r--cpp/common/framing/generated/stylesheets/amqp_client_handler_impl.xsl8
-rw-r--r--cpp/common/framing/generated/stylesheets/amqp_server_handler_impl.xsl4
-rw-r--r--cpp/common/framing/generated/stylesheets/amqp_server_operations.xsl2
-rw-r--r--cpp/common/framing/generated/stylesheets/cpp.xsl7
-rw-r--r--cpp/common/framing/inc/AMQHeaderBody.h2
-rw-r--r--cpp/common/framing/inc/AMQHeartbeatBody.h4
-rw-r--r--cpp/common/framing/inc/BasicHeaderProperties.h24
-rw-r--r--cpp/common/framing/inc/BodyHandler.h1
-rw-r--r--cpp/common/framing/inc/Buffer.h16
-rw-r--r--cpp/common/framing/inc/InitiationHandler.h1
-rw-r--r--cpp/common/framing/inc/InputHandler.h1
-rw-r--r--cpp/common/framing/inc/OutputHandler.h1
-rw-r--r--cpp/common/framing/inc/Value.h4
-rw-r--r--cpp/common/framing/src/AMQContentBody.cpp4
-rw-r--r--cpp/common/framing/src/AMQFrame.cpp32
-rw-r--r--cpp/common/framing/src/AMQHeaderBody.cpp4
-rw-r--r--cpp/common/framing/src/AMQMethodBody.cpp4
-rw-r--r--cpp/common/framing/src/BasicHeaderProperties.cpp36
-rw-r--r--cpp/common/framing/src/BodyHandler.cpp2
-rw-r--r--cpp/common/framing/src/Buffer.cpp48
-rw-r--r--cpp/common/framing/src/FieldTable.cpp17
-rw-r--r--cpp/common/framing/src/InitiationHandler.cpp21
-rw-r--r--cpp/common/framing/src/InputHandler.cpp21
-rw-r--r--cpp/common/framing/src/OutputHandler.cpp21
-rw-r--r--cpp/common/framing/test/BodyHandlerTest.cpp6
-rw-r--r--cpp/common/framing/test/field_table_test.cpp5
-rw-r--r--cpp/common/framing/test/framing_test.cpp5
-rw-r--r--cpp/common/framing/test/header_test.cpp5
-rw-r--r--cpp/common/io/Makefile4
-rw-r--r--cpp/common/io/inc/APRConnector.h2
-rw-r--r--cpp/common/io/inc/ConnectorImpl.h4
-rw-r--r--cpp/common/io/inc/LFProcessor.h2
-rw-r--r--cpp/common/io/src/APRConnector.cpp23
-rw-r--r--cpp/common/io/src/APRSocket.cpp4
-rw-r--r--cpp/common/io/src/BlockingAPRAcceptor.cpp9
-rw-r--r--cpp/common/io/src/BlockingAPRSessionContext.cpp17
-rw-r--r--cpp/common/io/src/LFAcceptor.cpp12
-rw-r--r--cpp/common/io/src/LFProcessor.cpp32
-rw-r--r--cpp/common/io/src/LFSessionContext.cpp34
-rw-r--r--cpp/common/utils/inc/logger.h82
-rw-r--r--cpp/common/utils/src/Makefile9
-rw-r--r--cpp/common/utils/src/logger.cpp209
-rw-r--r--cpp/common/utils/src/logger_test.cpp78
49 files changed, 268 insertions, 594 deletions
diff --git a/cpp/common/Makefile b/cpp/common/Makefile
index 0533cdd1a9..98e4025390 100644
--- a/cpp/common/Makefile
+++ b/cpp/common/Makefile
@@ -20,11 +20,7 @@
QPID_HOME=../..
include $(QPID_HOME)/cpp/options.mk
-
TARGET = $(LIB_DIR)/libqpid_common.so.1.0
-
-CXXFLAGS = $(DEBUG) $(OPT) -MMD -fpic $(COMMON_INCLUDES)
-
SOURCES = $(wildcard */src/*.cpp framing/generated/*.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
DEPS = $(SOURCES:.cpp=.d)
diff --git a/cpp/common/concurrent/inc/Runnable.h b/cpp/common/concurrent/inc/Runnable.h
index 523ad813f7..9753a1ad0a 100644
--- a/cpp/common/concurrent/inc/Runnable.h
+++ b/cpp/common/concurrent/inc/Runnable.h
@@ -24,6 +24,7 @@ namespace concurrent {
class Runnable
{
public:
+ virtual ~Runnable();
virtual void run() = 0;
};
diff --git a/cpp/common/concurrent/src/APRBase.cpp b/cpp/common/concurrent/src/APRBase.cpp
index f87ea9e25f..f9b34b9333 100644
--- a/cpp/common/concurrent/src/APRBase.cpp
+++ b/cpp/common/concurrent/src/APRBase.cpp
@@ -91,7 +91,6 @@ void qpid::concurrent::check(apr_status_t status, const std::string& file, const
std::string qpid::concurrent::get_desc(apr_status_t status){
const int size = 50;
char tmp[size];
- std::string msg(apr_strerror(status, tmp, size));
- return msg;
+ return std::string(apr_strerror(status, tmp, size));
}
diff --git a/cpp/common/concurrent/src/APRThread.cpp b/cpp/common/concurrent/src/APRThread.cpp
index 4202fe81b6..4167fb76ff 100644
--- a/cpp/common/concurrent/src/APRThread.cpp
+++ b/cpp/common/concurrent/src/APRThread.cpp
@@ -27,7 +27,7 @@ void* APR_THREAD_FUNC ExecRunnable(apr_thread_t* thread, void *data){
return NULL;
}
-APRThread::APRThread(apr_pool_t* _pool, Runnable* _runnable) : pool(_pool), runnable(_runnable){}
+APRThread::APRThread(apr_pool_t* _pool, Runnable* _runnable) : runnable(_runnable), pool(_pool) {}
APRThread::~APRThread(){
}
diff --git a/cpp/common/concurrent/src/APRThreadPool.cpp b/cpp/common/concurrent/src/APRThreadPool.cpp
index e0fcb804e6..8518d98b67 100644
--- a/cpp/common/concurrent/src/APRThreadPool.cpp
+++ b/cpp/common/concurrent/src/APRThreadPool.cpp
@@ -22,13 +22,11 @@
using namespace qpid::concurrent;
-APRThreadPool::APRThreadPool(int _size) : size(_size), factory(new APRThreadFactory()),
- deleteFactory(true), running(false){
+APRThreadPool::APRThreadPool(int _size) : deleteFactory(true), size(_size), factory(new APRThreadFactory()), running(false){
worker = new Worker(this);
}
-APRThreadPool::APRThreadPool(int _size, ThreadFactory* _factory) : size(_size), factory(_factory),
- deleteFactory(false), running(false){
+APRThreadPool::APRThreadPool(int _size, ThreadFactory* _factory) : deleteFactory(false), size(_size), factory(_factory), running(false){
worker = new Worker(this);
}
diff --git a/cpp/common/concurrent/src/Runnable.cpp b/cpp/common/concurrent/src/Runnable.cpp
new file mode 100644
index 0000000000..cf9b8d586f
--- /dev/null
+++ b/cpp/common/concurrent/src/Runnable.cpp
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 "Runnable.h"
+qpid::concurrent::Runnable::~Runnable() {}
diff --git a/cpp/common/framing/generated/stylesheets/amqp_client_handler_impl.xsl b/cpp/common/framing/generated/stylesheets/amqp_client_handler_impl.xsl
index aa095eaf79..0cc34e0ecf 100644
--- a/cpp/common/framing/generated/stylesheets/amqp_client_handler_impl.xsl
+++ b/cpp/common/framing/generated/stylesheets/amqp_client_handler_impl.xsl
@@ -7,7 +7,7 @@
===============================
Template: client_handler_impl_h
===============================
- Template to generate the AMQP_ServerHandlerImpl class header file.
+ Template to generate the AMQP_ClientHandlerImpl class header file.
-->
<xsl:template match="amqp" mode="client_handler_impl_h">
<xsl:param name="domain-cpp-table"/>
@@ -122,7 +122,7 @@ class AMQP_ClientHandlerImpl : virtual public AMQP_ClientOperations
=================================
Template: client_handler_impl_cpp
=================================
- Template to generate the AMQP_ServerHandlerImpl class stubs.
+ Template to generate the AMQP_ClientHandlerImpl class stubs.
-->
<xsl:template match="amqp" mode="client_handler_impl_cpp">
<xsl:param name="domain-cpp-table"/>
@@ -163,12 +163,12 @@ AMQP_ClientHandlerImpl::~AMQP_ClientHandlerImpl()
<xsl:for-each select="method">
<xsl:if test="chassis[@name='client']">
<xsl:text>void AMQP_ClientHandlerImpl::</xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl::</xsl:text>
- <xsl:value-of select="amqp:cpp-name(@name)"/><xsl:text>( u_int16_t channel</xsl:text>
+ <xsl:value-of select="amqp:cpp-name(@name)"/><xsl:text>( u_int16_t /*channel*/</xsl:text>
<xsl:if test="field">
<xsl:text>,&#xA; </xsl:text>
<xsl:for-each select="field">
<xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/>
- <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/>
+ <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' /*', amqp:cpp-name(@name), '*/')"/>
<xsl:if test="position()!=last()">
<xsl:text>,&#xA; </xsl:text>
</xsl:if>
diff --git a/cpp/common/framing/generated/stylesheets/amqp_server_handler_impl.xsl b/cpp/common/framing/generated/stylesheets/amqp_server_handler_impl.xsl
index de879a5670..6450d3fd0c 100644
--- a/cpp/common/framing/generated/stylesheets/amqp_server_handler_impl.xsl
+++ b/cpp/common/framing/generated/stylesheets/amqp_server_handler_impl.xsl
@@ -163,12 +163,12 @@ AMQP_ServerHandlerImpl::~AMQP_ServerHandlerImpl()
<xsl:for-each select="method">
<xsl:if test="chassis[@name='server']">
<xsl:text>void AMQP_ServerHandlerImpl::</xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl::</xsl:text>
- <xsl:value-of select="amqp:cpp-name(@name)"/><xsl:text>( u_int16_t channel</xsl:text>
+ <xsl:value-of select="amqp:cpp-name(@name)"/><xsl:text>( u_int16_t /*channel*/</xsl:text>
<xsl:if test="field">
<xsl:text>,&#xA; </xsl:text>
<xsl:for-each select="field">
<xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/>
- <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/>
+ <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' /*', amqp:cpp-name(@name), '*/')"/>
<xsl:if test="position()!=last()">
<xsl:text>,&#xA; </xsl:text>
</xsl:if>
diff --git a/cpp/common/framing/generated/stylesheets/amqp_server_operations.xsl b/cpp/common/framing/generated/stylesheets/amqp_server_operations.xsl
index b42242e8fe..4b97700f04 100644
--- a/cpp/common/framing/generated/stylesheets/amqp_server_operations.xsl
+++ b/cpp/common/framing/generated/stylesheets/amqp_server_operations.xsl
@@ -66,7 +66,7 @@ class AMQP_ServerOperations
<xsl:value-of select="amqp:process-docs(doc)"/>
<xsl:text>*/&#xA;</xsl:text>
</xsl:if>
- <xsl:for-each select="rule">/**
+ <xsl:for-each select="rule">
<xsl:text>&#xA;/**&#xA;</xsl:text>
<xsl:text>Rule "</xsl:text><xsl:value-of select="@name"/><xsl:text>":&#xA;</xsl:text>
<xsl:value-of select="amqp:process-docs(doc)"/>
diff --git a/cpp/common/framing/generated/stylesheets/cpp.xsl b/cpp/common/framing/generated/stylesheets/cpp.xsl
index ae66f65745..f9e5ba4141 100644
--- a/cpp/common/framing/generated/stylesheets/cpp.xsl
+++ b/cpp/common/framing/generated/stylesheets/cpp.xsl
@@ -122,7 +122,7 @@ public:
}
</xsl:if>
- inline void encodeContent(Buffer&amp; buffer) const
+ inline void encodeContent(Buffer&amp; <xsl:if test="$f/field">buffer</xsl:if>) const
{
<xsl:if test="$f/field[@type='bit']">
u_int8_t flags = 0;
@@ -140,11 +140,8 @@ public:
</xsl:for-each>
}
- inline void decodeContent(Buffer&amp; buffer)
+ inline void decodeContent(Buffer&amp; <xsl:if test="$f/field">buffer</xsl:if>)
{
- <xsl:if test="$f/field[@type='bit']">
- u_int8_t maxbit = <xsl:value-of select="$f/@bit-field-count"/>;
- </xsl:if>
<xsl:for-each select="$f/field">
<xsl:choose>
<xsl:when test="@type = 'bit' and @boolean-index = 1">
diff --git a/cpp/common/framing/inc/AMQHeaderBody.h b/cpp/common/framing/inc/AMQHeaderBody.h
index e39fffa8ce..4f9cdb571a 100644
--- a/cpp/common/framing/inc/AMQHeaderBody.h
+++ b/cpp/common/framing/inc/AMQHeaderBody.h
@@ -42,7 +42,7 @@ public:
HeaderProperties* getProperties(){ return properties; }
const HeaderProperties* getProperties() const { return properties; }
inline u_int64_t getContentSize() const { return contentSize; }
- inline void setContentSize(u_int64_t size) { contentSize = size; }
+ inline void setContentSize(u_int64_t _size) { contentSize = _size; }
virtual ~AMQHeaderBody();
virtual u_int32_t size() const;
virtual void encode(Buffer& buffer) const;
diff --git a/cpp/common/framing/inc/AMQHeartbeatBody.h b/cpp/common/framing/inc/AMQHeartbeatBody.h
index cfe057bdcd..da612a2a44 100644
--- a/cpp/common/framing/inc/AMQHeartbeatBody.h
+++ b/cpp/common/framing/inc/AMQHeartbeatBody.h
@@ -33,8 +33,8 @@ public:
virtual ~AMQHeartbeatBody();
inline u_int32_t size() const { return 0; }
inline u_int8_t type() const { return HEARTBEAT_BODY; }
- inline void encode(Buffer& buffer) const {}
- inline void decode(Buffer& buffer, u_int32_t size) {}
+ inline void encode(Buffer& ) const {}
+ inline void decode(Buffer& , u_int32_t /*size*/) {}
virtual void print(std::ostream& out) const;
};
diff --git a/cpp/common/framing/inc/BasicHeaderProperties.h b/cpp/common/framing/inc/BasicHeaderProperties.h
index 8688a37bf9..c32612221b 100644
--- a/cpp/common/framing/inc/BasicHeaderProperties.h
+++ b/cpp/common/framing/inc/BasicHeaderProperties.h
@@ -70,20 +70,20 @@ namespace framing {
inline string& getAppId(){ return appId; }
inline string& getClusterId(){ return clusterId; }
- void inline setContentType(string& type){ contentType = type; }
+ void inline setContentType(string& _type){ contentType = _type; }
void inline setContentEncoding(string& encoding){ contentEncoding = encoding; }
- void inline setHeaders(FieldTable& headers){ this->headers = headers; }
+ void inline setHeaders(FieldTable& _headers){ headers = _headers; }
void inline setDeliveryMode(u_int8_t mode){ deliveryMode = mode; }
- void inline setPriority(u_int8_t priority){ this->priority = priority; }
- void inline setCorrelationId(string& correlationId){ this->correlationId = correlationId; }
- void inline setReplyTo(string& replyTo){ this->replyTo = replyTo;}
- void inline setExpiration(string& expiration){ this->expiration = expiration; }
- void inline setMessageId(string& messageId){ this->messageId = messageId; }
- void inline setTimestamp(u_int64_t timestamp){ this->timestamp = timestamp; }
- void inline setType(string& type){ this->type = type; }
- void inline setUserId(string& userId){ this->userId = userId; }
- void inline setAppId(string& appId){this->appId = appId; }
- void inline setClusterId(string& clusterId){ this->clusterId = clusterId; }
+ void inline setPriority(u_int8_t _priority){ priority = _priority; }
+ void inline setCorrelationId(string& _correlationId){ correlationId = _correlationId; }
+ void inline setReplyTo(string& _replyTo){ replyTo = _replyTo;}
+ void inline setExpiration(string& _expiration){ expiration = _expiration; }
+ void inline setMessageId(string& _messageId){ messageId = _messageId; }
+ void inline setTimestamp(u_int64_t _timestamp){ timestamp = _timestamp; }
+ void inline setType(string& _type){ type = _type; }
+ void inline setUserId(string& _userId){ userId = _userId; }
+ void inline setAppId(string& _appId){appId = _appId; }
+ void inline setClusterId(string& _clusterId){ clusterId = _clusterId; }
};
}
diff --git a/cpp/common/framing/inc/BodyHandler.h b/cpp/common/framing/inc/BodyHandler.h
index f92ae66804..a4aee2709e 100644
--- a/cpp/common/framing/inc/BodyHandler.h
+++ b/cpp/common/framing/inc/BodyHandler.h
@@ -30,6 +30,7 @@ namespace framing {
class BodyHandler{
public:
+ virtual ~BodyHandler();
virtual void handleMethod(AMQMethodBody::shared_ptr body) = 0;
virtual void handleHeader(AMQHeaderBody::shared_ptr body) = 0;
virtual void handleContent(AMQContentBody::shared_ptr body) = 0;
diff --git a/cpp/common/framing/inc/Buffer.h b/cpp/common/framing/inc/Buffer.h
index e0532cc9d6..4d3d503b00 100644
--- a/cpp/common/framing/inc/Buffer.h
+++ b/cpp/common/framing/inc/Buffer.h
@@ -27,16 +27,16 @@ class FieldTable;
class Buffer
{
- const int size;
+ const u_int32_t size;
char* data;
- int position;
- int limit;
- int r_position;
- int r_limit;
+ u_int32_t position;
+ u_int32_t limit;
+ u_int32_t r_position;
+ u_int32_t r_limit;
public:
- Buffer(int size);
+ Buffer(u_int32_t size);
~Buffer();
void flip();
@@ -44,9 +44,9 @@ public:
void compact();
void record();
void restore();
- int available();
+ u_int32_t available();
char* start();
- void move(int bytes);
+ void move(u_int32_t bytes);
void putOctet(u_int8_t i);
void putShort(u_int16_t i);
diff --git a/cpp/common/framing/inc/InitiationHandler.h b/cpp/common/framing/inc/InitiationHandler.h
index 2e8d1e652b..7b1fb36e2d 100644
--- a/cpp/common/framing/inc/InitiationHandler.h
+++ b/cpp/common/framing/inc/InitiationHandler.h
@@ -27,6 +27,7 @@ namespace framing {
class InitiationHandler{
public:
+ virtual ~InitiationHandler();
virtual void initiated(ProtocolInitiation* header) = 0;
};
diff --git a/cpp/common/framing/inc/InputHandler.h b/cpp/common/framing/inc/InputHandler.h
index 2722cae0ed..927bd97ab4 100644
--- a/cpp/common/framing/inc/InputHandler.h
+++ b/cpp/common/framing/inc/InputHandler.h
@@ -27,6 +27,7 @@ namespace framing {
class InputHandler{
public:
+ virtual ~InputHandler();
virtual void received(AMQFrame* frame) = 0;
};
diff --git a/cpp/common/framing/inc/OutputHandler.h b/cpp/common/framing/inc/OutputHandler.h
index 7fe63660c3..afc8d7f257 100644
--- a/cpp/common/framing/inc/OutputHandler.h
+++ b/cpp/common/framing/inc/OutputHandler.h
@@ -27,6 +27,7 @@ namespace framing {
class OutputHandler{
public:
+ virtual ~OutputHandler();
virtual void send(AMQFrame* frame) = 0;
};
diff --git a/cpp/common/framing/inc/Value.h b/cpp/common/framing/inc/Value.h
index 3d525a0bef..fe939e8758 100644
--- a/cpp/common/framing/inc/Value.h
+++ b/cpp/common/framing/inc/Value.h
@@ -147,8 +147,8 @@ class EmptyValue : public Value {
~EmptyValue();
virtual u_int32_t size() const { return 0; }
virtual char getType() const { return 0; }
- virtual void encode(Buffer& buffer) {}
- virtual void decode(Buffer& buffer) {}
+ virtual void encode(Buffer& ) {}
+ virtual void decode(Buffer& ) {}
virtual bool operator==(const Value& v) const {
return dynamic_cast<const EmptyValue*>(&v);
}
diff --git a/cpp/common/framing/src/AMQContentBody.cpp b/cpp/common/framing/src/AMQContentBody.cpp
index 6bc588c3ab..1be8867d53 100644
--- a/cpp/common/framing/src/AMQContentBody.cpp
+++ b/cpp/common/framing/src/AMQContentBody.cpp
@@ -30,8 +30,8 @@ u_int32_t qpid::framing::AMQContentBody::size() const{
void qpid::framing::AMQContentBody::encode(Buffer& buffer) const{
buffer.putRawData(data);
}
-void qpid::framing::AMQContentBody::decode(Buffer& buffer, u_int32_t size){
- buffer.getRawData(data, size);
+void qpid::framing::AMQContentBody::decode(Buffer& buffer, u_int32_t _size){
+ buffer.getRawData(data, _size);
}
void qpid::framing::AMQContentBody::print(std::ostream& out) const
diff --git a/cpp/common/framing/src/AMQFrame.cpp b/cpp/common/framing/src/AMQFrame.cpp
index 5686c9ac81..487ab1a443 100644
--- a/cpp/common/framing/src/AMQFrame.cpp
+++ b/cpp/common/framing/src/AMQFrame.cpp
@@ -63,33 +63,13 @@ bool AMQFrame::decode(Buffer& buffer)
{
if(buffer.available() < 7) return false;
buffer.record();
- u_int8_t type = buffer.getOctet();
- channel = buffer.getShort();
- u_int32_t size = buffer.getLong();
- if(buffer.available() < size + 1){
+ u_int32_t bufSize = decodeHead(buffer);
+
+ if(buffer.available() < bufSize + 1){
buffer.restore();
return false;
}
- switch(type)
- {
- case METHOD_BODY:
- body = createMethodBody(buffer);
- break;
- case HEADER_BODY:
- body = AMQBody::shared_ptr(new AMQHeaderBody());
- break;
- case CONTENT_BODY:
- body = AMQBody::shared_ptr(new AMQContentBody());
- break;
- case HEARTBEAT_BODY:
- body = AMQBody::shared_ptr(new AMQHeartbeatBody());
- break;
- default:
- string msg("Unknown body type: ");
- msg += type;
- THROW_QPID_ERROR(FRAMING_ERROR, msg);
- }
- body->decode(buffer, size);
+ decodeBody(buffer, bufSize);
u_int8_t end = buffer.getOctet();
if(end != 0xCE) THROW_QPID_ERROR(FRAMING_ERROR, "Frame end not found");
return true;
@@ -101,7 +81,7 @@ u_int32_t AMQFrame::decodeHead(Buffer& buffer){
return buffer.getLong();
}
-void AMQFrame::decodeBody(Buffer& buffer, uint32_t size)
+void AMQFrame::decodeBody(Buffer& buffer, uint32_t bufSize)
{
switch(type)
{
@@ -122,7 +102,7 @@ void AMQFrame::decodeBody(Buffer& buffer, uint32_t size)
msg += type;
THROW_QPID_ERROR(FRAMING_ERROR, msg);
}
- body->decode(buffer, size);
+ body->decode(buffer, bufSize);
}
std::ostream& qpid::framing::operator<<(std::ostream& out, const AMQFrame& t){
diff --git a/cpp/common/framing/src/AMQHeaderBody.cpp b/cpp/common/framing/src/AMQHeaderBody.cpp
index 1fd387c5d5..dce5f1fd54 100644
--- a/cpp/common/framing/src/AMQHeaderBody.cpp
+++ b/cpp/common/framing/src/AMQHeaderBody.cpp
@@ -41,12 +41,12 @@ void qpid::framing::AMQHeaderBody::encode(Buffer& buffer) const {
properties->encode(buffer);
}
-void qpid::framing::AMQHeaderBody::decode(Buffer& buffer, u_int32_t size){
+void qpid::framing::AMQHeaderBody::decode(Buffer& buffer, u_int32_t bufSize){
u_int16_t classId = buffer.getShort();
weight = buffer.getShort();
contentSize = buffer.getLongLong();
createProperties(classId);
- properties->decode(buffer, size - 12);
+ properties->decode(buffer, bufSize - 12);
}
void qpid::framing::AMQHeaderBody::createProperties(int classId){
diff --git a/cpp/common/framing/src/AMQMethodBody.cpp b/cpp/common/framing/src/AMQMethodBody.cpp
index 73862bb2bf..7455050377 100644
--- a/cpp/common/framing/src/AMQMethodBody.cpp
+++ b/cpp/common/framing/src/AMQMethodBody.cpp
@@ -24,7 +24,7 @@ void qpid::framing::AMQMethodBody::encode(Buffer& buffer) const{
encodeContent(buffer);
}
-void qpid::framing::AMQMethodBody::decode(Buffer& buffer, u_int32_t size){
+void qpid::framing::AMQMethodBody::decode(Buffer& buffer, u_int32_t /*size*/){
decodeContent(buffer);
}
@@ -32,7 +32,7 @@ bool qpid::framing::AMQMethodBody::match(AMQMethodBody* other) const{
return other != 0 && other->amqpClassId() == amqpClassId() && other->amqpMethodId() == amqpMethodId();
}
-void qpid::framing::AMQMethodBody::invoke(AMQP_ServerOperations& target, u_int16_t channel){
+void qpid::framing::AMQMethodBody::invoke(AMQP_ServerOperations& /*target*/, u_int16_t /*channel*/){
THROW_QPID_ERROR(PROTOCOL_ERROR, "Method not supported by AMQP Server.");
}
diff --git a/cpp/common/framing/src/BasicHeaderProperties.cpp b/cpp/common/framing/src/BasicHeaderProperties.cpp
index 4219d33a8f..c9153665d5 100644
--- a/cpp/common/framing/src/BasicHeaderProperties.cpp
+++ b/cpp/common/framing/src/BasicHeaderProperties.cpp
@@ -23,23 +23,23 @@ qpid::framing::BasicHeaderProperties::BasicHeaderProperties() : deliveryMode(0),
qpid::framing::BasicHeaderProperties::~BasicHeaderProperties(){}
u_int32_t qpid::framing::BasicHeaderProperties::size() const{
- u_int32_t size = 2;//flags
- if(contentType.length() > 0) size += contentType.length() + 1;
- if(contentEncoding.length() > 0) size += contentEncoding.length() + 1;
- if(headers.count() > 0) size += headers.size();
- if(deliveryMode != 0) size += 1;
- if(priority != 0) size += 1;
- if(correlationId.length() > 0) size += correlationId.length() + 1;
- if(replyTo.length() > 0) size += replyTo.length() + 1;
- if(expiration.length() > 0) size += expiration.length() + 1;
- if(messageId.length() > 0) size += messageId.length() + 1;
- if(timestamp != 0) size += 8;
- if(type.length() > 0) size += type.length() + 1;
- if(userId.length() > 0) size += userId.length() + 1;
- if(appId.length() > 0) size += appId.length() + 1;
- if(clusterId.length() > 0) size += clusterId.length() + 1;
+ u_int32_t bytes = 2;//flags
+ if(contentType.length() > 0) bytes += contentType.length() + 1;
+ if(contentEncoding.length() > 0) bytes += contentEncoding.length() + 1;
+ if(headers.count() > 0) bytes += headers.size();
+ if(deliveryMode != 0) bytes += 1;
+ if(priority != 0) bytes += 1;
+ if(correlationId.length() > 0) bytes += correlationId.length() + 1;
+ if(replyTo.length() > 0) bytes += replyTo.length() + 1;
+ if(expiration.length() > 0) bytes += expiration.length() + 1;
+ if(messageId.length() > 0) bytes += messageId.length() + 1;
+ if(timestamp != 0) bytes += 8;
+ if(type.length() > 0) bytes += type.length() + 1;
+ if(userId.length() > 0) bytes += userId.length() + 1;
+ if(appId.length() > 0) bytes += appId.length() + 1;
+ if(clusterId.length() > 0) bytes += clusterId.length() + 1;
- return size;
+ return bytes;
}
void qpid::framing::BasicHeaderProperties::encode(qpid::framing::Buffer& buffer) const{
@@ -62,9 +62,8 @@ void qpid::framing::BasicHeaderProperties::encode(qpid::framing::Buffer& buffer)
if(clusterId.length() > 0) buffer.putShortString(clusterId);
}
-void qpid::framing::BasicHeaderProperties::decode(qpid::framing::Buffer& buffer, u_int32_t size){
+void qpid::framing::BasicHeaderProperties::decode(qpid::framing::Buffer& buffer, u_int32_t /*size*/){
u_int16_t flags = buffer.getShort();
- int shift = 15;
if(flags & (1 << 15)) buffer.getShortString(contentType);
if(flags & (1 << 14)) buffer.getShortString(contentEncoding);
if(flags & (1 << 13)) buffer.getFieldTable(headers);
@@ -83,7 +82,6 @@ void qpid::framing::BasicHeaderProperties::decode(qpid::framing::Buffer& buffer,
u_int16_t qpid::framing::BasicHeaderProperties::getFlags() const{
u_int16_t flags(0);
- int shift = 15;
if(contentType.length() > 0) flags |= (1 << 15);
if(contentEncoding.length() > 0) flags |= (1 << 14);
if(headers.count() > 0) flags |= (1 << 13);
diff --git a/cpp/common/framing/src/BodyHandler.cpp b/cpp/common/framing/src/BodyHandler.cpp
index 4e4e2e02f7..b428c62637 100644
--- a/cpp/common/framing/src/BodyHandler.cpp
+++ b/cpp/common/framing/src/BodyHandler.cpp
@@ -21,6 +21,8 @@
using namespace qpid::framing;
using namespace std::tr1;
+BodyHandler::~BodyHandler() {}
+
void BodyHandler::handleBody(AMQBody::shared_ptr& body){
switch(body->type())
diff --git a/cpp/common/framing/src/Buffer.cpp b/cpp/common/framing/src/Buffer.cpp
index 15a4485abd..87aa1df7e9 100644
--- a/cpp/common/framing/src/Buffer.cpp
+++ b/cpp/common/framing/src/Buffer.cpp
@@ -18,7 +18,7 @@
#include "Buffer.h"
#include "FieldTable.h"
-qpid::framing::Buffer::Buffer(int _size) : size(_size), position(0), limit(_size){
+qpid::framing::Buffer::Buffer(u_int32_t _size) : size(_size), position(0), limit(_size){
data = new char[size];
}
@@ -37,7 +37,7 @@ void qpid::framing::Buffer::clear(){
}
void qpid::framing::Buffer::compact(){
- int p = limit - position;
+ u_int32_t p = limit - position;
//copy p chars from position to 0
memmove(data, data + position, p);
limit = size;
@@ -54,7 +54,7 @@ void qpid::framing::Buffer::restore(){
limit = r_limit;
}
-int qpid::framing::Buffer::available(){
+u_int32_t qpid::framing::Buffer::available(){
return limit - position;
}
@@ -62,7 +62,7 @@ char* qpid::framing::Buffer::start(){
return data + position;
}
-void qpid::framing::Buffer::move(int bytes){
+void qpid::framing::Buffer::move(u_int32_t bytes){
position += bytes;
}
@@ -123,29 +123,29 @@ u_int64_t qpid::framing::Buffer::getLongLong(){
void qpid::framing::Buffer::putShortString(const string& s){
- u_int8_t size = s.length();
- putOctet(size);
- s.copy(data + position, size);
- position += size;
+ u_int8_t len = s.length();
+ putOctet(len);
+ s.copy(data + position, len);
+ position += len;
}
void qpid::framing::Buffer::putLongString(const string& s){
- u_int32_t size = s.length();
- putLong(size);
- s.copy(data + position, size);
- position += size;
+ u_int32_t len = s.length();
+ putLong(len);
+ s.copy(data + position, len);
+ position += len;
}
void qpid::framing::Buffer::getShortString(string& s){
- u_int8_t size = getOctet();
- s.assign(data + position, size);
- position += size;
+ u_int8_t len = getOctet();
+ s.assign(data + position, len);
+ position += len;
}
void qpid::framing::Buffer::getLongString(string& s){
- u_int32_t size = getLong();
- s.assign(data + position, size);
- position += size;
+ u_int32_t len = getLong();
+ s.assign(data + position, len);
+ position += len;
}
void qpid::framing::Buffer::putFieldTable(const FieldTable& t){
@@ -157,12 +157,12 @@ void qpid::framing::Buffer::getFieldTable(FieldTable& t){
}
void qpid::framing::Buffer::putRawData(const string& s){
- u_int32_t size = s.length();
- s.copy(data + position, size);
- position += size;
+ u_int32_t len = s.length();
+ s.copy(data + position, len);
+ position += len;
}
-void qpid::framing::Buffer::getRawData(string& s, u_int32_t size){
- s.assign(data + position, size);
- position += size;
+void qpid::framing::Buffer::getRawData(string& s, u_int32_t len){
+ s.assign(data + position, len);
+ position += len;
}
diff --git a/cpp/common/framing/src/FieldTable.cpp b/cpp/common/framing/src/FieldTable.cpp
index b12b2783df..088c8fb500 100644
--- a/cpp/common/framing/src/FieldTable.cpp
+++ b/cpp/common/framing/src/FieldTable.cpp
@@ -27,12 +27,12 @@ namespace framing {
FieldTable::~FieldTable() {}
u_int32_t FieldTable::size() const {
- u_int32_t size(4);
+ u_int32_t len(4);
for(ValueMap::const_iterator i = values.begin(); i != values.end(); ++i) {
// 2 = shortstr_len_byyte + type_char_byte
- size += 2 + (i->first).size() + (i->second)->size();
+ len += 2 + (i->first).size() + (i->second)->size();
}
- return size;
+ return len;
}
int FieldTable::count() const {
@@ -74,9 +74,6 @@ void FieldTable::setTable(const std::string& name, const FieldTable& value){
}
namespace {
-// TODO aconway 2006-09-26: This is messy. Revisit the field table
-// and Value classes with a traits-based approach.
-//
template <class T> T default_value() { return T(); }
template <> int default_value<int>() { return 0; }
template <> u_int64_t default_value<u_int64_t>() { return 0; }
@@ -117,9 +114,11 @@ void FieldTable::encode(Buffer& buffer) const{
}
void FieldTable::decode(Buffer& buffer){
- u_int32_t size = buffer.getLong();
- int leftover = buffer.available() - size;
-
+ u_int32_t len = buffer.getLong();
+ u_int32_t available = buffer.available();
+ if (available < len)
+ THROW_QPID_ERROR(FRAMING_ERROR, "Not enough data for field table.");
+ u_int32_t leftover = available - len;
while(buffer.available() > leftover){
std::string name;
buffer.getShortString(name);
diff --git a/cpp/common/framing/src/InitiationHandler.cpp b/cpp/common/framing/src/InitiationHandler.cpp
new file mode 100644
index 0000000000..9c18facf44
--- /dev/null
+++ b/cpp/common/framing/src/InitiationHandler.cpp
@@ -0,0 +1,21 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 "InitiationHandler.h"
+
+qpid::framing::InitiationHandler::~InitiationHandler() {}
diff --git a/cpp/common/framing/src/InputHandler.cpp b/cpp/common/framing/src/InputHandler.cpp
new file mode 100644
index 0000000000..7116caa24a
--- /dev/null
+++ b/cpp/common/framing/src/InputHandler.cpp
@@ -0,0 +1,21 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 "InputHandler.h"
+
+qpid::framing::InputHandler::~InputHandler() {}
diff --git a/cpp/common/framing/src/OutputHandler.cpp b/cpp/common/framing/src/OutputHandler.cpp
new file mode 100644
index 0000000000..8d99b4ef92
--- /dev/null
+++ b/cpp/common/framing/src/OutputHandler.cpp
@@ -0,0 +1,21 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 "OutputHandler.h"
+
+qpid::framing::OutputHandler::~OutputHandler() {}
diff --git a/cpp/common/framing/test/BodyHandlerTest.cpp b/cpp/common/framing/test/BodyHandlerTest.cpp
index 94038d9a6c..1cad6afe02 100644
--- a/cpp/common/framing/test/BodyHandlerTest.cpp
+++ b/cpp/common/framing/test/BodyHandlerTest.cpp
@@ -17,11 +17,7 @@
*/
#include <iostream>
#include "amqp_framing.h"
-#include <cppunit/TestCase.h>
-#include <cppunit/TextTestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
-
+#include "qpid_test_plugin.h"
using namespace qpid::framing;
class BodyHandlerTest : public CppUnit::TestCase
diff --git a/cpp/common/framing/test/field_table_test.cpp b/cpp/common/framing/test/field_table_test.cpp
index 48332e05bc..535f7f4a08 100644
--- a/cpp/common/framing/test/field_table_test.cpp
+++ b/cpp/common/framing/test/field_table_test.cpp
@@ -17,10 +17,7 @@
*/
#include <iostream>
#include "amqp_framing.h"
-#include <cppunit/TestCase.h>
-#include <cppunit/TextTestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
+#include <qpid_test_plugin.h>
using namespace qpid::framing;
diff --git a/cpp/common/framing/test/framing_test.cpp b/cpp/common/framing/test/framing_test.cpp
index 1978c2cbed..8c69f8718a 100644
--- a/cpp/common/framing/test/framing_test.cpp
+++ b/cpp/common/framing/test/framing_test.cpp
@@ -19,10 +19,7 @@
#include "ConnectionRedirectBody.h"
#include <iostream>
#include <sstream>
-#include <cppunit/TestCase.h>
-#include <cppunit/TextTestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
+#include <qpid_test_plugin.h>
#include <typeinfo>
using namespace qpid::framing;
diff --git a/cpp/common/framing/test/header_test.cpp b/cpp/common/framing/test/header_test.cpp
index 0ff6d47d57..f98dd5d108 100644
--- a/cpp/common/framing/test/header_test.cpp
+++ b/cpp/common/framing/test/header_test.cpp
@@ -17,10 +17,7 @@
*/
#include <iostream>
#include "amqp_framing.h"
-#include <cppunit/TestCase.h>
-#include <cppunit/TextTestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
+#include <qpid_test_plugin.h>
using namespace qpid::framing;
diff --git a/cpp/common/io/Makefile b/cpp/common/io/Makefile
index e94e802afa..617b91448a 100644
--- a/cpp/common/io/Makefile
+++ b/cpp/common/io/Makefile
@@ -16,10 +16,6 @@
QPID_HOME = ../../..
include ${QPID_HOME}/cpp/options.mk
-
-# Compiler flags
-CXXFLAGS = ${DEBUG} ${OPT} -MMD -I inc -I ../concurrent/inc -I ../error/inc -I ../framing/inc -I ../framing/generated -I ${APR_HOME}/include/apr-1/
-
SOURCES := $(wildcard src/*.cpp)
OBJECTS := $(subst .cpp,.o,$(SOURCES))
DEPS := $(subst .cpp,.d,$(SOURCES))
diff --git a/cpp/common/io/inc/APRConnector.h b/cpp/common/io/inc/APRConnector.h
index c292c4d7e0..c6ed887f78 100644
--- a/cpp/common/io/inc/APRConnector.h
+++ b/cpp/common/io/inc/APRConnector.h
@@ -68,7 +68,7 @@ namespace io {
void checkIdle(apr_status_t status);
void writeBlock(qpid::framing::AMQDataBlock* data);
- void writeToSocket(char* data, int available);
+ void writeToSocket(char* data, size_t available);
void setSocketTimeout();
void run();
diff --git a/cpp/common/io/inc/ConnectorImpl.h b/cpp/common/io/inc/ConnectorImpl.h
index 242f3aed49..1abb72f32a 100644
--- a/cpp/common/io/inc/ConnectorImpl.h
+++ b/cpp/common/io/inc/ConnectorImpl.h
@@ -32,7 +32,7 @@ namespace io {
{
public:
- ConnectorImpl(bool debug = false, u_int32_t buffer_size = 1024):APRConnector(debug,buffer_size){};
+ ConnectorImpl(bool _debug = false, u_int32_t buffer_size = 1024):APRConnector(_debug,buffer_size){};
virtual ~ConnectorImpl(){};
};
#else
@@ -40,7 +40,7 @@ namespace io {
{
public:
- ConnectorImpl(bool debug = false, u_int32_t buffer_size = 1024):LConnector(debug, buffer_size){};
+ ConnectorImpl(bool _debug = false, u_int32_t buffer_size = 1024):LConnector(_debug, buffer_size){};
virtual ~ConnectorImpl(){};
};
diff --git a/cpp/common/io/inc/LFProcessor.h b/cpp/common/io/inc/LFProcessor.h
index 8cfbd237a3..6e67268906 100644
--- a/cpp/common/io/inc/LFProcessor.h
+++ b/cpp/common/io/inc/LFProcessor.h
@@ -48,12 +48,12 @@ namespace io {
const apr_pollfd_t* signalledFDs;
int count;
const int workerCount;
+ bool hasLeader;
qpid::concurrent::Thread** const workers;
qpid::concurrent::APRMonitor leadLock;
qpid::concurrent::APRMonitor countLock;
qpid::concurrent::APRThreadFactory factory;
std::vector<LFSessionContext*> sessions;
- bool hasLeader;
volatile bool stopped;
const apr_pollfd_t* getNextEvent();
diff --git a/cpp/common/io/src/APRConnector.cpp b/cpp/common/io/src/APRConnector.cpp
index 0e022a8c73..5f3bfd6957 100644
--- a/cpp/common/io/src/APRConnector.cpp
+++ b/cpp/common/io/src/APRConnector.cpp
@@ -26,15 +26,18 @@ using namespace qpid::concurrent;
using namespace qpid::framing;
using qpid::QpidError;
-APRConnector::APRConnector(bool _debug, u_int32_t buffer_size) : closed(true), debug(_debug),
- idleIn(0), idleOut(0), timeout(0),
- timeoutHandler(0),
- shutdownHandler(0),
- lastIn(0), lastOut(0),
- receive_buffer_size(buffer_size),
- send_buffer_size(buffer_size),
- inbuf(receive_buffer_size),
- outbuf(send_buffer_size){
+APRConnector::APRConnector(bool _debug, u_int32_t buffer_size) :
+ debug(_debug),
+ receive_buffer_size(buffer_size),
+ send_buffer_size(buffer_size),
+ closed(true),
+ lastIn(0), lastOut(0),
+ timeout(0),
+ idleIn(0), idleOut(0),
+ timeoutHandler(0),
+ shutdownHandler(0),
+ inbuf(receive_buffer_size),
+ outbuf(send_buffer_size){
APRBase::increment();
@@ -104,7 +107,7 @@ void APRConnector::writeBlock(AMQDataBlock* data){
writeLock->release();
}
-void APRConnector::writeToSocket(char* data, int available){
+void APRConnector::writeToSocket(char* data, size_t available){
apr_size_t bytes(available);
apr_size_t written(0);
while(written < available && !closed){
diff --git a/cpp/common/io/src/APRSocket.cpp b/cpp/common/io/src/APRSocket.cpp
index 32861ea442..1ef7e270a3 100644
--- a/cpp/common/io/src/APRSocket.cpp
+++ b/cpp/common/io/src/APRSocket.cpp
@@ -17,7 +17,7 @@
*/
#include "APRBase.h"
#include "APRSocket.h"
-
+#include <assert.h>
#include <iostream>
using namespace qpid::io;
@@ -45,6 +45,8 @@ void APRSocket::write(qpid::framing::Buffer& buffer){
do{
bytes = buffer.available();
apr_status_t s = apr_socket_send(socket, buffer.start(), &bytes);
+ // TODO aconway 2006-10-05: better error handling
+ assert(s == 0);
buffer.move(bytes);
}while(bytes > 0);
}
diff --git a/cpp/common/io/src/BlockingAPRAcceptor.cpp b/cpp/common/io/src/BlockingAPRAcceptor.cpp
index 380318bcfa..bf74260a55 100644
--- a/cpp/common/io/src/BlockingAPRAcceptor.cpp
+++ b/cpp/common/io/src/BlockingAPRAcceptor.cpp
@@ -24,10 +24,11 @@ using namespace qpid::concurrent;
using namespace qpid::framing;
using namespace qpid::io;
-BlockingAPRAcceptor::BlockingAPRAcceptor(bool _debug, int c) : connectionBacklog(c),
- threadFactory(new APRThreadFactory()),
- debug(_debug){
-
+BlockingAPRAcceptor::BlockingAPRAcceptor(bool _debug, int c) :
+ debug(_debug),
+ threadFactory(new APRThreadFactory()),
+ connectionBacklog(c)
+{
APRBase::increment();
CHECK_APR_SUCCESS(apr_pool_create(&apr_pool, NULL));
}
diff --git a/cpp/common/io/src/BlockingAPRSessionContext.cpp b/cpp/common/io/src/BlockingAPRSessionContext.cpp
index 99352c90d5..6d1dc3470c 100644
--- a/cpp/common/io/src/BlockingAPRSessionContext.cpp
+++ b/cpp/common/io/src/BlockingAPRSessionContext.cpp
@@ -15,6 +15,7 @@
* limitations under the License.
*
*/
+#include <assert.h>
#include <iostream>
#include "BlockingAPRSessionContext.h"
#include "BlockingAPRAcceptor.h"
@@ -32,10 +33,10 @@ BlockingAPRSessionContext::BlockingAPRSessionContext(apr_socket_t* _socket,
bool _debug)
: socket(_socket),
debug(_debug),
- inbuf(65536),
- outbuf(65536),
handler(0),
acceptor(_acceptor),
+ inbuf(65536),
+ outbuf(65536),
closed(false){
reader = new Reader(this);
@@ -73,9 +74,9 @@ void BlockingAPRSessionContext::read(){
inbuf.flip();
if(!initiated){
- ProtocolInitiation* init = new ProtocolInitiation();
- if(init->decode(inbuf)){
- handler->initiated(init);
+ ProtocolInitiation* protocolInit = new ProtocolInitiation();
+ if(protocolInit->decode(inbuf)){
+ handler->initiated(protocolInit);
if(debug) std::cout << "RECV: [" << &socket << "]: Initialised " << std::endl;
initiated = true;
}
@@ -122,6 +123,7 @@ void BlockingAPRSessionContext::write(){
apr_size_t bytes = available;
while(available > written){
apr_status_t s = apr_socket_send(socket, data + written, &bytes);
+ assert(s == 0); // TODO aconway 2006-10-05: Error Handling.
written += bytes;
bytes = available - written;
}
@@ -146,9 +148,8 @@ void BlockingAPRSessionContext::send(AMQFrame* frame){
}
}
-void BlockingAPRSessionContext::init(SessionHandler* handler){
- this->handler = handler;
- //start the threads
+void BlockingAPRSessionContext::init(SessionHandler* _handler){
+ handler = _handler;
rThread->start();
wThread->start();
}
diff --git a/cpp/common/io/src/LFAcceptor.cpp b/cpp/common/io/src/LFAcceptor.cpp
index 6653e926db..bb5164f457 100644
--- a/cpp/common/io/src/LFAcceptor.cpp
+++ b/cpp/common/io/src/LFAcceptor.cpp
@@ -21,12 +21,12 @@
using namespace qpid::concurrent;
using namespace qpid::io;
-LFAcceptor::LFAcceptor(bool _debug, int c, int worker_threads, int m) : processor(aprPool.pool, worker_threads, 1000, 5000000),
- connectionBacklog(c),
- max_connections_per_processor(m),
- debug(_debug){
-
-}
+LFAcceptor::LFAcceptor(bool _debug, int c, int worker_threads, int m) :
+ processor(aprPool.pool, worker_threads, 1000, 5000000),
+ max_connections_per_processor(m),
+ debug(_debug),
+ connectionBacklog(c)
+{ }
void LFAcceptor::bind(int port, SessionHandlerFactory* factory){
diff --git a/cpp/common/io/src/LFProcessor.cpp b/cpp/common/io/src/LFProcessor.cpp
index 8ef3543b8f..3ac66576e3 100644
--- a/cpp/common/io/src/LFProcessor.cpp
+++ b/cpp/common/io/src/LFProcessor.cpp
@@ -25,15 +25,17 @@ using namespace qpid::io;
using namespace qpid::concurrent;
using qpid::QpidError;
-LFProcessor::LFProcessor(apr_pool_t* pool, int _workers, int _size, int _timeout) : size(_size),
- timeout(_timeout),
- signalledCount(0),
- current(0),
- count(0),
- hasLeader(false),
- workerCount(_workers),
- workers(new Thread*[_workers]),
- stopped(false){
+LFProcessor::LFProcessor(apr_pool_t* pool, int _workers, int _size, int _timeout) :
+ size(_size),
+ timeout(_timeout),
+ signalledCount(0),
+ current(0),
+ count(0),
+ workerCount(_workers),
+ hasLeader(false),
+ workers(new Thread*[_workers]),
+ stopped(false)
+{
CHECK_APR_SUCCESS(apr_pollset_create(&pollset, size, pool, APR_POLLSET_THREADSAFE));
//create & start the required number of threads
@@ -87,17 +89,13 @@ void LFProcessor::update(const apr_pollfd_t* const fd){
}
bool LFProcessor::full(){
- countLock.acquire();
- bool full = count == size;
- countLock.release();
- return full;
+ Locker locker(countLock);
+ return count == size;
}
bool LFProcessor::empty(){
- countLock.acquire();
- bool empty = count == 0;
- countLock.release();
- return empty;
+ Locker locker(countLock);
+ return count == 0;
}
void LFProcessor::poll(){
diff --git a/cpp/common/io/src/LFSessionContext.cpp b/cpp/common/io/src/LFSessionContext.cpp
index d786cb5e98..7b8208f704 100644
--- a/cpp/common/io/src/LFSessionContext.cpp
+++ b/cpp/common/io/src/LFSessionContext.cpp
@@ -26,17 +26,19 @@ using namespace qpid::framing;
LFSessionContext::LFSessionContext(apr_pool_t* _pool, apr_socket_t* _socket,
LFProcessor* const _processor,
- bool _debug) : socket(_socket),
- processor(_processor),
- initiated(false),
- processing(false),
- closing(false),
- in(32768),
- out(32768),
- reading(0),
- writing(0),
- debug(_debug){
-
+ bool _debug) :
+ debug(_debug),
+ socket(_socket),
+ initiated(false),
+ in(32768),
+ out(32768),
+ processor(_processor),
+ processing(false),
+ closing(false),
+ reading(0),
+ writing(0)
+{
+
fd.p = _pool;
fd.desc_type = APR_POLL_SOCKET;
fd.reqevents = APR_POLLIN;
@@ -63,9 +65,9 @@ void LFSessionContext::read(){
handler->received(&frame);
}
}else{
- ProtocolInitiation init;
- if(init.decode(in)){
- handler->initiated(&init);
+ ProtocolInitiation protocolInit;
+ if(protocolInit.decode(in)){
+ handler->initiated(&protocolInit);
initiated = true;
if(debug) std::cout << "INIT [" << &socket << "]" << std::endl;
}
@@ -173,8 +175,8 @@ void LFSessionContext::shutdown(){
handleClose();
}
-void LFSessionContext::init(SessionHandler* handler){
- this->handler = handler;
+void LFSessionContext::init(SessionHandler* _handler){
+ handler = _handler;
processor->add(&fd);
}
diff --git a/cpp/common/utils/inc/logger.h b/cpp/common/utils/inc/logger.h
deleted file mode 100644
index 8a57854476..0000000000
--- a/cpp/common/utils/inc/logger.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-/*********************************************************************
-*
-* NOTE: This is a lightweight logging class intended for debugging and
-* verification purposes only.
-*
-* DO NOT USE FOR PRODUCT DEVELOPMENT - Rather, use an agreed upon
-* established logging class (such as Apache's log4cxx) for product
-* development purposes.
-*
-*********************************************************************/
-
-#ifndef __LOGGER__
-#define __LOGGER__
-
-#include <fstream>
-#include <iostream>
-
-namespace qpid {
-namespace utils {
-
-class Logger : public std::ofstream
-{
- private:
- bool echo_flag;
- bool timestamp_flag;
- bool eol_flag;
- char buff[128]; // Buffer for writing formatted strings
-
- void write_timestamp();
-
- public:
- Logger(const char* filename, const bool append);
- Logger(std::string& filename, const bool append);
- ~Logger();
-
- bool getEchoFlag() {return echo_flag;}
- bool setEchoFlag(const bool _echo_flag) {echo_flag = _echo_flag;}
- bool getTimestampFlag() {return timestamp_flag;}
- bool setTimestampFlag(const bool _timestamp_flag) {timestamp_flag = _timestamp_flag;}
-
- void log(const char* message);
- void log(const char* message, const bool echo);
- void log(const char* message, const bool echo, const bool timestamp);
-
- Logger& operator<< (bool b);
- Logger& operator<< (const short s);
- Logger& operator<< (const unsigned short us);
- Logger& operator<< (const int i);
- Logger& operator<< (const unsigned int ui);
- Logger& operator<< (const long l);
- Logger& operator<< (const unsigned long ul);
- Logger& operator<< (const long long l);
- Logger& operator<< (const unsigned long long ul);
- Logger& operator<< (const float f);
- Logger& operator<< (const double d);
- Logger& operator<< (const long double ld);
- Logger& operator<< (const char* cstr);
- Logger& operator<< (const std::string& str);
-};
-
-}
-}
-
-
-#endif
diff --git a/cpp/common/utils/src/Makefile b/cpp/common/utils/src/Makefile
index 0185ab9975..b0ab76973c 100644
--- a/cpp/common/utils/src/Makefile
+++ b/cpp/common/utils/src/Makefile
@@ -13,13 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-##### Options #####
-QPID_HOME = ../../../..
-
-include ${QPID_HOME}/cpp/options.mk
-##### Compiler flags #####
-CXXFLAGS = -I ../inc -I ${APR_HOME}/include/apr-1/
+QPID_HOME = ../../../..
+include $(QPID_HOME)/cpp/options.mk
+INCLUDES=$(TEST_INCLUDES)
##### Targets #####
# Add additional source files to SOURCE LIST to include them in the build.
diff --git a/cpp/common/utils/src/logger.cpp b/cpp/common/utils/src/logger.cpp
deleted file mode 100644
index 603fa6574e..0000000000
--- a/cpp/common/utils/src/logger.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-/*********************************************************************
-*
-* NOTE: This is a lightweight logging class intended for debugging and
-* verification purposes only.
-*
-* DO NOT USE FOR PRODUCT DEVELOPMENT - Rather, use an agreed upon
-* established logging class (such as Apache's log4cxx) for product
-* development purposes.
-*
-*********************************************************************/
-
-#include <iostream>
-#include <ostream>
-#include <string.h>
-#include "apr_time.h"
-#include "logger.h"
-
-namespace qpid {
-namespace utils {
-
-Logger::Logger(const char* filename, const bool append):
- std::ofstream(filename, append ? std::ios::app : std::ios::out)
-{
- echo_flag = false;
- timestamp_flag = true;
- eol_flag = true;
-}
-
-Logger::Logger(std::string& filename, const bool append):
- std::ofstream(filename.c_str(), append ? std::ios::app : std::ios::out)
-{
- echo_flag = false;
- timestamp_flag = true;
- eol_flag = true;
-}
-
-Logger::~Logger()
-{
- close();
-}
-
-void Logger::write_timestamp()
-{
- int len;
- apr_time_exp_t now;
- apr_time_exp_lt(&now, apr_time_now());
- sprintf(buff, "%4d/%02d/%02d %02d:%02d:%02d.%06d : ", 1900+now.tm_year, now.tm_mon,
- now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, now.tm_usec);
- write(buff, strlen(buff));
-}
-
-
-void Logger::log(const char* message)
-{
- if (timestamp_flag && eol_flag)
- {
- eol_flag = false;
- write_timestamp();
- }
- write(message, strlen(message));
- if (echo_flag)
- std::cout << message;
- if (strchr(message, '\n'))
- eol_flag = true;
-}
-
-void Logger::log(const char* message, const bool echo)
-{
- if (timestamp_flag && eol_flag)
- {
- eol_flag = false;
- write_timestamp();
- }
- write(message, strlen(message));
- if (echo)
- std::cout << message;
- if (strchr(message, '\n'))
- eol_flag = true;
-}
-
-void Logger::log(const char* message, const bool echo, const bool timestamp)
-{
- if (timestamp && eol_flag)
- {
- eol_flag = false;
- write_timestamp();
- }
- write(message, strlen(message));
- if (echo)
- std::cout << message;
- if (strchr(message, '\n'))
- eol_flag = true;
-}
-
-Logger& Logger::operator<< (const bool b)
-{
- log(b ? "true" : "false");
- return *this;
-}
-
-Logger& Logger::operator<< (const short s)
-{
- sprintf(buff, "%d", s);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const unsigned short us)
-{
- sprintf(buff, "%u", us);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const int i)
-{
- sprintf(buff, "%d", i);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const unsigned int ui)
-{
- sprintf(buff, "%u", ui);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const long l)
-{
- sprintf(buff, "%ld", l);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const unsigned long ul)
-{
- sprintf(buff, "%lu", ul);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const long long l)
-{
- sprintf(buff, "%ld", l);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const unsigned long long ul)
-{
- sprintf(buff, "%lu", ul);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const float f)
-{
- sprintf(buff, "%f", f);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const double d)
-{
- sprintf(buff, "%lf", d);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const long double ld)
-{
- sprintf(buff, "%Lf", ld);
- log(buff);
- return *this;
-}
-
-Logger& Logger::operator<< (const char* cstr)
-{
- log(cstr);
- return *this;
-}
-
-Logger& Logger::operator<< (const std::string& str)
-{
- log(str.c_str());
- return *this;
-}
-
-}
-}
-
diff --git a/cpp/common/utils/src/logger_test.cpp b/cpp/common/utils/src/logger_test.cpp
deleted file mode 100644
index 1866af9fbb..0000000000
--- a/cpp/common/utils/src/logger_test.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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 <iostream>
-#include <string>
-#include "logger.h"
-
-using namespace qpid::utils;
-
-void run_sequence(Logger& log)
-{
- bool b = true;
- short s = -5;
- unsigned short us = 12;
- int i = -2345;
- unsigned int ui = 34567;
- long l = -12345678;
- unsigned long ul = 23456789;
- long long ll = -1234567890;
- unsigned long long ull = 1234567890;
- float f = -123.45678;
- double d = 123.45678901;
- long double ld = 23456.789012345678;
- char* cstr = "This is a test C string.";
- char* cr = "\n";
- std::string str("This is a test std::string");
- log << "bool = " << b << cr;
- log << "short = " << s << cr;
- log << "unsigned sort = " << us << cr;
- log << "int = " << i << cr;
- log << "unsigned int = " << ui << cr;
- log << "long = " << l << cr;
- log << "unsigned long = " << ul << cr;
- log << "long long = " << ll << cr;
- log << "unsigned long long = " << ull << cr;
- log << "float = " << f << cr;
- log << "double = " << d << cr;
- log << "long double = " << ld << cr;
- log << "char* = " << cstr << cr;
- log << "std::string = " << str << cr;
- log << "String 1\n";
- log << "String 2\n" << "String 3 " << "String 4\n";
- log << "Literal bool = " << false << cr;
- log << "Literal unsigned int = " << 15 << cr;
- log << "Literal double = " << (double)15 << cr;
-}
-
-int main(int argc, char** argv)
-{
- Logger log("test_log.txt", false);
- std::cout << "****** Initial state (echo off, timestamp on)" << std::endl;
- run_sequence(log);
- std::cout << std::endl << "****** (echo off, timestamp off)" << std::endl;
- log.setTimestampFlag(false);
- run_sequence(log);
- std::cout << std::endl << "****** (echo on, timestamp on)" << std::endl;
- log.setEchoFlag(true);
- log.setTimestampFlag(true);
- run_sequence(log);
- std::cout << std::endl << "****** (echo on, timestamp off)" << std::endl;
- log.setTimestampFlag(false);
- run_sequence(log);
- return 0;
-}