C++ Sockets Library documentation

C++ Sockets Library

Name of changed file

Version and , fileVersion and , file
Line 1 in Line 1 in
Context line
Removed line
Changed line
Context line
Context line
Changed line
Added line
Context line

Changelog

/usr/src/Sockets-2.3.9.8/Changelog 2013-04-10 19:45:55.0, 0200/usr/src/Sockets-2.3.9.9/Changelog 2013-06-22 11:00:11.0, 0200
Line 1 in ChangelogLine 1 in Changelog
diff for next release always available @ http://www.alhem.net/Sockets/latest_diff.html
2.3.9.9
--------
Make sure HttpGetSocket exits normally even when fetched resource has
zero length. Add optional connect parameter to HttpGetSocket
constructor, previous version always tried to establish a connection.
Made some methods in HTTPSocket protected, as those are only used
internally in derived classes.
Added some #include's to make library compile on never compilers.
2.3.9.8
--------

HttpClientSocket.cpp

/usr/src/Sockets-2.3.9.8/HttpClientSocket.cpp 2011-07-17 10:05:58.0, 0200/usr/src/Sockets-2.3.9.9/HttpClientSocket.cpp 2013-04-13 11:36:54.0, 0200
Line 50 in HttpClientSocket.cppLine 50 in HttpClientSocket.cpp
,m_data_size(0)
,m_content_length(0)
,m_content_length_is_set(false)
,m_data_ptr_set(false)
,m_fil(NULL)
Line 64 in HttpClientSocket.cppLine 65 in HttpClientSocket.cpp
,m_data_size(0)
,m_content_length(0)
,m_content_length_is_set(false)
,m_data_ptr_set(false)
,m_fil(NULL)
Line 81 in HttpClientSocket.cppLine 83 in HttpClientSocket.cpp
,m_data_size(0)
,m_content_length(0)
,m_content_length_is_set(false)
,m_data_ptr_set(false)
,m_fil(NULL)
Line 124 in HttpClientSocket.cppLine 127 in HttpClientSocket.cpp
{
m_content_length = atoi(value.c_str());
m_content_length_is_set = true;
}
else
Line 144 in HttpClientSocket.cppLine 148 in HttpClientSocket.cpp
}
}
else
if (!m_data_ptr && m_content_length)
{
m_data_ptr = new unsigned char[m_content_length];
m_data_size = m_content_length;
}
}
}
}
if (!m_data_ptr && m_content_length > 0)
{
m_data_ptr = new unsigned char[m_content_length];
m_data_size = m_content_length;
}
// make sure we finish in a good way even when response
// has content-length: 0
if (m_content_length_is_set && m_content_length == 0)
{
EndConnection();
}
}
void HttpClientSocket::EndConnection()
{
if (m_fil)
{
m_fil -> fclose();
delete m_fil;
m_fil = NULL;
}
m_b_complete = true;
OnContent();
if (m_b_close_when_complete)
{
SetCloseAndDelete();
}
}
Line 159 in HttpClientSocket.cppLine 185 in HttpClientSocket.cpp
m_fil -> fwrite(buf, 1, len);
}
else
if (m_data_ptr)
{
if (m_content_ptr + len > m_data_size)
{
Handler().LogError(this, "OnData", -1, "content buffer overflow", LOG_LEVEL_ERROR);
}
else
{
memcpy(m_data_ptr + m_content_ptr, buf, len);
}
}
m_content_ptr += len;
if (m_content_ptr == m_content_length && m_content_length)
{
if (m_fil)
{
m_fil -> fclose();
delete m_fil;
m_fil = NULL;
}
m_b_complete = true;
OnContent();
if (m_b_close_when_complete)
{
SetCloseAndDelete();
}
}
}
m_fil -> fwrite(buf, 1, len);
}
if (m_data_ptr)
{
size_t left = m_data_size - m_content_ptr;
size_t sz = len < left ? len : left;
if (sz > 0)
memcpy(m_data_ptr + m_content_ptr, buf, sz);
m_content_ptr += sz;
if (len > left)
{
Handler().LogError(this, "OnData", -1, "content buffer overflow", LOG_LEVEL_ERROR);
}
}
if (m_content_ptr == m_content_length && m_content_length)
{
EndConnection();
}
}

