namespace Msp {
namespace Http {
-Client::Client():
- sock(0),
- event_disp(0),
- resolver(0),
- resolve_listener(0),
- resolve_tag(0),
- user_agent("libmsphttp/0.1"),
- request(0),
- response(0)
-{ }
-
Client::~Client()
{
delete sock;
void resolve_failed(unsigned, const std::exception &);
};
- Net::StreamSocket *sock;
- IO::EventDispatcher *event_disp;
- Net::Resolver *resolver;
- ResolveListener *resolve_listener;
- unsigned resolve_tag;
- std::string user_agent;
- Request *request;
- Response *response;
+ Net::StreamSocket *sock = 0;
+ IO::EventDispatcher *event_disp = 0;
+ Net::Resolver *resolver = 0;
+ ResolveListener *resolve_listener = 0;
+ unsigned resolve_tag = 0;
+ std::string user_agent = "libmspnet/1.0";
+ Request *request = 0;
+ Response *response = 0;
std::string in_buf;
Client(const Client &);
Client &operator=(const Client &);
public:
- Client();
~Client();
void use_event_dispatcher(IO::EventDispatcher *);
namespace Msp {
namespace Http {
-Message::Message():
- http_version(0x11),
- chunk_length(0),
- complete(false)
-{ }
-
void Message::set_header(const string &hdr, const string &val)
{
headers[normalize_header_name(hdr)] = val;
protected:
typedef std::map<std::string, std::string> HeaderMap;
- Version http_version;
+ Version http_version = 0x11;
HeaderMap headers;
std::string content;
- std::string::size_type chunk_length;
- bool complete;
+ std::string::size_type chunk_length = 0;
+ bool complete = false;
Variant user_data;
- Message();
+ Message() = default;
public:
virtual ~Message() = default;
namespace Http {
Server::Server():
- sock(Net::INET6),
- event_disp(0)
+ sock(Net::INET6)
{ }
Server::Server(unsigned port):
- sock(Net::INET6),
- event_disp(0)
+ sock(Net::INET6)
{
listen(port);
}
Server::Client::Client(RefPtr<Net::StreamSocket> s):
- sock(s),
- request(0),
- response(0),
- keepalive(false),
- async(false),
- stale(false)
+ sock(s)
{ }
Server::Client::~Client()
{
RefPtr<Net::StreamSocket> sock;
std::string in_buf;
- Request *request;
- Response *response;
- bool keepalive;
- bool async;
- bool stale;
+ Request *request = 0;
+ Response *response = 0;
+ bool keepalive = false;
+ bool async = false;
+ bool stale = false;
Client(RefPtr<Net::StreamSocket>);
~Client();
Net::StreamServerSocket sock;
std::list<Client> clients;
std::map<Response *, Client *> responses;
- IO::EventDispatcher *event_disp;
+ IO::EventDispatcher *event_disp = 0;
public:
Server();
namespace Net {
ClientSocket::ClientSocket(Family af, int type, int proto):
- Socket(af, type, proto),
- connecting(false),
- connected(false),
- peer_addr(0)
+ Socket(af, type, proto)
{ }
ClientSocket::ClientSocket(const Private &p, const SockAddr &paddr):
Socket(p),
- connecting(false),
connected(true),
peer_addr(paddr.copy())
{ }
sigc::signal<void, const std::exception *> signal_connect_finished;
protected:
- bool connecting;
- bool connected;
- SockAddr *peer_addr;
+ bool connecting = false;
+ bool connected = false;
+ SockAddr *peer_addr = 0;
ClientSocket(const Private &, const SockAddr &);
ClientSocket(Family, int, int);
class HandshakeReceiver: public PacketReceiver<Handshake>
{
private:
- uint64_t hash;
+ uint64_t hash = 0;
public:
- HandshakeReceiver();
uint64_t get_hash() const { return hash; }
void receive(const Handshake &) override;
};
-HandshakeReceiver::HandshakeReceiver():
- hash(0)
-{ }
-
void HandshakeReceiver::receive(const Handshake &shake)
{
hash = shake.hash;
socket(s),
protocol(p),
receiver(r),
- handshake_status(0),
- buf_size(65536),
in_buf(new char[buf_size]),
in_begin(in_buf),
in_end(in_buf),
- out_buf(new char[buf_size]),
- good(true)
+ out_buf(new char[buf_size])
{
socket.signal_data_available.connect(sigc::mem_fun(this, &Communicator::data_available));
}
StreamSocket &socket;
const Protocol &protocol;
ReceiverBase &receiver;
- int handshake_status;
- std::size_t buf_size;
- char *in_buf;
- char *in_begin;
- char *in_end;
- char *out_buf;
- bool good;
+ int handshake_status = 0;
+ std::size_t buf_size = 65536;
+ char *in_buf = 0;
+ char *in_begin = 0;
+ char *in_end = 0;
+ char *out_buf = 0;
+ bool good = true;
public:
Communicator(StreamSocket &, const Protocol &, ReceiverBase &);
namespace Msp {
namespace Net {
-InetAddr::InetAddr():
- port(0)
-{
- fill(addr, addr+4, 0);
-}
-
InetAddr::InetAddr(const SysAddr &sa)
{
const sockaddr_in &sai = reinterpret_cast<const sockaddr_in &>(sa.addr);
class InetAddr: public SockAddr
{
private:
- unsigned char addr[4];
- unsigned port;
+ unsigned char addr[4] = { };
+ unsigned port = 0;
public:
- InetAddr();
+ InetAddr() = default;
InetAddr(const SysAddr &);
InetAddr *copy() const override { return new InetAddr(*this); }
namespace Msp {
namespace Net {
-Inet6Addr::Inet6Addr():
- port(0)
-{
- fill(addr, addr+16, 0);
-}
-
Inet6Addr::Inet6Addr(const SysAddr &sa)
{
const sockaddr_in6 &sai6 = reinterpret_cast<const sockaddr_in6 &>(sa.addr);
class Inet6Addr: public SockAddr
{
private:
- unsigned char addr[16];
- unsigned port;
+ unsigned char addr[16] = { };
+ unsigned port = 0;
public:
- Inet6Addr();
+ Inet6Addr() = default;
Inet6Addr(const SysAddr &);
Inet6Addr *copy() const override { return new Inet6Addr(*this); }
{ }
-Protocol::PacketHeader::PacketHeader():
- type(0),
- length(0)
-{ }
-
Protocol::PacketHeader::PacketHeader(uint16_t t, uint16_t l):
type(t),
length(l)
struct PacketHeader
{
- std::uint16_t type;
- std::uint16_t length;
+ std::uint16_t type = 0;
+ std::uint16_t length = 0;
- PacketHeader();
+ PacketHeader() = default;
PacketHeader(std::uint16_t, std::uint16_t);
};
}
-Resolver::Resolver():
- event_disp(0),
- next_tag(1)
+Resolver::Resolver()
{
thread.get_notify_pipe().signal_data_available.connect(sigc::mem_fun(this, &Resolver::task_done));
}
}
-Resolver::Task::Task():
- tag(0),
- family(UNSPEC),
- addr(0),
- error(0)
-{ }
-
-
Resolver::WorkerThread::WorkerThread():
Thread("Resolver"),
- sem(1),
- done(false)
+ sem(1)
{
launch();
}
private:
struct Task
{
- unsigned tag;
+ unsigned tag = 0;
std::string host;
std::string serv;
- Family family;
- SockAddr *addr;
- std::runtime_error *error;
-
- Task();
+ Family family = UNSPEC;
+ SockAddr *addr = 0;
+ std::runtime_error *error = 0;
bool is_complete() const { return addr || error; }
};
Mutex queue_mutex;
Semaphore sem;
IO::Pipe notify_pipe;
- bool done;
+ bool done = false;
public:
WorkerThread();
sigc::signal<void, unsigned, const std::exception &> signal_resolve_failed;
private:
- IO::EventDispatcher *event_disp;
+ IO::EventDispatcher *event_disp = 0;
WorkerThread thread;
- unsigned next_tag;
+ unsigned next_tag = 1;
public:
Resolver();
}
}
-SockAddr::SysAddr::SysAddr():
- size(sizeof(sockaddr_storage))
+SockAddr::SysAddr::SysAddr()
{
addr.ss_family = AF_UNSPEC;
}
struct SockAddr::SysAddr
{
struct sockaddr_storage addr;
- socklen_t size;
+ socklen_t size = sizeof(sockaddr_storage);
SysAddr();
};
namespace Net {
Socket::Socket(const Private &p):
- priv(new Private),
- local_addr(0)
+ priv(new Private)
{
mode = IO::M_RDWR;
}
Socket::Socket(Family af, int type, int proto):
- priv(new Private),
- local_addr(0)
+ priv(new Private)
{
mode = IO::M_RDWR;
struct Private;
- Private *priv;
- SockAddr *local_addr;
+ Private *priv = 0;
+ SockAddr *local_addr = 0;
Socket(const Private &);
Socket(Family, int, int);
namespace Net {
StreamServerSocket::StreamServerSocket(Family af, int proto):
- ServerSocket(af, SOCK_STREAM, proto),
- listening(false)
+ ServerSocket(af, SOCK_STREAM, proto)
{ }
void StreamServerSocket::listen(const SockAddr &addr, unsigned backlog)
class StreamServerSocket: public ServerSocket
{
private:
- bool listening;
+ bool listening = false;
public:
StreamServerSocket(Family, int = 0);
namespace Msp {
namespace Net {
-UnixAddr::UnixAddr():
- abstract(false)
-{
-}
-
string UnixAddr::str() const
{
string result = "unix:";
{
private:
std::string path;
- bool abstract;
+ bool abstract = false;
public:
- UnixAddr();
+ UnixAddr() = default;
UnixAddr(const SysAddr &);
UnixAddr(const std::string &, bool = false);
namespace Msp {
namespace Net {
-UnixAddr::UnixAddr(const SysAddr &sa):
- abstract(false)
+UnixAddr::UnixAddr(const SysAddr &sa)
{
const sockaddr_un &sau = reinterpret_cast<const sockaddr_un &>(sa.addr);
if(static_cast<size_t>(sa.size)>sizeof(sa_family_t))
namespace Msp {
namespace Net {
-UnixAddr::UnixAddr(const SysAddr &):
- abstract(false)
+UnixAddr::UnixAddr(const SysAddr &)
{
throw unsupported("AF_UNIX");
}