@@ -668,9 +668,18 @@ class Server {
668
668
669
669
Server &set_keep_alive_max_count (size_t count);
670
670
Server &set_keep_alive_timeout (time_t sec);
671
+
671
672
Server &set_read_timeout (time_t sec, time_t usec = 0 );
673
+ template <class Rep , class Period >
674
+ Server &set_read_timeout (const std::chrono::duration<Rep, Period> &duration);
675
+
672
676
Server &set_write_timeout (time_t sec, time_t usec = 0 );
677
+ template <class Rep , class Period >
678
+ Server &set_write_timeout (const std::chrono::duration<Rep, Period> &duration);
679
+
673
680
Server &set_idle_interval (time_t sec, time_t usec = 0 );
681
+ template <class Rep , class Period >
682
+ Server &set_idle_interval (const std::chrono::duration<Rep, Period> &duration);
674
683
675
684
Server &set_payload_max_length (size_t length);
676
685
@@ -966,8 +975,16 @@ class ClientImpl {
966
975
void set_socket_options (SocketOptions socket_options);
967
976
968
977
void set_connection_timeout (time_t sec, time_t usec = 0 );
978
+ template <class Rep , class Period >
979
+ void set_connection_timeout (const std::chrono::duration<Rep, Period> &duration);
980
+
969
981
void set_read_timeout (time_t sec, time_t usec = 0 );
982
+ template <class Rep , class Period >
983
+ void set_read_timeout (const std::chrono::duration<Rep, Period> &duration);
984
+
970
985
void set_write_timeout (time_t sec, time_t usec = 0 );
986
+ template <class Rep , class Period >
987
+ void set_write_timeout (const std::chrono::duration<Rep, Period> &duration);
971
988
972
989
void set_basic_auth (const char *username, const char *password);
973
990
void set_bearer_token_auth (const char *token);
@@ -1268,8 +1285,16 @@ class Client {
1268
1285
void set_socket_options (SocketOptions socket_options);
1269
1286
1270
1287
void set_connection_timeout (time_t sec, time_t usec = 0 );
1288
+ template <class Rep , class Period >
1289
+ void set_connection_timeout (const std::chrono::duration<Rep, Period> &duration);
1290
+
1271
1291
void set_read_timeout (time_t sec, time_t usec = 0 );
1292
+ template <class Rep , class Period >
1293
+ void set_read_timeout (const std::chrono::duration<Rep, Period> &duration);
1294
+
1272
1295
void set_write_timeout (time_t sec, time_t usec = 0 );
1296
+ template <class Rep , class Period >
1297
+ void set_write_timeout (const std::chrono::duration<Rep, Period> &duration);
1273
1298
1274
1299
void set_basic_auth (const char *username, const char *password);
1275
1300
void set_bearer_token_auth (const char *token);
@@ -3804,6 +3829,15 @@ class ContentProviderAdapter {
3804
3829
ContentProviderWithoutLength content_provider_;
3805
3830
};
3806
3831
3832
+ template <typename T, typename U>
3833
+ inline void duration_to_sec_and_usec (const T &duration, U callback) {
3834
+ auto sec = std::chrono::duration_cast<std::chrono::seconds>(duration).count ();
3835
+ auto usec = std::chrono::duration_cast<std::chrono::microseconds>(
3836
+ duration - std::chrono::seconds (sec))
3837
+ .count ();
3838
+ callback (sec, usec);
3839
+ }
3840
+
3807
3841
} // namespace detail
3808
3842
3809
3843
// Header utilities
@@ -4381,20 +4415,47 @@ inline Server &Server::set_read_timeout(time_t sec, time_t usec) {
4381
4415
return *this ;
4382
4416
}
4383
4417
4418
+ template <class Rep , class Period >
4419
+ inline Server &Server::set_read_timeout (
4420
+ const std::chrono::duration<Rep, Period> &duration) {
4421
+ detail::duration_to_sec_and_usec (duration, [&](time_t sec, time_t usec) {
4422
+ set_read_timeout (sec, usec);
4423
+ });
4424
+ return *this ;
4425
+ }
4426
+
4384
4427
inline Server &Server::set_write_timeout (time_t sec, time_t usec) {
4385
4428
write_timeout_sec_ = sec;
4386
4429
write_timeout_usec_ = usec;
4387
4430
4388
4431
return *this ;
4389
4432
}
4390
4433
4434
+ template <class Rep , class Period >
4435
+ inline Server &Server::set_write_timeout (
4436
+ const std::chrono::duration<Rep, Period> &duration) {
4437
+ detail::duration_to_sec_and_usec (duration, [&](time_t sec, time_t usec) {
4438
+ set_write_timeout (sec, usec);
4439
+ });
4440
+ return *this ;
4441
+ }
4442
+
4391
4443
inline Server &Server::set_idle_interval (time_t sec, time_t usec) {
4392
4444
idle_interval_sec_ = sec;
4393
4445
idle_interval_usec_ = usec;
4394
4446
4395
4447
return *this ;
4396
4448
}
4397
4449
4450
+ template <class Rep , class Period >
4451
+ inline Server &Server::set_idle_interval (
4452
+ const std::chrono::duration<Rep, Period> &duration) {
4453
+ detail::duration_to_sec_and_usec (duration, [&](time_t sec, time_t usec) {
4454
+ set_idle_interval (sec, usec);
4455
+ });
4456
+ return *this ;
4457
+ }
4458
+
4398
4459
inline Server &Server::set_payload_max_length (size_t length) {
4399
4460
payload_max_length_ = length;
4400
4461
@@ -6273,16 +6334,40 @@ inline void ClientImpl::set_connection_timeout(time_t sec, time_t usec) {
6273
6334
connection_timeout_usec_ = usec;
6274
6335
}
6275
6336
6337
+ template <class Rep , class Period >
6338
+ inline void ClientImpl::set_connection_timeout (
6339
+ const std::chrono::duration<Rep, Period> &duration) {
6340
+ detail::duration_to_sec_and_usec (duration, [&](time_t sec, time_t usec) {
6341
+ set_connection_timeout (sec, usec);
6342
+ });
6343
+ }
6344
+
6276
6345
inline void ClientImpl::set_read_timeout (time_t sec, time_t usec) {
6277
6346
read_timeout_sec_ = sec;
6278
6347
read_timeout_usec_ = usec;
6279
6348
}
6280
6349
6350
+ template <class Rep , class Period >
6351
+ inline void ClientImpl::set_read_timeout (
6352
+ const std::chrono::duration<Rep, Period> &duration) {
6353
+ detail::duration_to_sec_and_usec (duration, [&](time_t sec, time_t usec) {
6354
+ set_read_timeout (sec, usec);
6355
+ });
6356
+ }
6357
+
6281
6358
inline void ClientImpl::set_write_timeout (time_t sec, time_t usec) {
6282
6359
write_timeout_sec_ = sec;
6283
6360
write_timeout_usec_ = usec;
6284
6361
}
6285
6362
6363
+ template <class Rep , class Period >
6364
+ inline void ClientImpl::set_write_timeout (
6365
+ const std::chrono::duration<Rep, Period> &duration) {
6366
+ detail::duration_to_sec_and_usec (duration, [&](time_t sec, time_t usec) {
6367
+ set_write_timeout (sec, usec);
6368
+ });
6369
+ }
6370
+
6286
6371
inline void ClientImpl::set_basic_auth (const char *username,
6287
6372
const char *password) {
6288
6373
basic_auth_username_ = username;
@@ -7372,20 +7457,41 @@ inline void Client::set_default_headers(Headers headers) {
7372
7457
}
7373
7458
7374
7459
inline void Client::set_tcp_nodelay (bool on) { cli_->set_tcp_nodelay (on); }
7460
+
7375
7461
inline void Client::set_socket_options (SocketOptions socket_options) {
7376
7462
cli_->set_socket_options (std::move (socket_options));
7377
7463
}
7378
7464
7379
7465
inline void Client::set_connection_timeout (time_t sec, time_t usec) {
7380
7466
cli_->set_connection_timeout (sec, usec);
7381
7467
}
7468
+
7469
+ template <class Rep , class Period >
7470
+ inline void Client::set_connection_timeout (
7471
+ const std::chrono::duration<Rep, Period> &duration) {
7472
+ cli_->set_connection_timeout (duration);
7473
+ }
7474
+
7382
7475
inline void Client::set_read_timeout (time_t sec, time_t usec) {
7383
7476
cli_->set_read_timeout (sec, usec);
7384
7477
}
7478
+
7479
+ template <class Rep , class Period >
7480
+ inline void Client::set_read_timeout (
7481
+ const std::chrono::duration<Rep, Period> &duration) {
7482
+ cli_->set_read_timeout (duration);
7483
+ }
7484
+
7385
7485
inline void Client::set_write_timeout (time_t sec, time_t usec) {
7386
7486
cli_->set_write_timeout (sec, usec);
7387
7487
}
7388
7488
7489
+ template <class Rep , class Period >
7490
+ inline void Client::set_write_timeout (
7491
+ const std::chrono::duration<Rep, Period> &duration) {
7492
+ cli_->set_write_timeout (duration);
7493
+ }
7494
+
7389
7495
inline void Client::set_basic_auth (const char *username, const char *password) {
7390
7496
cli_->set_basic_auth (username, password);
7391
7497
}
0 commit comments