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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
//
// socket_base.cpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/socket_base.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ip/udp.hpp>
#include "unit_test.hpp"
//------------------------------------------------------------------------------
// socket_base_compile test
// ~~~~~~~~~~~~~~~~~~~~~~~~
// The following test checks that all nested classes, enums and constants in
// socket_base compile and link correctly. Runtime failures are ignored.
namespace socket_base_compile {
void test()
{
using namespace boost::asio;
namespace ip = boost::asio::ip;
try
{
io_context ioc;
ip::tcp::socket sock(ioc);
char buf[1024];
// shutdown_type enumeration.
sock.shutdown(socket_base::shutdown_receive);
sock.shutdown(socket_base::shutdown_send);
sock.shutdown(socket_base::shutdown_both);
// message_flags constants.
sock.receive(buffer(buf), socket_base::message_peek);
sock.receive(buffer(buf), socket_base::message_out_of_band);
sock.send(buffer(buf), socket_base::message_do_not_route);
// broadcast class.
socket_base::broadcast broadcast1(true);
sock.set_option(broadcast1);
socket_base::broadcast broadcast2;
sock.get_option(broadcast2);
broadcast1 = true;
(void)static_cast<bool>(broadcast1);
(void)static_cast<bool>(!broadcast1);
(void)static_cast<bool>(broadcast1.value());
// debug class.
socket_base::debug debug1(true);
sock.set_option(debug1);
socket_base::debug debug2;
sock.get_option(debug2);
debug1 = true;
(void)static_cast<bool>(debug1);
(void)static_cast<bool>(!debug1);
(void)static_cast<bool>(debug1.value());
// do_not_route class.
socket_base::do_not_route do_not_route1(true);
sock.set_option(do_not_route1);
socket_base::do_not_route do_not_route2;
sock.get_option(do_not_route2);
do_not_route1 = true;
(void)static_cast<bool>(do_not_route1);
(void)static_cast<bool>(!do_not_route1);
(void)static_cast<bool>(do_not_route1.value());
// keep_alive class.
socket_base::keep_alive keep_alive1(true);
sock.set_option(keep_alive1);
socket_base::keep_alive keep_alive2;
sock.get_option(keep_alive2);
keep_alive1 = true;
(void)static_cast<bool>(keep_alive1);
(void)static_cast<bool>(!keep_alive1);
(void)static_cast<bool>(keep_alive1.value());
// send_buffer_size class.
socket_base::send_buffer_size send_buffer_size1(1024);
sock.set_option(send_buffer_size1);
socket_base::send_buffer_size send_buffer_size2;
sock.get_option(send_buffer_size2);
send_buffer_size1 = 1;
(void)static_cast<int>(send_buffer_size1.value());
// send_low_watermark class.
socket_base::send_low_watermark send_low_watermark1(128);
sock.set_option(send_low_watermark1);
socket_base::send_low_watermark send_low_watermark2;
sock.get_option(send_low_watermark2);
send_low_watermark1 = 1;
(void)static_cast<int>(send_low_watermark1.value());
// receive_buffer_size class.
socket_base::receive_buffer_size receive_buffer_size1(1024);
sock.set_option(receive_buffer_size1);
socket_base::receive_buffer_size receive_buffer_size2;
sock.get_option(receive_buffer_size2);
receive_buffer_size1 = 1;
(void)static_cast<int>(receive_buffer_size1.value());
// receive_low_watermark class.
socket_base::receive_low_watermark receive_low_watermark1(128);
sock.set_option(receive_low_watermark1);
socket_base::receive_low_watermark receive_low_watermark2;
sock.get_option(receive_low_watermark2);
receive_low_watermark1 = 1;
(void)static_cast<int>(receive_low_watermark1.value());
// reuse_address class.
socket_base::reuse_address reuse_address1(true);
sock.set_option(reuse_address1);
socket_base::reuse_address reuse_address2;
sock.get_option(reuse_address2);
reuse_address1 = true;
(void)static_cast<bool>(reuse_address1);
(void)static_cast<bool>(!reuse_address1);
(void)static_cast<bool>(reuse_address1.value());
// linger class.
socket_base::linger linger1(true, 30);
sock.set_option(linger1);
socket_base::linger linger2;
sock.get_option(linger2);
linger1.enabled(true);
(void)static_cast<bool>(linger1.enabled());
linger1.timeout(1);
(void)static_cast<int>(linger1.timeout());
// out_of_band_inline class.
socket_base::out_of_band_inline out_of_band_inline1(true);
sock.set_option(out_of_band_inline1);
socket_base::out_of_band_inline out_of_band_inline2;
sock.get_option(out_of_band_inline2);
out_of_band_inline1 = true;
(void)static_cast<bool>(out_of_band_inline1);
(void)static_cast<bool>(!out_of_band_inline1);
(void)static_cast<bool>(out_of_band_inline1.value());
// enable_connection_aborted class.
socket_base::enable_connection_aborted enable_connection_aborted1(true);
sock.set_option(enable_connection_aborted1);
socket_base::enable_connection_aborted enable_connection_aborted2;
sock.get_option(enable_connection_aborted2);
enable_connection_aborted1 = true;
(void)static_cast<bool>(enable_connection_aborted1);
(void)static_cast<bool>(!enable_connection_aborted1);
(void)static_cast<bool>(enable_connection_aborted1.value());
// bytes_readable class.
socket_base::bytes_readable bytes_readable;
sock.io_control(bytes_readable);
std::size_t bytes = bytes_readable.get();
(void)bytes;
}
catch (std::exception&)
{
}
}
} // namespace socket_base_compile
//------------------------------------------------------------------------------
// socket_base_runtime test
// ~~~~~~~~~~~~~~~~~~~~~~~~
// The following test checks the runtime operation of the socket options and I/O
// control commands defined in socket_base.
namespace socket_base_runtime {
void test()
{
using namespace boost::asio;
namespace ip = boost::asio::ip;
io_context ioc;
ip::udp::socket udp_sock(ioc, ip::udp::v4());
ip::tcp::socket tcp_sock(ioc, ip::tcp::v4());
ip::tcp::acceptor tcp_acceptor(ioc, ip::tcp::v4());
boost::system::error_code ec;
// broadcast class.
socket_base::broadcast broadcast1(true);
BOOST_ASIO_CHECK(broadcast1.value());
BOOST_ASIO_CHECK(static_cast<bool>(broadcast1));
BOOST_ASIO_CHECK(!!broadcast1);
udp_sock.set_option(broadcast1, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::broadcast broadcast2;
udp_sock.get_option(broadcast2, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(broadcast2.value());
BOOST_ASIO_CHECK(static_cast<bool>(broadcast2));
BOOST_ASIO_CHECK(!!broadcast2);
socket_base::broadcast broadcast3(false);
BOOST_ASIO_CHECK(!broadcast3.value());
BOOST_ASIO_CHECK(!static_cast<bool>(broadcast3));
BOOST_ASIO_CHECK(!broadcast3);
udp_sock.set_option(broadcast3, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::broadcast broadcast4;
udp_sock.get_option(broadcast4, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(!broadcast4.value());
BOOST_ASIO_CHECK(!static_cast<bool>(broadcast4));
BOOST_ASIO_CHECK(!broadcast4);
// debug class.
socket_base::debug debug1(true);
BOOST_ASIO_CHECK(debug1.value());
BOOST_ASIO_CHECK(static_cast<bool>(debug1));
BOOST_ASIO_CHECK(!!debug1);
udp_sock.set_option(debug1, ec);
#if defined(__linux__)
// On Linux, only root can set SO_DEBUG.
bool not_root = (ec == boost::asio::error::access_denied);
BOOST_ASIO_CHECK(!ec || not_root);
BOOST_ASIO_WARN_MESSAGE(!ec, "Must be root to set debug socket option");
#else // defined(__linux__)
# if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
# else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
# endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
#endif // defined(__linux__)
socket_base::debug debug2;
udp_sock.get_option(debug2, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
# if defined(__linux__)
BOOST_ASIO_CHECK(debug2.value() || not_root);
BOOST_ASIO_CHECK(static_cast<bool>(debug2) || not_root);
BOOST_ASIO_CHECK(!!debug2 || not_root);
# else // defined(__linux__)
BOOST_ASIO_CHECK(debug2.value());
BOOST_ASIO_CHECK(static_cast<bool>(debug2));
BOOST_ASIO_CHECK(!!debug2);
# endif // defined(__linux__)
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
socket_base::debug debug3(false);
BOOST_ASIO_CHECK(!debug3.value());
BOOST_ASIO_CHECK(!static_cast<bool>(debug3));
BOOST_ASIO_CHECK(!debug3);
udp_sock.set_option(debug3, ec);
#if defined(__linux__)
BOOST_ASIO_CHECK(!ec || not_root);
#else // defined(__linux__)
# if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
# else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
# endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
#endif // defined(__linux__)
socket_base::debug debug4;
udp_sock.get_option(debug4, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
# if defined(__linux__)
BOOST_ASIO_CHECK(!debug4.value() || not_root);
BOOST_ASIO_CHECK(!static_cast<bool>(debug4) || not_root);
BOOST_ASIO_CHECK(!debug4 || not_root);
# else // defined(__linux__)
BOOST_ASIO_CHECK(!debug4.value());
BOOST_ASIO_CHECK(!static_cast<bool>(debug4));
BOOST_ASIO_CHECK(!debug4);
# endif // defined(__linux__)
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// do_not_route class.
socket_base::do_not_route do_not_route1(true);
BOOST_ASIO_CHECK(do_not_route1.value());
BOOST_ASIO_CHECK(static_cast<bool>(do_not_route1));
BOOST_ASIO_CHECK(!!do_not_route1);
udp_sock.set_option(do_not_route1, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
socket_base::do_not_route do_not_route2;
udp_sock.get_option(do_not_route2, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(do_not_route2.value());
BOOST_ASIO_CHECK(static_cast<bool>(do_not_route2));
BOOST_ASIO_CHECK(!!do_not_route2);
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
socket_base::do_not_route do_not_route3(false);
BOOST_ASIO_CHECK(!do_not_route3.value());
BOOST_ASIO_CHECK(!static_cast<bool>(do_not_route3));
BOOST_ASIO_CHECK(!do_not_route3);
udp_sock.set_option(do_not_route3, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
socket_base::do_not_route do_not_route4;
udp_sock.get_option(do_not_route4, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(!do_not_route4.value());
BOOST_ASIO_CHECK(!static_cast<bool>(do_not_route4));
BOOST_ASIO_CHECK(!do_not_route4);
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// keep_alive class.
socket_base::keep_alive keep_alive1(true);
BOOST_ASIO_CHECK(keep_alive1.value());
BOOST_ASIO_CHECK(static_cast<bool>(keep_alive1));
BOOST_ASIO_CHECK(!!keep_alive1);
tcp_sock.set_option(keep_alive1, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::keep_alive keep_alive2;
tcp_sock.get_option(keep_alive2, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(keep_alive2.value());
BOOST_ASIO_CHECK(static_cast<bool>(keep_alive2));
BOOST_ASIO_CHECK(!!keep_alive2);
socket_base::keep_alive keep_alive3(false);
BOOST_ASIO_CHECK(!keep_alive3.value());
BOOST_ASIO_CHECK(!static_cast<bool>(keep_alive3));
BOOST_ASIO_CHECK(!keep_alive3);
tcp_sock.set_option(keep_alive3, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::keep_alive keep_alive4;
tcp_sock.get_option(keep_alive4, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(!keep_alive4.value());
BOOST_ASIO_CHECK(!static_cast<bool>(keep_alive4));
BOOST_ASIO_CHECK(!keep_alive4);
// send_buffer_size class.
socket_base::send_buffer_size send_buffer_size1(4096);
BOOST_ASIO_CHECK(send_buffer_size1.value() == 4096);
tcp_sock.set_option(send_buffer_size1, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::send_buffer_size send_buffer_size2;
tcp_sock.get_option(send_buffer_size2, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(send_buffer_size2.value() == 4096);
socket_base::send_buffer_size send_buffer_size3(16384);
BOOST_ASIO_CHECK(send_buffer_size3.value() == 16384);
tcp_sock.set_option(send_buffer_size3, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::send_buffer_size send_buffer_size4;
tcp_sock.get_option(send_buffer_size4, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(send_buffer_size4.value() == 16384);
// send_low_watermark class.
socket_base::send_low_watermark send_low_watermark1(4096);
BOOST_ASIO_CHECK(send_low_watermark1.value() == 4096);
tcp_sock.set_option(send_low_watermark1, ec);
#if defined(WIN32) || defined(__linux__) || defined(__sun)
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows, Linux or Solaris.
#else
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
#endif
socket_base::send_low_watermark send_low_watermark2;
tcp_sock.get_option(send_low_watermark2, ec);
#if defined(WIN32) || defined(__sun)
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
#elif defined(__linux__)
BOOST_ASIO_CHECK(!ec); // Not supported on Linux but can get value.
#else
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(send_low_watermark2.value() == 4096);
#endif
socket_base::send_low_watermark send_low_watermark3(8192);
BOOST_ASIO_CHECK(send_low_watermark3.value() == 8192);
tcp_sock.set_option(send_low_watermark3, ec);
#if defined(WIN32) || defined(__linux__) || defined(__sun)
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows, Linux or Solaris.
#else
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
#endif
socket_base::send_low_watermark send_low_watermark4;
tcp_sock.get_option(send_low_watermark4, ec);
#if defined(WIN32) || defined(__sun)
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
#elif defined(__linux__)
BOOST_ASIO_CHECK(!ec); // Not supported on Linux but can get value.
#else
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(send_low_watermark4.value() == 8192);
#endif
// receive_buffer_size class.
socket_base::receive_buffer_size receive_buffer_size1(4096);
BOOST_ASIO_CHECK(receive_buffer_size1.value() == 4096);
tcp_sock.set_option(receive_buffer_size1, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
socket_base::receive_buffer_size receive_buffer_size2;
tcp_sock.get_option(receive_buffer_size2, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK(!ec); // Not supported under Windows CE but can get value.
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(receive_buffer_size2.value() == 4096);
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
socket_base::receive_buffer_size receive_buffer_size3(16384);
BOOST_ASIO_CHECK(receive_buffer_size3.value() == 16384);
tcp_sock.set_option(receive_buffer_size3, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// Option is not supported under Windows CE.
BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option,
ec.value() << ", " << ec.message());
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
socket_base::receive_buffer_size receive_buffer_size4;
tcp_sock.get_option(receive_buffer_size4, ec);
#if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK(!ec); // Not supported under Windows CE but can get value.
#else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(receive_buffer_size4.value() == 16384);
#endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE)
// receive_low_watermark class.
socket_base::receive_low_watermark receive_low_watermark1(4096);
BOOST_ASIO_CHECK(receive_low_watermark1.value() == 4096);
tcp_sock.set_option(receive_low_watermark1, ec);
#if defined(WIN32) || defined(__sun)
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
#else
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
#endif
socket_base::receive_low_watermark receive_low_watermark2;
tcp_sock.get_option(receive_low_watermark2, ec);
#if defined(WIN32) || defined(__sun)
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
#else
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(receive_low_watermark2.value() == 4096);
#endif
socket_base::receive_low_watermark receive_low_watermark3(8192);
BOOST_ASIO_CHECK(receive_low_watermark3.value() == 8192);
tcp_sock.set_option(receive_low_watermark3, ec);
#if defined(WIN32) || defined(__sun)
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
#else
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
#endif
socket_base::receive_low_watermark receive_low_watermark4;
tcp_sock.get_option(receive_low_watermark4, ec);
#if defined(WIN32) || defined(__sun)
BOOST_ASIO_CHECK(!!ec); // Not supported on Windows or Solaris.
#else
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(receive_low_watermark4.value() == 8192);
#endif
// reuse_address class.
socket_base::reuse_address reuse_address1(true);
BOOST_ASIO_CHECK(reuse_address1.value());
BOOST_ASIO_CHECK(static_cast<bool>(reuse_address1));
BOOST_ASIO_CHECK(!!reuse_address1);
udp_sock.set_option(reuse_address1, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::reuse_address reuse_address2;
udp_sock.get_option(reuse_address2, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(reuse_address2.value());
BOOST_ASIO_CHECK(static_cast<bool>(reuse_address2));
BOOST_ASIO_CHECK(!!reuse_address2);
socket_base::reuse_address reuse_address3(false);
BOOST_ASIO_CHECK(!reuse_address3.value());
BOOST_ASIO_CHECK(!static_cast<bool>(reuse_address3));
BOOST_ASIO_CHECK(!reuse_address3);
udp_sock.set_option(reuse_address3, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::reuse_address reuse_address4;
udp_sock.get_option(reuse_address4, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(!reuse_address4.value());
BOOST_ASIO_CHECK(!static_cast<bool>(reuse_address4));
BOOST_ASIO_CHECK(!reuse_address4);
// linger class.
socket_base::linger linger1(true, 60);
BOOST_ASIO_CHECK(linger1.enabled());
BOOST_ASIO_CHECK(linger1.timeout() == 60);
tcp_sock.set_option(linger1, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::linger linger2;
tcp_sock.get_option(linger2, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(linger2.enabled());
BOOST_ASIO_CHECK(linger2.timeout() == 60);
socket_base::linger linger3(false, 0);
BOOST_ASIO_CHECK(!linger3.enabled());
BOOST_ASIO_CHECK(linger3.timeout() == 0);
tcp_sock.set_option(linger3, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::linger linger4;
tcp_sock.get_option(linger4, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(!linger4.enabled());
// enable_connection_aborted class.
socket_base::enable_connection_aborted enable_connection_aborted1(true);
BOOST_ASIO_CHECK(enable_connection_aborted1.value());
BOOST_ASIO_CHECK(static_cast<bool>(enable_connection_aborted1));
BOOST_ASIO_CHECK(!!enable_connection_aborted1);
tcp_acceptor.set_option(enable_connection_aborted1, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::enable_connection_aborted enable_connection_aborted2;
tcp_acceptor.get_option(enable_connection_aborted2, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(enable_connection_aborted2.value());
BOOST_ASIO_CHECK(static_cast<bool>(enable_connection_aborted2));
BOOST_ASIO_CHECK(!!enable_connection_aborted2);
socket_base::enable_connection_aborted enable_connection_aborted3(false);
BOOST_ASIO_CHECK(!enable_connection_aborted3.value());
BOOST_ASIO_CHECK(!static_cast<bool>(enable_connection_aborted3));
BOOST_ASIO_CHECK(!enable_connection_aborted3);
tcp_acceptor.set_option(enable_connection_aborted3, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
socket_base::enable_connection_aborted enable_connection_aborted4;
tcp_acceptor.get_option(enable_connection_aborted4, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
BOOST_ASIO_CHECK(!enable_connection_aborted4.value());
BOOST_ASIO_CHECK(!static_cast<bool>(enable_connection_aborted4));
BOOST_ASIO_CHECK(!enable_connection_aborted4);
// bytes_readable class.
socket_base::bytes_readable bytes_readable;
udp_sock.io_control(bytes_readable, ec);
BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
}
} // namespace socket_base_runtime
//------------------------------------------------------------------------------
BOOST_ASIO_TEST_SUITE
(
"socket_base",
BOOST_ASIO_TEST_CASE(socket_base_compile::test)
BOOST_ASIO_TEST_CASE(socket_base_runtime::test)
)
|