HttpClientSocket.h

/usr/src/Sockets-2.3.9.8/HttpClientSocket.h 2011-07-17 10:03:08.0, 0200/usr/src/Sockets-2.3.9.9/HttpClientSocket.h 2013-04-13 11:36:54.0, 0200
Line 108 in HttpClientSocket.hLine 108 in HttpClientSocket.h
HttpClientSocket& operator=(const HttpClientSocket& ) { return *this; } // assignment operator
private:
void EndConnection();
std::string m_filename; ///< Filename to write response to
unsigned char *m_data_ptr; ///< Ptr to buffer where to store response
size_t m_data_size; ///< Max size of data buffer
size_t m_content_length; ///< Content-length header received from remote
bool m_content_length_is_set;
std::string m_content; ///< Received http headers
bool m_data_ptr_set; ///< Buffer set from outside, do not delete

HttpGetSocket.cpp

/usr/src/Sockets-2.3.9.8/HttpGetSocket.cpp 2011-09-23 16:34:47.0, 0200/usr/src/Sockets-2.3.9.9/HttpGetSocket.cpp 2013-05-11 09:25:08.0, 0200
Line 51 in HttpGetSocket.cppLine 51 in HttpGetSocket.cpp
HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& url_in,const std::string& to_file) : HttpClientSocket(h, url_in)
{
if (to_file.size())
HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& url_in,const std::string& to_file, bool connect) : HttpClientSocket(h, url_in)
{
if (to_file.size())
Line 57 in HttpGetSocket.cppLine 57 in HttpGetSocket.cpp
SetFilename(to_file);
}
if (!Open(GetUrlHost(),GetUrlPort()))
{
if (!Connecting())
SetFilename(to_file);
}
if (connect)
DoConnect();
}
void HttpGetSocket::DoConnect()
{
DoConnect(GetUrlHost(), GetUrlPort());
}
void HttpGetSocket::DoConnect(const std::string& host, unsigned short port)
{
if (!Open(host, port))
{
if (!Connecting())
Line 68 in HttpGetSocket.cppLine 81 in HttpGetSocket.cpp
HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& host,port_t port,const std::string& url,const std::string& to_file) : HttpClientSocket(h, host, port, url)
{
SetUrl(url);
HttpGetSocket::HttpGetSocket(ISocketHandler& h,const std::string& host,port_t port,const std::string& url,const std::string& to_file, bool connect) : HttpClientSocket(h, host, port, url)
{
SetUrl(url);
Line 75 in HttpGetSocket.cppLine 88 in HttpGetSocket.cpp
SetFilename(to_file);
}
if (!Open(host, port))
{
if (!Connecting())
{
Handler().LogError(this, "HttpGetSocket", -1, "connect() failed miserably", LOG_LEVEL_FATAL);
SetCloseAndDelete();
}
}
}
SetFilename(to_file);
}
if (connect)
DoConnect(host, port);
}

HttpGetSocket.h

/usr/src/Sockets-2.3.9.8/HttpGetSocket.h 2011-07-17 10:03:15.0, 0200/usr/src/Sockets-2.3.9.9/HttpGetSocket.h 2013-05-11 09:25:24.0, 0200
Line 47 in HttpGetSocket.hLine 47 in HttpGetSocket.h
public:
HttpGetSocket(ISocketHandler&);
HttpGetSocket(ISocketHandler&,const std::string& url,const std::string& to_file = "");
HttpGetSocket(ISocketHandler&,const std::string& host,port_t port,const std::string& url,const std::string& to_file = "");
~HttpGetSocket();
void OnConnect();
public:
HttpGetSocket(ISocketHandler&);
HttpGetSocket(ISocketHandler&,const std::string& url,const std::string& to_file = "", bool connect = true);
HttpGetSocket(ISocketHandler&,const std::string& host,port_t port,const std::string& url,const std::string& to_file = "", bool connect = true);
~HttpGetSocket();
void DoConnect();
void DoConnect(const std::string& host, unsigned short port);
void OnConnect();

HTTPSocket.cpp

