Changeset - 83ba9855b521
[Not reviewed]
0 2 0
Jan Kaluza - 10 years ago 2015-12-15 07:46:56
jkaluza@redhat.com
Fix crash after HTTPRequestQueue destruction caused by HTTP response arriving after its destruction
2 files changed with 12 insertions and 8 deletions:
0 comments (0 inline, 0 general)
include/transport/HTTPRequestQueue.h
Show inline comments
 
@@ -32,7 +32,7 @@ class HTTPRequestQueue {
 
	private:
 
		int m_delay;
 
		std::queue<HTTPRequest *> m_queue;
 
		bool m_processing;
 
		HTTPRequest *m_req;
 
		Swift::Timer::ref m_queueTimer;
 
};
 

	
src/HTTPRequestQueue.cpp
Show inline comments
 
@@ -8,7 +8,7 @@ DEFINE_LOGGER(logger, "HTTPRequestQueue")
 

	
 
HTTPRequestQueue::HTTPRequestQueue(Component *component, int delay) {
 
	m_delay = delay;
 
	m_processing = false;
 
	m_req = NULL;
 

	
 
	m_queueTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(500);
 
	m_queueTimer->onTick.connect(boost::bind(&HTTPRequestQueue::sendNextRequest, this));
 
@@ -16,6 +16,10 @@ HTTPRequestQueue::HTTPRequestQueue(Component *component, int delay) {
 

	
 
HTTPRequestQueue::~HTTPRequestQueue() {
 
	m_queueTimer->stop();
 

	
 
	if (m_req) {
 
		m_req->onRequestFinished.disconnect(boost::bind(&HTTPRequestQueue::handleRequestFinished, this));
 
	}
 
}
 

	
 
void HTTPRequestQueue::handleRequestFinished() {
 
@@ -24,25 +28,25 @@ void HTTPRequestQueue::handleRequestFinished() {
 

	
 
void HTTPRequestQueue::sendNextRequest() {
 
	if (m_queue.empty()) {
 
		m_processing = false;
 
		m_req = NULL;
 
		m_queueTimer->stop();
 
		return;
 
	}
 

	
 
	if (m_processing) {
 
	if (m_req) {
 
		return;
 
	}
 

	
 
	HTTPRequest *req = m_queue.front();
 
	m_req = m_queue.front();
 
	m_queue.pop();
 
	req->onRequestFinished.connect(boost::bind(&HTTPRequestQueue::handleRequestFinished, this));
 
	req->execute();
 
	m_req->onRequestFinished.connect(boost::bind(&HTTPRequestQueue::handleRequestFinished, this));
 
	m_req->execute();
 
}
 

	
 
void HTTPRequestQueue::queueRequest(HTTPRequest *req) {
 
	m_queue.push(req);
 

	
 
	if (!m_processing) {
 
	if (!m_req) {
 
		sendNextRequest();
 
	}
 
}
0 comments (0 inline, 0 general)