poco/MongoDB/src/Connection.cpp
Roger Meier b0581433a7 LICENSE: add info about SPDX-License-Identifier usage and use it
fix: remove executable flag and change back to 100644 (was 100755)

Signed-off-by: Roger Meier <r.meier@siemens.com>
2014-05-14 08:38:09 +02:00

112 lines
1.6 KiB
C++

//
// Connection.cpp
//
// $Id$
//
// Library: MongoDB
// Package: MongoDB
// Module: Connection
//
// Implementation of the Connection class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Net/SocketStream.h"
#include "Poco/MongoDB/Connection.h"
#include <iostream>
namespace Poco {
namespace MongoDB {
Connection::Connection() : _address(), _socket()
{
}
Connection::Connection(const std::string& hostAndPort) : _address(hostAndPort), _socket()
{
connect();
}
Connection::Connection(const std::string& host, int port) : _address(host, port), _socket()
{
connect();
}
Connection::Connection(const Net::SocketAddress& addrs) : _address(addrs), _socket()
{
connect();
}
Connection::~Connection()
{
try
{
_socket.close();
}
catch (...)
{
}
}
void Connection::connect()
{
_socket.connect(_address);
}
void Connection::connect(const std::string& hostAndPort)
{
_address = Net::SocketAddress(hostAndPort);
connect();
}
void Connection::connect(const std::string& host, int port)
{
_address = Net::SocketAddress(host, port);
connect();
}
void Connection::connect(const Net::SocketAddress& addrs)
{
_address = addrs;
connect();
}
void Connection::disconnect()
{
_socket.close();
}
void Connection::sendRequest(RequestMessage& request)
{
Net::SocketOutputStream sos(_socket);
request.send(sos);
}
void Connection::sendRequest(RequestMessage& request, ResponseMessage& response)
{
sendRequest(request);
Net::SocketInputStream sis(_socket);
response.read(sis);
}
} } // Poco::MongoDB