• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libbitcoin / libbitcoin-network / 45495981786

24 Nov 2026 09:55PM UTC coverage: 94.028% (-0.2%) from 94.184%
45495981786

push

github

web-flow
Merge pull request #1062 from evoskuil/master

Regenerate artifacts.

16200 of 17229 relevant lines covered (94.03%)

2210.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.82
/src/net/socket.cpp
1
/**
2
 * Copyright (c) 2011-2026 libbitcoin developers
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#include <bitcoin/network/net/socket.hpp>
20

21
#include <bitcoin/network/async/async.hpp>
22
#include <bitcoin/network/config/config.hpp>
23
#include <bitcoin/network/define.hpp>
24
#include <bitcoin/network/log/log.hpp>
25
#include <bitcoin/network/net/deadline.hpp>
26

27
// Async operations not thread safe for same socket object.
28
// Calls stranded to protect socket member.
29

30
namespace libbitcoin {
31
namespace network {
32

33
using namespace system;
34
using namespace std::placeholders;
35

36
// Shared pointers required in handler parameters so closures control lifetime.
37
BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
38
BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED)
39
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
40

41
// Bounds query overrun following caller drop, not response latency.
42
constexpr auto watch_interval = milliseconds(10);
43

44
// Construct.
45
// ----------------------------------------------------------------------------
46

47
socket::socket(const logger& log, io::context& service,
414 ✔
48
    const parameters& parameters, bool proxied) NOEXCEPT
414 ✔
49
  : socket(log, service, parameters, {}, {}, proxied, true)
414 ✔
50
{
51
}
414 ✔
52

53
socket::socket(const logger& log, io::context& service,
135 ✔
54
    const parameters& params, const config::address& address,
55
    const config::endpoint& endpoint, bool proxied) NOEXCEPT
135 ✔
56
  : socket(log, service, params, address, endpoint, proxied, false)
135 ✔
57
{
58
}
135 ✔
59

60
// protected
61
socket::socket(const logger& log, io::context& service,
549 ✔
62
    const parameters& params, const config::address& address,
63
    const config::endpoint& endpoint, bool proxied, bool inbound) NOEXCEPT
549 ✔
64
  : reporter(log),
65
    tracker<socket>(log),
66
    inbound_(inbound),
549 ✔
67
    proxied_(proxied),
549 ✔
68
    maximum_(params.maximum_request),
549 ✔
69
    header_(std::min(params.maximum_request, maximum_http_header)),
549 ✔
70
    minimum_buffer_(params.minimum_buffer),
549 ✔
71
    bind_(params.bind),
549 ✔
72
    slot_(params.slot),
549 ✔
73
    strand_(service.get_executor()),
549 ✔
74
    service_(service),
549 ✔
75
    context_(params.context),
549 ✔
76
    role_(params.role),
549 ✔
77
    address_(address),
549 ✔
78
    endpoint_(endpoint),
549 ✔
79
    timer_(emplace_shared<deadline>(log, strand_, params.connect_timeout)),
549 ✔
80
    watch_(emplace_shared<deadline>(log, strand_, watch_interval)),
549 ✔
81
    socket_(std::in_place_type<io::socket>, strand_),
549 ✔
82
    response_(params.maximum_buffer)
2,196 ✔
83
{
84
}
549 ✔
85

86
socket::~socket() NOEXCEPT
549 ✔
87
{
88
    BC_ASSERT_MSG(stopped(), "socket is not stopped");
549 ✔
89
    if (!stopped_.load()) { LOGF("~socket is not stopped."); }
549 ✔
90
}
549 ✔
91

92
// Wait.
93
// ----------------------------------------------------------------------------
94

95
void socket::watch(result_handler&& handler) NOEXCEPT
18 ✔
96
{
97
    io::dispatch(strand_,
18 ✔
98
        std::bind(&socket::do_watch,
36 ✔
99
            shared_from_this(), std::move(handler)));
36 ✔
100
}
18 ✔
101

102
void socket::poll(result_handler&& handler) NOEXCEPT
3 ✔
103
{
104
    io::dispatch(strand_,
3 ✔
105
        std::bind(&socket::do_poll,
6 ✔
106
            shared_from_this(), std::move(handler)));
6 ✔
107
}
3 ✔
108

109
// private
110
void socket::do_watch(const result_handler& handler) NOEXCEPT
21 ✔
111
{
112
    BC_ASSERT(stranded());
21 ✔
113

114
    if (stopped_.load())
21 ✔
115
    {
116
        handler(error::success);
×
117
        return;
×
118
    }
119

120
    watch_->start(std::bind(&socket::handle_watch,
21 ✔
121
        shared_from_this(), _1, handler));
42 ✔
122
}
123

124
// private
125
void socket::do_poll(const result_handler& handler) NOEXCEPT
3 ✔
126
{
127
    BC_ASSERT(stranded());
3 ✔
128

129
    if (stopped_.load())
3 ✔
130
    {
131
        handler(error::success);
1 ✔
132
        return;
1 ✔
133
    }
134

135
    watch_->start(std::bind(&socket::handle_poll,
2 ✔
136
        shared_from_this(), _1, handler));
4 ✔
137
}
138

139
// private
140
void socket::handle_watch(const code& ec,
21 ✔
141
    const result_handler& handler) NOEXCEPT
142
{
143
    BC_ASSERT(stranded());
21 ✔
144

145
    // Only timer stop results in caller not stopping the channel.
146
    if (ec)
21 ✔
147
    {
148
        handler(error::success);
17 ✔
149
        return;
17 ✔
150
    }
151

152
    if (get_base().half_closed())
4 ✔
153
    {
154
        handler(error::peer_disconnect);
1 ✔
155
        return;
1 ✔
156
    }
157

158
    do_watch(handler);
3 ✔
159
}
160

161
// private
162
void socket::handle_poll(const code& ec,
2 ✔
163
    const result_handler& handler) NOEXCEPT
164
{
165
    BC_ASSERT(stranded());
2 ✔
166

167
    // Timer stop (socket stop) results in caller not stopping the channel.
168
    if (!ec && get_base().half_closed())
2 ✔
169
    {
170
        handler(error::peer_disconnect);
1 ✔
171
        return;
1 ✔
172
    }
173

174
    handler(error::success);
1 ✔
175
}
176

177
// Properties.
178
// ----------------------------------------------------------------------------
179

180
io::context& socket::service() const NOEXCEPT
2 ✔
181
{
182
    return service_;
2 ✔
183
}
184

185
io::strand& socket::strand() NOEXCEPT
3,200 ✔
186
{
187
    return strand_;
3,200 ✔
188
}
189

190
bool socket::stranded() const NOEXCEPT
410,920 ✔
191
{
192
    return strand_.running_in_this_thread();
410,920 ✔
193
}
194

195
bool socket::stopped() const NOEXCEPT
83,490 ✔
196
{
197
    return stopped_.load();
83,490 ✔
198
}
199

200
bool socket::inbound() const NOEXCEPT
793 ✔
201
{
202
    return inbound_;
793 ✔
203
}
204

205
bool socket::websocket() const NOEXCEPT
77,958 ✔
206
{
207
    return websocket_.load();
77,958 ✔
208
}
209

210
bool socket::downgraded() const NOEXCEPT
191 ✔
211
{
212
    return downgraded_.load();
191 ✔
213
}
214

215
bool socket::detected() const NOEXCEPT
72 ✔
216
{
217
    return detected_.load();
72 ✔
218
}
219

220
const config::address& socket::address() const NOEXCEPT
314 ✔
221
{
222
    return address_;
314 ✔
223
}
224

225
const config::endpoint& socket::endpoint() const NOEXCEPT
330 ✔
226
{
227
    return endpoint_;
330 ✔
228
}
229

230
const config::endpoint& socket::binding() const NOEXCEPT
9 ✔
231
{
232
    return binding_;
9 ✔
233
}
234

235
size_t socket::slot() const NOEXCEPT
4 ✔
236
{
237
    return slot_;
4 ✔
238
}
239

240
void socket::set_address(const config::address& address) NOEXCEPT
2 ✔
241
{
242
    BC_ASSERT(stranded());
2 ✔
243
    address_ = address;
2 ✔
244
    endpoint_ = address;
2 ✔
245
}
2 ✔
246

247
// Variant state (protected by strand).
248
// ----------------------------------------------------------------------------
249

250
bool socket::secure() const NOEXCEPT
40 ✔
251
{
252
    BC_ASSERT(stranded());
40 ✔
253
    return std::holds_alternative<tls::stream>(socket_);
40 ✔
254
}
255

256
bool socket::encrypted() const NOEXCEPT
1,032 ✔
257
{
258
    BC_ASSERT(stranded());
1,032 ✔
259
    return std::holds_alternative<p2ps::stream>(socket_);
1,032 ✔
260
}
261

262
bool socket::zeromq() const NOEXCEPT
327 ✔
263
{
264
    BC_ASSERT(stranded());
327 ✔
265
    return std::holds_alternative<zmtp::stream>(socket_);
327 ✔
266
}
267

268
// protected
269
bool socket::is_base() const NOEXCEPT
1 ✔
270
{
271
    BC_ASSERT(stranded());
1 ✔
272
    return std::holds_alternative<io::socket>(socket_);
1 ✔
273
}
274

275
// Variant accessors.
276
// ----------------------------------------------------------------------------
277
// protected
278

279
socket::tcp_t socket::get_tcp() NOEXCEPT
76,971 ✔
280
{
281
    BC_ASSERT(stranded());
76,971 ✔
282

283
    return std::visit(overload
153,942 ✔
284
    {
285
        [](io::socket& value) NOEXCEPT -> socket::tcp_t
76,962 ✔
286
        {
287
            return std::ref(value);
76,962 ✔
288
        },
289
        [](tls::stream& value) NOEXCEPT -> socket::tcp_t
9 ✔
290
        {
291
            return std::ref(value);
9 ✔
292
        },
293
        [](p2ps::stream&) NOEXCEPT -> socket::tcp_t
×
294
        {
295
            std::terminate();
×
296
        },
297
        [](zmtp::stream&) NOEXCEPT -> socket::tcp_t
×
298
        {
299
            std::terminate();
×
300
        }
301
    }, socket_);
76,971 ✔
302
}
303

304
io::socket& socket::get_base() NOEXCEPT
2,688 ✔
305
{
306
    return std::visit(overload
5,376 ✔
307
    {
308
        [](io::socket& value) NOEXCEPT -> io::socket&
2,629 ✔
309
        {
310
            return value;
2,629 ✔
311
        },
312
        [](tls::stream& value) NOEXCEPT -> io::socket&
12 ✔
313
        {
314
            return value.next_layer();
12 ✔
315
        },
316
        [](p2ps::stream& value) NOEXCEPT -> io::socket&
4 ✔
317
        {
318
            return value.next_layer();
4 ✔
319
        },
320
        [](zmtp::stream& value) NOEXCEPT -> io::socket&
43 ✔
321
        {
322
            return value.next_layer();
43 ✔
323
        }
324
    }, socket_);
2,688 ✔
325
}
326

327
tls::stream& socket::get_tls() NOEXCEPT
×
328
{
329
    BC_ASSERT(stranded());
×
330
    BC_ASSERT(secure());
×
331

332
    return std::visit(overload
×
333
    {
334
        [](io::socket&) NOEXCEPT -> tls::stream&
×
335
        {
336
            std::terminate();
×
337
        },
338
        [](tls::stream& value) NOEXCEPT -> tls::stream&
×
339
        {
340
            return value;
×
341
        },
342
        [](p2ps::stream&) NOEXCEPT -> tls::stream&
×
343
        {
344
            std::terminate();
×
345
        },
346
        [](zmtp::stream&) NOEXCEPT -> tls::stream&
×
347
        {
348
            std::terminate();
×
349
        }
350
    }, socket_);
×
351
}
352

353
p2ps::stream& socket::get_p2ps() NOEXCEPT
8 ✔
354
{
355
    BC_ASSERT(stranded());
8 ✔
356
    BC_ASSERT(encrypted());
8 ✔
357

358
    return std::visit(overload
16 ✔
359
    {
360
        [](io::socket&) NOEXCEPT -> p2ps::stream&
×
361
        {
362
            std::terminate();
×
363
        },
364
        [](tls::stream&) NOEXCEPT -> p2ps::stream&
×
365
        {
366
            std::terminate();
×
367
        },
368
        [](p2ps::stream& value) NOEXCEPT -> p2ps::stream&
8 ✔
369
        {
370
            return value;
8 ✔
371
        },
372
        [](zmtp::stream&) NOEXCEPT -> p2ps::stream&
×
373
        {
374
            std::terminate();
×
375
        }
376
    }, socket_);
8 ✔
377
}
378

379
zmtp::stream& socket::get_zmtp() NOEXCEPT
94 ✔
380
{
381
    BC_ASSERT(stranded());
94 ✔
382
    BC_ASSERT(zeromq());
94 ✔
383

384
    return std::visit(overload
188 ✔
385
    {
386
        [](io::socket&) NOEXCEPT -> zmtp::stream&
×
387
        {
388
            std::terminate();
×
389
        },
390
        [](tls::stream&) NOEXCEPT -> zmtp::stream&
×
391
        {
392
            std::terminate();
×
393
        },
394
        [](p2ps::stream&) NOEXCEPT -> zmtp::stream&
×
395
        {
396
            std::terminate();
×
397
        },
398
        [](zmtp::stream& value) NOEXCEPT -> zmtp::stream&
94 ✔
399
        {
400
            return value;
94 ✔
401
        }
402
    }, socket_);
94 ✔
403
}
404

405
// Variant (ws vs. tcp)  helpers.
406
// ----------------------------------------------------------------------------
407
// protected
408

409
// write message frame (ws, finish closes message) or unframed fixed size bytes
410
// (tcp). Binary/text setting applies only at start of message, so it is
411
// harmless to pass it on every frame of message.
412
void socket::async_write(const io::const_buffer& buffer, bool binary,
126 ✔
413
    bool finish, const count_handler& handler) NOEXCEPT
414
{
415
    BC_ASSERT(stranded());
126 ✔
416

417
    if (websocket())
126 ✔
418
    {
419
        ws_send_data(buffer, binary, finish, handler);
1 ✔
420
    }
421
    else
422
    {
423
        transmit({ &buffer, one }, finish,
125 ✔
424
            std::bind(&socket::handle_async,
250 ✔
425
                shared_from_this(), _1, _2, handler, "async_write"));
250 ✔
426
    }
427
}
126 ✔
428

429
// Transport (write).
430
// ----------------------------------------------------------------------------
431
// Writes issued one at a time, write issued over
432
// another deferred to its completion. Retained buffer
433
// not prepared while write of its bytes is in progress.
434

435
void socket::hold(bool enable) NOEXCEPT
494 ✔
436
{
437
    BC_ASSERT(stranded());
494 ✔
438
    hold_ = enable;
494 ✔
439
    settling_ = enable;
494 ✔
440
}
494 ✔
441

442
void socket::settle() NOEXCEPT
492 ✔
443
{
444
    BC_ASSERT(stranded());
492 ✔
445
    settling_ = false;
492 ✔
446
    if (settled_)
492 ✔
447
        std::exchange(settled_, {})();
5 ✔
448
}
492 ✔
449

450
bool socket::holding() const NOEXCEPT
472 ✔
451
{
452
    BC_ASSERT(stranded());
472 ✔
453
    return !is_zero(response_.size());
472 ✔
454
}
455

456
void socket::release(count_handler&& handler) NOEXCEPT
2 ✔
457
{
458
    BC_ASSERT(stranded());
2 ✔
459
    hold_ = false;
2 ✔
460
    settling_ = false;
2 ✔
461
    transmit({}, false, handler);
2 ✔
462
}
2 ✔
463

464
// protected
465
// Write is preceded by held writes, or is held (if hold) with them.
466
void socket::transmit(const std::span<const io::const_buffer>& buffers,
781 ✔
467
    bool hold, const count_handler& handler) NOEXCEPT
468
{
469
    BC_ASSERT(stranded());
781 ✔
470

471
    if (sending_)
781 ✔
472
    {
473
        deferred_ = std::bind(&socket::transmit, shared_from_this(),
×
474
            io::to_buffers<io::const_buffer>(buffers), hold, handler);
×
475
        return;
8 ✔
476
    }
477

478
    const auto held = response_.size();
781 ✔
479
    const auto size = io::buffer_size(buffers);
781 ✔
480
    const auto bound = std::min(minimum_buffer_, response_.max_size());
781 ✔
481
    if (hold && hold_ && size <= floored_subtract(bound, held))
781 ✔
482
    {
483
        response_.append(buffers);
8 ✔
484
        if (settling_)
8 ✔
485
        {
486
            settling_ = false;
5 ✔
487
            settled_ = std::bind(handler, error::success, size);
5 ✔
488
            return;
5 ✔
489
        }
490

491
        io::post(strand_, std::bind(handler, error::success, size));
3 ✔
492
        return;
3 ✔
493
    }
494

495
    io::const_buffers gather{};
773 ✔
496
    if (!is_zero(held))
773 ✔
497
        gather.push_back(response_.cdata());
7 ✔
498

499
    gather.insert(gather.end(), buffers.begin(), buffers.end());
773 ✔
500
    response_.clear();
773 ✔
501
    sending_ = true;
773 ✔
502
    VARIANT_DISPATCH_FUNCTION(io::async_write, get_tcp(),
1,546 ✔
503
        gather, std::bind(&socket::handle_transmit,
504
            shared_from_this(), _1, _2, held, handler));
505
}
773 ✔
506

507
// protected
508
// Write is independent of held writes.
509
void socket::interject(const std::span<const io::const_buffer>& buffers,
4 ✔
510
    const count_handler& handler) NOEXCEPT
511
{
512
    BC_ASSERT(stranded());
4 ✔
513

514
    if (sending_)
4 ✔
515
    {
516
        deferred_ = std::bind(&socket::interject, shared_from_this(),
×
517
            io::to_buffers<io::const_buffer>(buffers), handler);
×
518
        return;
×
519
    }
520

521
    sending_ = true;
4 ✔
522
    VARIANT_DISPATCH_FUNCTION(io::async_write, get_tcp(),
8 ✔
523
        buffers, std::bind(&socket::handle_transmit,
524
            shared_from_this(), _1, _2, zero, handler));
525
}
526

527
// private
528
// Size reported excludes that of held writes (reported when held).
529
void socket::handle_transmit(const code& ec, size_t size, size_t held,
777 ✔
530
    const count_handler& handler) NOEXCEPT
531
{
532
    BC_ASSERT(stranded());
777 ✔
533

534
    sending_ = false;
777 ✔
535
    const auto next = std::exchange(deferred_, {});
777 ✔
536
    handler(ec, floored_subtract(size, held));
777 ✔
537

538
    if (next)
777 ✔
539
        next();
×
540
}
777 ✔
541

542
// read arbitrary tcp bytes, iterate (up to buffer capacity).
543
void socket::async_read_some(const io::mutable_buffer& buffer,
125 ✔
544
    const count_handler& handler) NOEXCEPT
545
{
546
    BC_ASSERT(stranded());
125 ✔
547

548
    if (websocket())
125 ✔
549
    {
550
        // Websockets read messages, use async_read(flat_buffer).
551
        handler(error::operation_failed, {});
×
552
    }
553
    else
554
    {
555
        VARIANT_DISPATCH_METHOD(get_tcp(),
250 ✔
556
            async_read_some(buffer, std::bind(&socket::handle_async,
557
                shared_from_this(), _1, _2, handler, "async_read_some")));
558
    }
559
}
125 ✔
560

561
// read arbitrary tcp bytes, iterate (up to buffer capacity).
562
// read whole ws message in any number of frames (up to buffer capacity).
563
void socket::async_read(http::flat_buffer& buffer,
40 ✔
564
    const count_handler& handler) NOEXCEPT
565
{
566
    BC_ASSERT(stranded());
40 ✔
567

568
    try
569
    {
570
        if (websocket())
40 ✔
571
        {
572
            buffer.consume(buffer.size());
13 ✔
573
            do_ws_read_message(std::ref(buffer), handler);
13 ✔
574
        }
575
        else
576
        {
577
            auto remain = floored_subtract(buffer.max_size(), buffer.size());
27 ✔
578
            if (is_zero(remain))
27 ✔
579
            {
580
                handler(error::buffer_overflow, {});
1 ✔
581
                return;
1 ✔
582
            }
583

584
            VARIANT_DISPATCH_METHOD(get_tcp(),
52 ✔
585
                async_read_some(buffer.prepare(remain),
586
                    std::bind(&socket::handle_async, shared_from_this(),
587
                    _1, _2, handler, "async_read_some")));
588
        }
589
    }
590
    catch (const std::exception& e)
×
591
    {
592
        LOGF("Exception @ async_read: " << e.what());
×
593
        handler(error::operation_failed, {});
×
594
    }
×
595
}
596

597
// read tcp fixed count of bytes (waits until mutable buffer is filled).
598
void socket::async_read(const io::mutable_buffer& buffer,
76,002 ✔
599
    const count_handler& handler) NOEXCEPT
600
{
601
    BC_ASSERT(stranded());
76,002 ✔
602

603
    if (websocket())
76,002 ✔
604
    {
605
        // Websockets read frame not size, use async_read(flat_buffer).
606
        handler(error::operation_failed, {});
1 ✔
607
    }
608
    else
609
    {
610
        // Fixed-size semantics.
611
        VARIANT_DISPATCH_FUNCTION(io::async_read, get_tcp(),
152,002 ✔
612
            buffer, std::bind(&socket::handle_async,
613
                shared_from_this(), _1, _2, handler, "async_read"));
614
    }
615
}
76,002 ✔
616

617
void socket::async_read_http(http::flat_buffer& buffer, http::request& request,
26 ✔
618
    const count_handler& handler) NOEXCEPT
619
{
620
    BC_ASSERT(stranded());
26 ✔
621

622
    if (websocket())
26 ✔
623
    {
624
        // Body reader processes websocket read just like
625
        // http read but without headers. Expected body type
626
        // (parser) must be preselected on request object.
627
        body_read(buffer, request, move_copy(handler));
8 ✔
628
    }
629
    else
630
    {
631
        const auto parser = to_shared<http_parser>();
18 ✔
632
        parser->body_limit(maximum_);
18 ✔
633
        parser->header_limit(header_);
18 ✔
634
        do_parse(std::ref(buffer), parser, parse_mode::all, zero,
18 ✔
635
            std::bind(&socket::handle_http_read,
36 ✔
636
                shared_from_this(), _1, _2, std::ref(request), parser,
36 ✔
637
                handler));
638
    }
18 ✔
639
}
26 ✔
640

641
void socket::async_write_http(http::response&& response,
41 ✔
642
    const count_handler& handler) NOEXCEPT
643
{
644
    BC_ASSERT(stranded());
41 ✔
645
    assign_buffer(response.body());
41 ✔
646

647
    if (websocket())
41 ✔
648
    {
649
        // Body writer processes websocket write just like
650
        // http write but without headers. Expected body type
651
        // (serializer) is determined by caller-assigned body.
652
        body_write(std::move(response), move_copy(handler));
6 ✔
653
    }
654
    else
655
    {
656
        const auto out = emplace_shared<serialize_state<http_serializer>>(
657
            std::move(response));
35 ✔
658

659
        do_serialize(out, zero,
35 ✔
660
            std::bind(&socket::handle_http_write,
70 ✔
661
                shared_from_this(), _1, _2, handler));
70 ✔
662
    }
35 ✔
663
}
41 ✔
664

665
// Handlers.
666
// ----------------------------------------------------------------------------
667

668
// private
669
void socket::handle_async(const code& ec, size_t size,
76,289 ✔
670
    const count_handler& handler, const std::string& operation) NOEXCEPT
671
{
672
    BC_ASSERT(stranded());
76,289 ✔
673

674
    if (ec == error::operation_canceled)
76,289 ✔
675
    {
676
        handler(error::channel_stopped, size);
29 ✔
677
        return;
29 ✔
678
    }
679

680

681
    if (ec == error::unknown)
76,260 ✔
682
        logx(operation, ec);
×
683

684
    handler(ec, size);
76,260 ✔
685
}
686

687
// Logging.
688
// ----------------------------------------------------------------------------
689
// private
690

691
void socket::logx(const std::string& context,
×
692
    const code& ec) const NOEXCEPT
693
{
694
    LOGX("Socket " << context << " error (" << ec.value() << ") "
×
695
        << ec.category().name() << " : " << ec.message());
696
}
×
697

698
BC_POP_WARNING()
699
BC_POP_WARNING()
700
BC_POP_WARNING()
701

702
} // namespace network
703
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc