Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit164ae3b

Browse files
committed
Avoid deprecated Boost.Asio interfaces
Change-Id: I7041c89ea9147e08c8b6226b84a6d17dddeed0e1
1 parent7df36bd commit164ae3b

File tree

11 files changed

+75
-132
lines changed

11 files changed

+75
-132
lines changed

‎.waf-tools/default-compiler-flags.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ def getCompilerVersion(self, conf):
128128

129129
defgetGeneralFlags(self,conf):
130130
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are always needed"""
131-
return {'CXXFLAGS': [],'LINKFLAGS': [],'DEFINES': []}
131+
return {
132+
'CXXFLAGS': [],
133+
'LINKFLAGS': [],
134+
'DEFINES': ['BOOST_ASIO_NO_DEPRECATED','BOOST_FILESYSTEM_NO_DEPRECATED'],
135+
}
132136

133137
defgetDebugFlags(self,conf):
134138
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in debug mode"""

‎examples/data-producer.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Publisher
8787

8888
private:
8989
ndn::Face m_face;
90-
ndn::Scheduler m_scheduler{m_face.getIoService()};
90+
ndn::Scheduler m_scheduler{m_face.getIoContext()};
9191
std::uniform_int_distribution<> m_randomDist{200,1000};
9292
};
9393

@@ -118,7 +118,7 @@ void
118118
Publisher::generateFromFile()
119119
{
120120
if (insertStream.eof()) {
121-
m_face.getIoService().stop();
121+
m_face.getIoContext().stop();
122122
return;
123123
}
124124

‎src/handles/tcp-bulk-insert-handle.cpp‎

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,39 @@ NDN_LOG_INIT(repo.TcpHandle);
2828
namespaceip= boost::asio::ip;
2929

3030
namespacerepo {
31-
namespacedetail{
31+
namespace {
3232

3333
classTcpBulkInsertClient : noncopyable
3434
{
3535
public:
36-
TcpBulkInsertClient(TcpBulkInsertHandle& writer,std::shared_ptr<ip::tcp::socket> socket)
36+
TcpBulkInsertClient(TcpBulkInsertHandle& writer, ip::tcp::socket socket)
3737
: m_writer(writer)
3838
, m_socket(std::move(socket))
3939
{
4040
}
4141

4242
staticvoid
43-
startReceive(TcpBulkInsertHandle& writer,std::shared_ptr<ip::tcp::socket> socket)
43+
startReceive(TcpBulkInsertHandle& writer, ip::tcp::socket socket)
4444
{
4545
auto client = std::make_shared<TcpBulkInsertClient>(writer,std::move(socket));
46-
client->m_socket->async_receive(
46+
client->m_socket.async_receive(
4747
boost::asio::buffer(client->m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE),0,
4848
std::bind(&TcpBulkInsertClient::handleReceive, client, _1, _2, client));
4949
}
5050

5151
private:
5252
void
53-
handleReceive(const boost::system::error_code& error,
54-
std::size_t nBytesReceived,
53+
handleReceive(const boost::system::error_code& error, std::size_t nBytesReceived,
5554
const std::shared_ptr<TcpBulkInsertClient>& client);
5655

5756
private:
5857
TcpBulkInsertHandle& m_writer;
59-
std::shared_ptr<ip::tcp::socket> m_socket;
58+
ip::tcp::socket m_socket;
6059
uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
6160
std::size_t m_inputBufferSize =0;
6261
};
6362

64-
}// namespace detail
63+
}// namespace
6564

6665
TcpBulkInsertHandle::TcpBulkInsertHandle(boost::asio::io_context& io,
6766
RepoStorage& storageHandle)
@@ -74,14 +73,12 @@ void
7473
TcpBulkInsertHandle::listen(const std::string& host,const std::string& port)
7574
{
7675
ip::tcp::resolverresolver(m_acceptor.get_executor());
77-
ip::tcp::resolver::queryquery(host, port);
76+
boost::system::error_code ec;
77+
auto results = resolver.resolve(host, port, ec);
78+
if (ec)
79+
NDN_THROW(Error("Cannot resolve" + host +":" + port +" (" + ec.message() +")"));
7880

79-
ip::tcp::resolver::iterator endpoint = resolver.resolve(query);
80-
ip::tcp::resolver::iterator end;
81-
if (endpoint == end)
82-
NDN_THROW(Error("Cannot listen on" + host +" port" + port));
83-
84-
m_localEndpoint = *endpoint;
81+
m_localEndpoint = *results.begin();
8582
NDN_LOG_DEBUG("Start listening on" << m_localEndpoint);
8683

8784
m_acceptor.open(m_localEndpoint.protocol());
@@ -105,39 +102,31 @@ TcpBulkInsertHandle::stop()
105102
void
106103
TcpBulkInsertHandle::asyncAccept()
107104
{
108-
auto clientSocket = std::make_shared<ip::tcp::socket>(m_acceptor.get_executor());
109-
m_acceptor.async_accept(*clientSocket,
110-
std::bind(&TcpBulkInsertHandle::handleAccept,this, _1, clientSocket));
111-
}
112-
113-
void
114-
TcpBulkInsertHandle::handleAccept(const boost::system::error_code& error,
115-
const std::shared_ptr<ip::tcp::socket>& socket)
116-
{
117-
if (error) {
118-
return;
119-
}
120-
121-
NDN_LOG_DEBUG("New connection from" << socket->remote_endpoint());
105+
m_acceptor.async_accept([this] (constauto& error, ip::tcp::socket socket) {
106+
if (error) {
107+
return;
108+
}
122109

123-
detail::TcpBulkInsertClient::startReceive(*this, socket);
110+
NDN_LOG_DEBUG("New connection from" << socket.remote_endpoint());
111+
TcpBulkInsertClient::startReceive(*this,std::move(socket));
124112

125-
// prepare accepting the next connection
126-
asyncAccept();
113+
// prepare accepting the next connection
114+
asyncAccept();
115+
});
127116
}
128117

129118
void
130-
detail::TcpBulkInsertClient::handleReceive(const boost::system::error_code& error,
131-
std::size_t nBytesReceived,
132-
const std::shared_ptr<detail::TcpBulkInsertClient>& client)
119+
TcpBulkInsertClient::handleReceive(const boost::system::error_code& error,
120+
std::size_t nBytesReceived,
121+
const std::shared_ptr<TcpBulkInsertClient>& client)
133122
{
134123
if (error) {
135-
if (error == boost::system::errc::operation_canceled)// when socket is closed by someone
124+
if (error == boost::asio::error::operation_aborted)// when socket is closed by someone
136125
return;
137126

138127
boost::system::error_code ec;
139-
m_socket->shutdown(ip::tcp::socket::shutdown_both, ec);
140-
m_socket->close(ec);
128+
m_socket.shutdown(ip::tcp::socket::shutdown_both, ec);
129+
m_socket.close(ec);
141130
return;
142131
}
143132

@@ -175,8 +164,8 @@ detail::TcpBulkInsertClient::handleReceive(const boost::system::error_code& erro
175164

176165
if (!isOk && m_inputBufferSize == ndn::MAX_NDN_PACKET_SIZE && offset ==0) {
177166
boost::system::error_code ec;
178-
m_socket->shutdown(ip::tcp::socket::shutdown_both, ec);
179-
m_socket->close(ec);
167+
m_socket.shutdown(ip::tcp::socket::shutdown_both, ec);
168+
m_socket.close(ec);
180169
return;
181170
}
182171

@@ -190,9 +179,9 @@ detail::TcpBulkInsertClient::handleReceive(const boost::system::error_code& erro
190179
}
191180
}
192181

193-
m_socket->async_receive(boost::asio::buffer(m_inputBuffer + m_inputBufferSize,
194-
ndn::MAX_NDN_PACKET_SIZE - m_inputBufferSize),0,
195-
std::bind(&TcpBulkInsertClient::handleReceive,this, _1, _2, client));
182+
m_socket.async_receive(boost::asio::buffer(m_inputBuffer + m_inputBufferSize,
183+
ndn::MAX_NDN_PACKET_SIZE - m_inputBufferSize),0,
184+
std::bind(&TcpBulkInsertClient::handleReceive,this, _1, _2, client));
196185
}
197186

198187
}// namespace repo

‎src/handles/tcp-bulk-insert-handle.hpp‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ class TcpBulkInsertHandle : noncopyable
5555
void
5656
asyncAccept();
5757

58-
void
59-
handleAccept(const boost::system::error_code& error,
60-
const std::shared_ptr<boost::asio::ip::tcp::socket>& socket);
61-
6258
private:
6359
boost::asio::ip::tcp::acceptor m_acceptor;
6460
boost::asio::ip::tcp::endpoint m_localEndpoint;

‎tests/integrated/command-fixture.cpp‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎tests/integrated/command-fixture.hpp‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-*/
22
/*
3-
* Copyright (c) 2014-2022, Regents of the University of California.
3+
* Copyright (c) 2014-2023, Regents of the University of California.
44
*
55
* This file is part of NDN repo-ng (Next generation of NDN repository).
66
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -30,15 +30,19 @@ namespace repo::tests {
3030
classCommandFixture :publicvirtual IdentityManagementFixture
3131
{
3232
protected:
33-
CommandFixture();
33+
CommandFixture()
34+
{
35+
addIdentity("/ndn/test/repo");
36+
saveIdentityCertificate("/ndn/test/repo","tests/integrated/insert-delete-test.cert");
37+
validator.load("tests/integrated/insert-delete-validator-config.conf");
38+
}
3439

3540
protected:
3641
Face repoFace;
37-
Scheduler scheduler;
38-
ndn::KeyChain& keyChain;
39-
ndn::mgmt::Dispatcher dispatcher;
42+
Scheduler scheduler{repoFace.getIoContext()};
43+
ndn::mgmt::Dispatcher dispatcher{repoFace, m_keyChain};
4044
/// \todo #4091 switch to ValidatorPolicyConf and load insert-delete-validator-config.conf
41-
ndn::security::ValidatorConfig validator;
45+
ndn::security::ValidatorConfig validator{repoFace};
4246
};
4347

4448
}// namespace repo::tests

‎tests/integrated/test-basic-command-insert-delete.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class Fixture : public CommandFixture, public RepoStorageFixture, public Dataset
5050
Fixture()
5151
: writeHandle(repoFace, *handle, dispatcher, scheduler, validator)
5252
, deleteHandle(repoFace, *handle, dispatcher, scheduler, validator)
53-
, insertFace(repoFace.getIoService())
54-
, deleteFace(repoFace.getIoService())
55-
, signer(keyChain)
53+
, insertFace(repoFace.getIoContext())
54+
, deleteFace(repoFace.getIoContext())
55+
, signer(m_keyChain)
5656
{
5757
NamecmdPrefix("/repo/command");
5858
repoFace.registerPrefix(cmdPrefix,nullptr,
@@ -114,11 +114,11 @@ template<class T>
114114
void
115115
Fixture<T>::onInsertInterest(const Interest& interest)
116116
{
117-
Datadata(Name(interest.getName()));
117+
Datadata(interest.getName());
118118
data.setContent(CONTENT);
119-
data.setFreshnessPeriod(0_ms);
120-
keyChain.sign(data);
119+
m_keyChain.sign(data);
121120
insertFace.put(data);
121+
122122
auto eventIt = insertEvents.find(interest.getName());
123123
if (eventIt != insertEvents.end()) {
124124
eventIt->second.cancel();

‎tests/integrated/test-basic-interest-read.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ class BasicInterestReadFixture : public RepoStorageFixture, public Dataset
3838
{
3939
public:
4040
BasicInterestReadFixture()
41-
: scheduler(repoFace.getIoService())
41+
: scheduler(repoFace.getIoContext())
4242
, readHandle(repoFace, *handle,0)
43-
, readFace(repoFace.getIoService())
43+
, readFace(repoFace.getIoContext())
4444
{
4545
}
4646

4747
~BasicInterestReadFixture()
4848
{
49-
repoFace.getIoService().stop();
49+
repoFace.getIoContext().stop();
5050
}
5151

5252
void

‎tests/unit/read-handle.t.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Fixture : public RepoStorageFixture
4444
public:
4545
Fixture()
4646
: face({true,true})
47-
, scheduler(face.getIoService())
47+
, scheduler(face.getIoContext())
4848
, subsetLength(1)
4949
, dataPrefix("/ndn/test/prefix")
5050
, identity("/ndn/test/identity")

‎tests/unit/tcp-bulk-insert-handle.cpp‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
*/
1919

2020
#include"handles/tcp-bulk-insert-handle.hpp"
21-
#include"storage/sqlite-storage.hpp"
21+
2222
#include"../repo-storage-fixture.hpp"
2323
#include"../dataset-fixtures.hpp"
2424

25+
#include<boost/asio/ip/tcp.hpp>
2526
#include<boost/test/unit_test.hpp>
2627

2728
namespacerepo::tests {
@@ -34,28 +35,21 @@ class TcpClient
3435
void
3536
start(const std::string& host,const std::string& port)
3637
{
37-
usingnamespaceboost::asio;
38-
39-
ip::tcp::resolverresolver(ioCtx);
40-
ip::tcp::resolver::queryquery(host, port);
41-
42-
ip::tcp::resolver::iterator endpoint = resolver.resolve(query);
43-
ip::tcp::resolver::iterator end;
44-
45-
if (endpoint == end)
38+
boost::asio::ip::tcp::resolverresolver(ioCtx);
39+
boost::system::error_code ec;
40+
auto results = resolver.resolve(host, port, ec);
41+
if (ec) {
4642
BOOST_FAIL("Cannot resolve [" + host +":" + port +"]");
43+
}
4744

48-
ip::tcp::endpoint serverEndpoint = *endpoint;
49-
50-
socket.async_connect(serverEndpoint,
51-
std::bind(&TcpClient::onSuccessfullConnect,this, _1));
45+
socket.async_connect(*results.begin(),std::bind(&TcpClient::handleConnect,this, _1));
5246
}
5347

5448
virtualvoid
55-
onSuccessfullConnect(const boost::system::error_code& error)
49+
handleConnect(const boost::system::error_code& error)
5650
{
5751
if (error) {
58-
BOOST_FAIL("TCP connectionaborted");
52+
BOOST_FAIL("TCP connectionfailed");
5953
}
6054
}
6155

@@ -78,9 +72,9 @@ class TcpBulkInsertFixture : public TcpClient,
7872
}
7973

8074
void
81-
onSuccessfullConnect(const boost::system::error_code& error)override
75+
handleConnect(const boost::system::error_code& error)override
8276
{
83-
TcpClient::onSuccessfullConnect(error);
77+
TcpClient::handleConnect(error);
8478

8579
// This value may need to be adjusted if some dataset exceeds 100k
8680
socket.set_option(boost::asio::socket_base::send_buffer_size(100000));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp