Skip to content

Commit 067b5ed

Browse files
committed
Use make_shared instead of new
1 parent a133ab3 commit 067b5ed

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/resolver_impl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void resolver_impl::resolve_continuous(const std::string &query, double forget_a
137137
// start a wave of resolve packets
138138
next_resolve_wave();
139139
// spawn a thread that runs the IO operations
140-
background_io_.reset(new lslboost::thread(lslboost::bind(&io_context::run, io_)));
140+
background_io_ = std::make_shared<lslboost::thread>(lslboost::bind(&io_context::run, io_));
141141
}
142142

143143
std::vector<stream_info_impl> resolver_impl::results(uint32_t max_results) {
@@ -192,8 +192,9 @@ void resolver_impl::udp_multicast_burst() {
192192
// start one per IP stack under consideration
193193
for (std::size_t k = 0, failures = 0; k < udp_protocols_.size(); k++) {
194194
try {
195-
resolve_attempt_udp_p attempt(new resolve_attempt_udp(*io_, udp_protocols_[k],
196-
mcast_endpoints_, query_, results_, results_mut_, cfg_->multicast_max_rtt(), this));
195+
resolve_attempt_udp_p attempt(
196+
std::make_shared<resolve_attempt_udp>(*io_, udp_protocols_[k], mcast_endpoints_,
197+
query_, results_, results_mut_, cfg_->multicast_max_rtt(), this));
197198
attempt->begin();
198199
} catch (std::exception &e) {
199200
if (++failures == udp_protocols_.size())

src/stream_outlet_impl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ using namespace lslboost::asio;
1111

1212
stream_outlet_impl::stream_outlet_impl(
1313
const stream_info_impl &info, int chunk_size, int max_capacity)
14-
: chunk_size_(chunk_size), info_(new stream_info_impl(info)),
15-
sample_factory_(new factory(info.channel_format(), info.channel_count(),
14+
: chunk_size_(chunk_size), info_(std::make_shared<stream_info_impl>(info)),
15+
sample_factory_(std::make_shared<factory>(info.channel_format(), info.channel_count(),
1616
info.nominal_srate()
1717
? info.nominal_srate() * api_config::get_instance()->outlet_buffer_reserve_ms() / 1000
1818
: api_config::get_instance()->outlet_buffer_reserve_samples())),
19-
send_buffer_(new send_buffer(max_capacity)) {
19+
send_buffer_(std::make_shared<send_buffer>(max_capacity)) {
2020
ensure_lsl_initialized();
2121
const api_config *cfg = api_config::get_instance();
2222

src/tcp_server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class client_session : public std::enable_shared_from_this<client_session> {
151151
tcp_server::tcp_server(const stream_info_impl_p &info, const io_context_p &io,
152152
const send_buffer_p &sendbuf, const factory_p &factory, tcp protocol, int chunk_size)
153153
: chunk_size_(chunk_size), shutdown_(false), info_(info), io_(io), factory_(factory),
154-
send_buffer_(sendbuf), acceptor_(new tcp::acceptor(*io)) {
154+
send_buffer_(sendbuf), acceptor_(std::make_shared<tcp::acceptor>(*io)) {
155155
// open the server connection
156156
acceptor_->open(protocol);
157157

@@ -338,7 +338,7 @@ void client_session::handle_read_query_outcome(error_code err) {
338338
}
339339

340340
void client_session::send_status_message(const std::string &str) {
341-
string_p msg(new std::string(str));
341+
string_p msg(std::make_shared<std::string>(str));
342342
async_write(*sock_, lslboost::asio::buffer(*msg),
343343
lslboost::bind(
344344
&client_session::handle_status_outcome, shared_from_this(), msg, placeholders::error));
@@ -504,7 +504,7 @@ void client_session::handle_send_feedheader_outcome(error_code err, std::size_t
504504
if (!err) {
505505
feedbuf_.consume(n);
506506
// register outstanding work at the server (will be unregistered at session destruction)
507-
work_.reset(new work_p::element_type(serv_->io_->get_executor()));
507+
work_ = std::make_shared<work_p::element_type>(serv_->io_->get_executor());
508508
// spawn a sample transfer thread
509509
lslboost::thread(&client_session::transfer_samples_thread, this, shared_from_this());
510510
}

src/udp_server.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ using namespace lsl;
1212
using namespace lslboost::asio;
1313

1414
udp_server::udp_server(const stream_info_impl_p &info, io_context &io, udp protocol)
15-
: info_(info), io_(io), socket_(new udp::socket(io)), time_services_enabled_(true) {
15+
: info_(info), io_(io), socket_(std::make_shared<udp::socket>(io)),
16+
time_services_enabled_(true) {
1617
// open the socket for the specified protocol
1718
socket_->open(protocol);
1819

@@ -29,7 +30,8 @@ udp_server::udp_server(const stream_info_impl_p &info, io_context &io, udp proto
2930

3031
udp_server::udp_server(const stream_info_impl_p &info, io_context &io, const std::string &address,
3132
uint16_t port, int ttl, const std::string &listen_address)
32-
: info_(info), io_(io), socket_(new udp::socket(io)), time_services_enabled_(false) {
33+
: info_(info), io_(io), socket_(std::make_shared<udp::socket>(io)),
34+
time_services_enabled_(false) {
3335
ip::address addr = ip::make_address(address);
3436
bool is_broadcast = addr == ip::address_v4::broadcast();
3537

@@ -127,7 +129,8 @@ void udp_server::handle_receive_outcome(error_code err, std::size_t len) {
127129
if (info_->matches_query(query)) {
128130
// query matches: send back reply
129131
udp::endpoint return_endpoint(remote_endpoint_.address(), return_port);
130-
string_p replymsg(new std::string((query_id += "\r\n") += shortinfo_msg_));
132+
string_p replymsg(
133+
std::make_shared<std::string>((query_id += "\r\n") += shortinfo_msg_));
131134
socket_->async_send_to(lslboost::asio::buffer(*replymsg), return_endpoint,
132135
lslboost::bind(&udp_server::handle_send_outcome, shared_from_this(),
133136
replymsg, placeholders::error));
@@ -147,7 +150,7 @@ void udp_server::handle_receive_outcome(error_code err, std::size_t len) {
147150
std::ostringstream reply;
148151
reply.precision(16);
149152
reply << " " << wave_id << " " << t0 << " " << t1 << " " << lsl_clock();
150-
string_p replymsg(new std::string(reply.str()));
153+
string_p replymsg(std::make_shared<std::string>(reply.str()));
151154
socket_->async_send_to(lslboost::asio::buffer(*replymsg), remote_endpoint_,
152155
lslboost::bind(&udp_server::handle_send_outcome, shared_from_this(),
153156
replymsg, placeholders::error));

0 commit comments

Comments
 (0)