Skip to content

Commit 95ed934

Browse files
CDRIVER-3871 implement public setters and getters for timeoutMS
1 parent 20cada3 commit 95ed934

23 files changed

+402
-17
lines changed

src/libmongoc/doc/errors.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Many C Driver functions report errors by returning ``false`` or -1 and filling o
9797
+-----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
9898
| ``MONGOC_ERROR_CLIENT_SIDE_ENCRYPTION`` | Error code produced by libmongocrypt. | An error occurred in the library responsible for Client Side Encryption |
9999
+-----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
100+
| ``MONGOC_ERROR_TIMEOUT`` | ``MONGOC_ERROR_TIMEOUT_INVALID`` | You passed an invalid value for a timeout paramenter. |
101+
+-----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
100102

101103
.. _error_labels:
102104

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
:man_page: mongoc_client_get_timeout_ms
2+
3+
mongoc_client_get_timeout_ms()
4+
==============================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
int64_t
12+
mongoc_client_get_timeout_ms (const mongoc_client_t *client)
13+
14+
Returns the client-side operation timeout value for this object. If ``client`` does not have a timeout currently set, this method returns -1 for MONGOC_TIMEOUTMS_UNSET.
15+
16+
Parameters
17+
----------
18+
19+
* ``client``: A :symbol:`mongoc_client_t`.
20+
21+
Returns
22+
-------
23+
24+
The timeout set on this client or -1 for MONGOC_TIMEOUTMS_UNSET.

src/libmongoc/doc/mongoc_client_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Example
6868
mongoc_client_get_server_description
6969
mongoc_client_get_server_descriptions
7070
mongoc_client_get_server_status
71+
mongoc_client_get_timeout_ms
7172
mongoc_client_get_uri
7273
mongoc_client_get_write_concern
7374
mongoc_client_new
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
:man_page: mongoc_collection_get_timeout_ms
2+
3+
mongoc_collection_get_timeout_ms()
4+
==================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
int64_t
12+
mongoc_collection_get_timeout_ms (const mongoc_collection_t *collection)
13+
14+
Returns the client-side operation timeout value for this object. If ``collection`` does not have a timeout currently set, this method will return a value inherited from the parent :symbol:`mongoc_database_t` or :symbol:`mongoc_client_t` object. If no timeout is set on any parent object, returns -1 for MONGOC_TIMEOUTMS_UNSET.
15+
16+
Parameters
17+
----------
18+
19+
* ``collection``: A :symbol:`mongoc_collection_t`.
20+
21+
Returns
22+
-------
23+
24+
The timeout set on this collection or inherited from a parent object.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
:man_page: mongoc_collection_set_timeout_ms
2+
3+
mongoc_collection_set_timeout_ms()
4+
==================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_collection_set_timeout_ms (mongoc_collection_t *collection, int64_t timeout_ms, bson_error_t *error)
13+
14+
Sets the client-side operation timeout value for ``collection`` to the given ``timeout_ms``. If there is an error setting the timeout, this method will return false and ``error`` will be set.
15+
16+
17+
This function will set ``error`` and return false in the following cases:
18+
19+
* ``timeout_ms`` is a negative number
20+
21+
Parameters
22+
----------
23+
24+
* ``collection``: A :symbol:`mongoc_collection_t`.
25+
* ``timeout_ms``: A value, in milliseconds, for the timeout. Must be non-negative.
26+
27+
Returns
28+
-------
29+
30+
true if the timeout_ms is set successfully. Otherwise, false.

src/libmongoc/doc/mongoc_collection_t.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Read preferences and write concerns are inherited from the parent client. They c
5858
mongoc_collection_get_name
5959
mongoc_collection_get_read_concern
6060
mongoc_collection_get_read_prefs
61+
mongoc_collection_get_timeout_ms
6162
mongoc_collection_get_write_concern
6263
mongoc_collection_insert
6364
mongoc_collection_insert_bulk
@@ -73,6 +74,7 @@ Read preferences and write concerns are inherited from the parent client. They c
7374
mongoc_collection_save
7475
mongoc_collection_set_read_concern
7576
mongoc_collection_set_read_prefs
77+
mongoc_collection_set_timeout_ms
7678
mongoc_collection_set_write_concern
7779
mongoc_collection_stats
7880
mongoc_collection_update
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
:man_page: mongoc_database_get_timeout_ms
2+
3+
mongoc_database_get_timeout_ms()
4+
================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
int64_t
12+
mongoc_database_get_timeout_ms (const mongoc_database_t *database)
13+
14+
Returns the client-side operation timeout value for this object. If ``database`` does not have a timeout currently set, this method will return a value inherited from the parent :symbol:`mongoc_client_t` object. If no timeout is set on the parent object, returns -1, or MONGOC_TIMEOUTMS_UNSET.
15+
16+
Parameters
17+
----------
18+
19+
* ``database``: A :symbol:`mongoc_database_t`.
20+
21+
Returns
22+
-------
23+
24+
The timeout set on this database or inherited from a parent object.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
:man_page: mongoc_database_set_timeout_ms
2+
3+
mongoc_database_set_timeout_ms()
4+
================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_database_set_timeout_ms (mongoc_database_t *database, int64_t timeout_ms, bson_error_t *error)
13+
14+
Sets the client-side operation timeout value for ``database`` to the given ``timeout_ms``. If there is an error setting the timeout, this method will return false and ``error`` will be set.
15+
16+
17+
This function will set ``error`` and return false in the following cases:
18+
19+
* ``timeout_ms`` is a negative number
20+
21+
Parameters
22+
----------
23+
24+
* ``database``: A :symbol:`mongoc_database_t`.
25+
* ``timeout_ms``: A value, in milliseconds, for the timeout. Must be non-negative.
26+
27+
Returns
28+
-------
29+
30+
true if the timeout_ms is set successfully. Otherwise, false.

src/libmongoc/doc/mongoc_database_t.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Read preferences and write concerns are inherited from the parent client. They c
4343
mongoc_database_get_name
4444
mongoc_database_get_read_concern
4545
mongoc_database_get_read_prefs
46+
mongoc_database_get_timeout_ms
4647
mongoc_database_get_write_concern
4748
mongoc_database_has_collection
4849
mongoc_database_read_command_with_opts
@@ -51,6 +52,7 @@ Read preferences and write concerns are inherited from the parent client. They c
5152
mongoc_database_remove_user
5253
mongoc_database_set_read_concern
5354
mongoc_database_set_read_prefs
55+
mongoc_database_set_timeout_ms
5456
mongoc_database_set_write_concern
5557
mongoc_database_watch
5658
mongoc_database_write_command_with_opts

src/libmongoc/src/mongoc/mongoc-client-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ struct _mongoc_client_t {
122122
mongoc_set_t *client_sessions;
123123
unsigned int csid_rand_seed;
124124

125+
int64_t timeout_ms;
126+
125127
uint32_t generation;
126128
};
127129

0 commit comments

Comments
 (0)