forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnection.cpp
More file actions
executable file
·111 lines (81 loc) · 1.59 KB
/
Connection.cpp
File metadata and controls
executable file
·111 lines (81 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// 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