-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #1751 Support nng_aio_set_expire().
While here fixed a number of nits in comments.
- Loading branch information
Showing
6 changed files
with
62 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
= nng_aio_set_timeout(3) | ||
// | ||
// Copyright 2018 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2023 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2018 Capitar IT Group BV <[email protected]> | ||
// | ||
// This document is supplied under the terms of the MIT License, a | ||
|
@@ -21,6 +21,9 @@ nng_aio_set_timeout - set asynchronous I/O timeout | |
typedef int nng_duration; | ||
void nng_aio_set_timeout(nng_aio *aio, nng_duration timeout); | ||
typedef uint64_t nng_time; | ||
void nng_aio_set_expire(nng_aio *aio, nng_time expiration); | ||
---- | ||
|
||
== DESCRIPTION | ||
|
@@ -37,6 +40,12 @@ If the timeout is `NNG_DURATION_DEFAULT`, then a "default" or socket-specific | |
timeout is used. | ||
(This is frequently the same as `NNG_DURATION_INFINITE`.) | ||
|
||
The `nng_aio_set_expire()` function is similar to `nng_aio_set_timeout()`, but sets | ||
an absolute expiration time based on the system clock. The _expiration_ | ||
is expressed as a number of milliseconds since some point in the past. | ||
The xref:nng_clock.3supp.adoc[`nng_clock()`] function can be used to determine | ||
the current value of the clock. | ||
|
||
TIP: As most operations involve some context switching, it is usually a good | ||
idea to allow at least a few tens of milliseconds before timing them out -- | ||
a too small timeout might not allow the operation to properly begin before | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Copyright 2018 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2023 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2018 Capitar IT Group BV <[email protected]> | ||
// | ||
// This software is supplied under the terms of the MIT License, a | ||
|
@@ -27,13 +27,9 @@ | |
extern "C" { | ||
#endif | ||
|
||
// nng_time represents an absolute time since some arbitrary point in the | ||
// past, measured in milliseconds. The values are always positive. | ||
typedef uint64_t nng_time; | ||
|
||
// Return an absolute time from some arbitrary point. The value is | ||
// provided in milliseconds, and is of limited resolution based on the | ||
// system clock. (Do not use it for fine grained performance measurements.) | ||
// system clock. (Do not use it for fine-grained performance measurements.) | ||
NNG_DECL nng_time nng_clock(void); | ||
|
||
// Sleep for specified msecs. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// Copyright 2022 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2023 Staysail Systems, Inc. <[email protected]> | ||
// Copyright 2018 Capitar IT Group BV <[email protected]> | ||
// | ||
// This software is supplied under the terms of the MIT License, a | ||
|
@@ -190,6 +190,27 @@ test_explicit_timeout(void) | |
NUTS_PASS(nng_close(s)); | ||
} | ||
|
||
void | ||
test_explicit_expiration(void) | ||
{ | ||
nng_socket s; | ||
nng_aio * a; | ||
int done = 0; | ||
nng_time now; | ||
|
||
NUTS_PASS(nng_pair1_open(&s)); | ||
NUTS_PASS(nng_aio_alloc(&a, cb_done, &done)); | ||
now = nng_clock(); | ||
now += 40; | ||
nng_aio_set_expire(a, now); | ||
nng_recv_aio(s, a); | ||
nng_aio_wait(a); | ||
NUTS_TRUE(done == 1); | ||
NUTS_FAIL(nng_aio_result(a), NNG_ETIMEDOUT); | ||
nng_aio_free(a); | ||
NUTS_PASS(nng_close(s)); | ||
} | ||
|
||
void | ||
test_inherited_timeout(void) | ||
{ | ||
|
@@ -384,6 +405,7 @@ NUTS_TESTS = { | |
{ "consumer cancel", test_consumer_cancel }, | ||
{ "traffic", test_traffic }, | ||
{ "explicit timeout", test_explicit_timeout }, | ||
{ "explicit expire", test_explicit_expiration }, | ||
{ "inherited timeout", test_inherited_timeout }, | ||
{ "zero timeout", test_zero_timeout }, | ||
{ "aio reap", test_aio_reap }, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters