From c7d74bee17171a715af7b4a3a633938604ebdb09 Mon Sep 17 00:00:00 2001 From: David Brodsky Date: Sun, 6 Aug 2006 10:54:36 +0200 Subject: [PATCH] Add close() and isActive() methods to Tairon::Net::HTTPClient. --- src/net-http/httpclient.cpp | 21 +++++++++++++++++++-- src/net-http/httpclient.h | 9 +++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/net-http/httpclient.cpp b/src/net-http/httpclient.cpp index e9851ec..f71753c 100644 --- a/src/net-http/httpclient.cpp +++ b/src/net-http/httpclient.cpp @@ -55,6 +55,17 @@ void HTTPClient::clearParameters() } /* }}} */ +/* {{{ HTTPClient::close() */ +void HTTPClient::close() +{ + if (!socket) // there is nothing to do + return; + + delete socket; + socket = 0; +} +/* }}} */ + /* {{{ HTTPClient::connected(Tairon::Net::Socket *) */ void HTTPClient::connected(Tairon::Net::Socket *) { @@ -121,6 +132,13 @@ void HTTPClient::get(const String &what) } /* }}} */ +/* {{{ HTTPClient::isActive() */ +bool HTTPClient::isActive() +{ + return socket != 0; +} +/* }}} */ + /* {{{ HTTPClient::prepareParameters() */ String HTTPClient::prepareParameters() { @@ -200,8 +218,7 @@ void HTTPClient::readyRead(Tairon::Net::Socket *) if (!socket) // connection has been closed dataReadSignal.emit(this); } catch (const char *e) { // invalid data received - delete socket; // close connection - socket = 0; + close(); errorSignal.emit(this, e, 0); } } diff --git a/src/net-http/httpclient.h b/src/net-http/httpclient.h index b9fe970..2c34184 100644 --- a/src/net-http/httpclient.h +++ b/src/net-http/httpclient.h @@ -55,6 +55,10 @@ class HTTPClient */ void clearParameters(); + /** Closes the connection to the server if it is opened. + */ + void close(); + /** Deletes given parameter from list. */ void delParameter(const String &key); @@ -78,6 +82,11 @@ class HTTPClient return data; }; + /** Returns true if there is an active connection to the server; + * otherwise returns false. + */ + bool isActive(); + /** Sets parameter of the GET method. */ void setParameter(const String &key, const String &value); -- 2.11.4.GIT