/usr/src/Sockets-2.3.9.8/HTTPSocket.cpp 2011-09-30 20:26:08.0, 0200/usr/src/Sockets-2.3.9.9/HTTPSocket.cpp 2013-04-13 11:36:54.0, 0200
Line 354 in HTTPSocket.cppLine 354 in HTTPSocket.cpp
const std::string& HTTPSocket::GetMethod()
{
return m_method;
const std::string& HTTPSocket::GetMethod() const
{
return m_method;
Line 366 in HTTPSocket.cppLine 366 in HTTPSocket.cpp
const std::string& HTTPSocket::GetUrl()
{
return m_url;
const std::string& HTTPSocket::GetUrl() const
{
return m_url;
Line 378 in HTTPSocket.cppLine 378 in HTTPSocket.cpp
const std::string& HTTPSocket::GetUri()
{
return m_uri;
const std::string& HTTPSocket::GetUri() const
{
return m_uri;
Line 384 in HTTPSocket.cppLine 384 in HTTPSocket.cpp
const std::string& HTTPSocket::GetQueryString()
{
return m_query_string;
const std::string& HTTPSocket::GetQueryString() const
{
return m_query_string;
Line 390 in HTTPSocket.cppLine 390 in HTTPSocket.cpp
const std::string& HTTPSocket::GetHttpVersion()
{
return m_http_version;
const std::string& HTTPSocket::GetHttpVersion() const
{
return m_http_version;
Line 396 in HTTPSocket.cppLine 396 in HTTPSocket.cpp
const std::string& HTTPSocket::GetStatus()
{
return m_status;
const std::string& HTTPSocket::GetStatus() const
{
return m_status;
Line 402 in HTTPSocket.cppLine 402 in HTTPSocket.cpp
const std::string& HTTPSocket::GetStatusText()
{
return m_status_text;
const std::string& HTTPSocket::GetStatusText() const
{
return m_status_text;
Line 408 in HTTPSocket.cppLine 408 in HTTPSocket.cpp
bool HTTPSocket::IsRequest()
{
return m_request;
bool HTTPSocket::IsRequest() const
{
return m_request;
Line 414 in HTTPSocket.cppLine 414 in HTTPSocket.cpp
bool HTTPSocket::IsResponse()
{
return m_response;
bool HTTPSocket::IsResponse() const
{
return m_response;
Line 505 in HTTPSocket.cppLine 505 in HTTPSocket.cpp
bool HTTPSocket::ResponseHeaderIsSet(const std::string& name)
{
string_m::iterator it = m_response_header.find( name );
if (it != m_response_header.end())
{
return true;
}
std::list<std::pair<std::string, std::string> >::iterator it2;
for (it2 = m_response_header_append.begin(); it2 != m_response_header_append.end(); ++it2)
{
std::pair<std::string, std::string>& ref = *it2;
if (!strcasecmp(ref.first.c_str(), name.c_str()) )
{
bool HTTPSocket::ResponseHeaderIsSet(const std::string& name) const
{
string_m::const_iterator it = m_response_header.find( name );
if (it != m_response_header.end())
{
return true;
}
std::list<std::pair<std::string, std::string> >::const_iterator it2;
for (it2 = m_response_header_append.begin(); it2 != m_response_header_append.end(); ++it2)
{
const std::pair<std::string, std::string>& ref = *it2;
if (!strcasecmp(ref.first.c_str(), name.c_str()) )
{

HTTPSocket.h

/usr/src/Sockets-2.3.9.8/HTTPSocket.h 2011-07-17 10:03:23.0, 0200/usr/src/Sockets-2.3.9.9/HTTPSocket.h 2013-04-13 11:39:05.0, 0200
Line 71 in HTTPSocket.hLine 71 in HTTPSocket.h
/** Get http method from incoming request, ie GET/POST/PUT etc */
const std::string& GetMethod();
/** Set http method to be used in request. */
void SetMethod(const std::string& x);
/** Get url from request. */
const std::string& GetUrl();
/** Set url to be used in outgoing request. */
void SetUrl(const std::string& x);
/** Get part of url before '?' character. */
const std::string& GetUri();
/** Now why would I need this when there is a SetUrl method? */
void SetUri(const std::string& x);
/** Get part of url after '?' character. */
const std::string& GetQueryString();
/** Get http version from incoming request/response. */
const std::string& GetHttpVersion();
/** Get http status from incoming response. */
const std::string& GetStatus();
/** Get http statustext from incoming response. */
const std::string& GetStatusText();
/** Incoming header has been identified as a request (method url http_version\r\n). */
bool IsRequest();
/** Incoming header has been identified as a response (http_version status status_text\r\n). */
bool IsResponse();
/** Set http version to be used in outgoing request/response. */
void SetHttpVersion(const std::string& x);
/** Get http method from incoming request, ie GET/POST/PUT etc */
const std::string& GetMethod() const;
public:
/** Get url from request. */
const std::string& GetUrl() const;
/** Get part of url before '?' character. */
const std::string& GetUri() const;
/** Get part of url after '?' character. */
const std::string& GetQueryString() const;
/** Get http version from incoming request/response. */
const std::string& GetHttpVersion() const;
/** Get http status from incoming response. */
const std::string& GetStatus() const;
/** Get http statustext from incoming response. */
const std::string& GetStatusText() const;
/** Incoming header has been identified as a request (method url http_version\r\n). */
bool IsRequest() const;
/** Incoming header has been identified as a response (http_version status status_text\r\n). */
bool IsResponse() const;
/** Set http version to be used in outgoing request/response. */
void SetHttpVersion(const std::string& x);
Line 107 in HTTPSocket.hLine 104 in HTTPSocket.h
void AppendResponseHeader(const std::string& x,const std::string& y);
/** See if http header 'name' has been set. */
bool ResponseHeaderIsSet(const std::string& name);
/** Send response prepared with calls to methods SetHttpVersion, SetStatus, SetStatusText,
and AddResponseHeader. */
void AppendResponseHeader(const std::string& x,const std::string& y);
/** See if http header 'name' has been set. */
bool ResponseHeaderIsSet(const std::string& name) const;
/** Send response prepared with calls to methods SetHttpVersion, SetStatus, SetStatusText,
and AddResponseHeader. */
Line 122 in HTTPSocket.hLine 119 in HTTPSocket.h
/** Transfer coding 'chunked' */
bool IsChunked() { return m_b_chunked; }
protected:
/** Transfer coding 'chunked' */
bool IsChunked() const { return m_b_chunked; }
protected:
Line 131 in HTTPSocket.hLine 128 in HTTPSocket.h
void SetMaxHeaderCount(int x) { m_max_header_count = x; }
/** Set http method to be used in request. */
void SetMethod(const std::string& x);
/** Set url to be used in outgoing request. */
void SetUrl(const std::string& x);
/** Now why would I need this when there is a SetUrl method? */
void SetUri(const std::string& x);
private:
HTTPSocket& operator=(const HTTPSocket& ) { return *this; }

IFile.h

/usr/src/Sockets-2.3.9.8/IFile.h 2011-07-17 10:03:32.0, 0200/usr/src/Sockets-2.3.9.9/IFile.h 2013-04-21 10:52:06.0, 0200
Line 35 in IFile.hLine 35 in IFile.h
#include "sockets-config.h"
#include <string>
#include <cstdio>
#ifdef SOCKETS_NAMESPACE

Ipv6Address.cpp

/usr/src/Sockets-2.3.9.8/Ipv6Address.cpp 2011-07-17 10:06:18.0, 0200/usr/src/Sockets-2.3.9.9/Ipv6Address.cpp 2013-04-13 11:36:54.0, 0200
Line 39 in Ipv6Address.cppLine 39 in Ipv6Address.cpp
#endif
#ifdef IPPROTO_IPV6
#include <cstdio>
#ifdef SOCKETS_NAMESPACE

Makefile.Defines.linux-x86-32

/usr/src/Sockets-2.3.9.8/Makefile.Defines.linux-x86-32 2013-03-13 15:13:31.0, 0100/usr/src/Sockets-2.3.9.9/Makefile.Defines.linux-x86-32 2013-04-21 10:53:03.0, 0200
Line 32 in Makefile.Defines.linux-x86-32Line 32 in Makefile.Defines.linux-x86-32
.cpp.o:
@echo [$(CXX)] Compiling $<
$(CXX) $(CFLAGS) -o $@ -c $<
.cpp.o:
@echo [$(CXX)] Compiling $<
@$(CXX) $(CFLAGS) -o $@ -c $<

Makefile.version

/usr/src/Sockets-2.3.9.8/Makefile.version 2013-04-10 19:51:21.0, 0200/usr/src/Sockets-2.3.9.9/Makefile.version 2013-04-13 11:38:16.0, 0200
Line 1 in Makefile.versionLine 1 in Makefile.version
MAJOR = 2
MINOR = 3.9.8
VERSION = $(MAJOR).$(MINOR)
DIFF_VERSION = 2.3.9.7
DEBIAN_REV = 1
MAJOR = 2
MINOR = 3.9.9
VERSION = $(MAJOR).$(MINOR)
DIFF_VERSION = 2.3.9.8
DEBIAN_REV = 1

Socket.cpp

/usr/src/Sockets-2.3.9.8/Socket.cpp 2011-08-16 12:04:36.0, 0200/usr/src/Sockets-2.3.9.9/Socket.cpp 2013-04-14 07:07:59.0, 0200
Line 900 in Socket.cppLine 900 in Socket.cpp
const bool Socket::IsDetached() const
{
return m_detached;
bool Socket::IsDetached() const
{
return m_detached;

Socket.h

/usr/src/Sockets-2.3.9.8/Socket.h 2012-09-08 08:44:49.0, 0200/usr/src/Sockets-2.3.9.9/Socket.h 2013-04-14 07:07:44.0, 0200
Line 627 in Socket.hLine 627 in Socket.h
/** Check detached flag.
\return true if the socket runs in its own thread. */
const bool IsDetached() const;
/** Order this socket to start its own thread and call OnDetached
when ready for operation. */
/** Check detached flag.
\return true if the socket runs in its own thread. */
bool IsDetached() const;
/** Order this socket to start its own thread and call OnDetached
when ready for operation. */

sockets-config.h

/usr/src/Sockets-2.3.9.8/sockets-config.h 2013-04-10 19:43:56.0, 0200/usr/src/Sockets-2.3.9.9/sockets-config.h 2011-09-26 16:46:55.0, 0200
Line 99 in sockets-config.hLine 99 in sockets-config.h
/* XML classes. */
//#define ENABLE_XML
/* XML classes. */
#define ENABLE_XML

StreamSocket.h

/usr/src/Sockets-2.3.9.8/StreamSocket.h 2011-07-17 10:04:29.0, 0200/usr/src/Sockets-2.3.9.9/StreamSocket.h 2013-04-14 07:07:17.0, 0200
Line 116 in StreamSocket.hLine 116 in StreamSocket.h
protected:
StreamSocket(const StreamSocket& ) {} // copy constructor
private:
protected:
StreamSocket(const StreamSocket& src) : Socket(src) {} // copy constructor
private:

TcpSocket.h

/usr/src/Sockets-2.3.9.8/TcpSocket.h 2012-07-25 10:32:38.0, 0200/usr/src/Sockets-2.3.9.9/TcpSocket.h 2013-04-14 07:08:54.0, 0200
Line 94 in TcpSocket.hLine 94 in TcpSocket.h
private:
CircularBuffer(const CircularBuffer& s) {}
CircularBuffer& operator=(const CircularBuffer& ) { return *this; }
char *buf;
private:
CircularBuffer(const CircularBuffer& ) {}
CircularBuffer& operator=(const CircularBuffer& ) { return *this; }
char *buf;

Utility.cpp

/usr/src/Sockets-2.3.9.8/Utility.cpp 2011-09-23 16:30:45.0, 0200/usr/src/Sockets-2.3.9.9/Utility.cpp 2013-04-13 11:44:46.0, 0200
Line 284 in Utility.cppLine 284 in Utility.cpp
for (size_t i = 0; i < src.size(); ++i)
{
if (isalnum(src[i]))
{
dst += src[i];
}
else
if (src[i] == ' ')
{
dst += '+';
for (size_t i = 0; i < src.size(); ++i)
{
unsigned char c = static_cast<unsigned char>(src[i]);
if (isalnum(c))
{
dst += c;
}
else
if (c == ' ')
{
dst += '+';
Line 295 in Utility.cppLine 296 in Utility.cpp
else
{
unsigned char c = static_cast<unsigned char>(src[i]);
dst += '%';
dst += hex[c / 16];
Page, code, and content Copyright (C) 2013 by Anders Hedström