Skip to content

Commit 4835c38

Browse files
author
Jesse Williamson
authored
Fix CDRIVER3441 - document mongoc_handshake_data_append and alias as … (#852)
* Fix CDRIVER3441 - document mongoc_handshake_data_append and alias as mongoc_add_driver_info I took a slightly different tack on this and made the older form an alias to the preferred, newer one. https://jira.mongodb.org/browse/CDRIVER-3441 Signed-off-by: Jesse Williamson <[email protected]> * Add Sphinx documentation. Signed-off-by: Jesse Williamson <[email protected]> * Move inline documentation out of source. Signed-off-by: Jesse Williamson <[email protected]> * Add test showing that forwarding function can be called. Signed-off-by: Jesse Williamson <[email protected]> * Revert renaming and forwarding function. Signed-off-by: Jesse Williamson <[email protected]> * Update documentation: this is not deprecated, we will be offering an alternative. Signed-off-by: Jesse Williamson <[email protected]> * Add mongoc_handshake_data_append into the TOC/document structure. Signed-off-by: Jesse Williamson <[email protected]> * Update mongoc_handshake_data_append documentation to more accurately describe server monitoring and initiation. Some cosmetic adjustments. Signed-off-by: Jesse Williamson <[email protected]> * Update example responses to reflect current behavior. Signed-off-by: Jesse Williamson <[email protected]>
1 parent 0024b5d commit 4835c38

File tree

5 files changed

+90
-62
lines changed

5 files changed

+90
-62
lines changed

src/libmongoc/doc/mongoc_client_t.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ Example
8989
mongoc_client_start_session
9090
mongoc_client_watch
9191
mongoc_client_write_command_with_opts
92+
mongoc_handshake_data_append
93+
9294

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
:man_page: mongoc_handshake_data_append
2+
3+
mongoc_handshake_data_append()
4+
==============================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
bool
12+
mongoc_handshake_data_append (const char *driver_name,
13+
const char *driver_version,
14+
const char *platform);
15+
16+
Appends the given strings to the handshake data for the underlying C Driver.
17+
18+
Description
19+
-----------
20+
21+
This function is intended for use by drivers which wrap the C Driver.
22+
Calling this function will store the given strings as handshake data about
23+
the system and driver by appending them to the handshake data for the
24+
underlying C Driver. These values, along with other handshake data collected
25+
during mongoc_init will be sent to the server as part of the initial
26+
connection handshake in the "client" document. This function must not be
27+
called more than once, or after server monitoring begins. For a single-threaded
28+
:symbol:`mongoc_client_t`, server monitoring begins on the first operation
29+
requiring a server. For a :symbol:`mongoc_client_pool_t`, server monitoring
30+
begins on the first call to `:symbol:`mongoc_client_pool_pop`.
31+
32+
The passed in strings are copied, and don't have to remain valid after the
33+
call to :symbol:`mongoc_handshake_data_append`. The driver may store truncated
34+
versions of the passed in strings.
35+
36+
.. note::
37+
This function allocates memory, and therefore caution should be used when
38+
using this in conjunction with :symbol:`bson_mem_set_vtable`. If this function is
39+
called before :symbol:`bson_mem_set_vtable`, then :symbol:`bson_mem_restore_vtable` must be
40+
called before calling :symbol:`mongoc_cleanup`. Failure to do so will result in
41+
memory being freed by the wrong allocator.
42+
43+
Parameters
44+
----------
45+
46+
* ``driver_name``: An optional string storing the name of the wrapping driver
47+
* ``driver_version``: An optional string storing the version of the wrapping driver.
48+
* ``platform``: An optional string storing any information about the current platform, for example configure options or compile flags.
49+
50+
Returns
51+
-------
52+
53+
``true`` if the given fields are set successfully. Otherwise, it returns ``false`` and logs an error.
54+
55+
The default handshake data the driver sends with "hello" looks something
56+
like:
57+
58+
.. code-block:: c
59+
60+
client: {
61+
driver: {
62+
name: "mongoc",
63+
version: "1.5.0"
64+
},
65+
os: {...},
66+
platform: "CC=gcc CFLAGS=-Wall -pedantic"
67+
}
68+
69+
If we call
70+
:symbol:`mongoc_handshake_data_append` ("phongo", "1.1.8", "CC=clang / ")
71+
and it returns true, the driver sends handshake data like:
72+
73+
.. code-block:: c
74+
75+
client: {
76+
driver: {
77+
name: "mongoc / phongo",
78+
version: "1.5.0 / 1.1.8"
79+
},
80+
os: {...},
81+
platform: "CC=clang / gcc CFLAGS=-Wall -pedantic"
82+
}
83+
84+

src/libmongoc/src/mongoc/mongoc-handshake.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 MongoDB, Inc.
2+
* Copyright 2016-present MongoDB, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/libmongoc/src/mongoc/mongoc-handshake.h

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 MongoDB, Inc.
2+
* Copyright 2016-present MongoDB, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,64 +28,7 @@ BSON_BEGIN_DECLS
2828

2929
#define MONGOC_HANDSHAKE_APPNAME_MAX 128
3030

31-
/**
32-
* mongoc_handshake_data_append:
33-
*
34-
* This function is intended for use by drivers which wrap the C Driver.
35-
* Calling this function will store the given strings as handshake data about
36-
* the system and driver by appending them to the handshake data for the
37-
* underlying C Driver. These values, along with other handshake data collected
38-
* during mongoc_init will be sent to the server as part of the initial
39-
* connection handshake in the "client" document. This function cannot be
40-
* called more than once, or after a handshake has been initiated.
41-
*
42-
* The passed in strings are copied, and don't have to remain valid after the
43-
* call to mongoc_handshake_data_append(). The driver may store truncated
44-
* versions of the passed in strings.
45-
*
46-
* Note:
47-
* This function allocates memory, and therefore caution should be used when
48-
* using this in conjunction with bson_mem_set_vtable. If this function is
49-
* called before bson_mem_set_vtable, then bson_mem_restore_vtable must be
50-
* called before calling mongoc_cleanup. Failure to do so will result in
51-
* memory being freed by the wrong allocator.
52-
*
53-
*
54-
* @driver_name: An optional string storing the name of the wrapping driver
55-
* @driver_version: An optional string storing the version of the wrapping
56-
* driver.
57-
* @platform: An optional string storing any information about the current
58-
* platform, for example configure options or compile flags.
59-
*
60-
*
61-
* Returns true if the given fields are set successfully. Otherwise, it returns
62-
* false and logs an error.
63-
*
64-
* The default handshake data the driver sends with "hello" looks something
65-
* like:
66-
* client: {
67-
* driver: {
68-
* name: "mongoc",
69-
* version: "1.5.0"
70-
* },
71-
* os: {...},
72-
* platform: "CC=gcc CFLAGS=-Wall -pedantic"
73-
* }
74-
*
75-
* If we call
76-
* mongoc_handshake_data_append ("phongo", "1.1.8", "CC=clang")
77-
* and it returns true, the driver sends handshake data like:
78-
* client: {
79-
* driver: {
80-
* name: "mongoc / phongo",
81-
* version: "1.5.0 / 1.1.8"
82-
* },
83-
* os: {...},
84-
* platform: "CC=gcc CFLAGS=-Wall -pedantic / CC=clang"
85-
* }
86-
*
87-
*/
88-
MONGOC_EXPORT (bool)
31+
MONGOC_EXPORT (bool)
8932
mongoc_handshake_data_append (const char *driver_name,
9033
const char *driver_version,
9134
const char *platform);

src/libmongoc/tests/test-mongoc-handshake.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,7 @@ test_mongoc_handshake_race_condition (void)
818818
BSON_ASSERT (!COMMON_PREFIX (thread_create) (
819819
&threads[j], &handshake_append_worker, NULL));
820820
}
821-
822-
for (j = 0; j < 4; ++j) {
821+
for (j = 0; j < 4; ++j) {
823822
COMMON_PREFIX (thread_join) (threads[j]);
824823
}
825824
}

0 commit comments

Comments
 (0)