-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tutorial: Simple Connection #2
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
261e477
Tweak style of code blocks
vector-of-bool a0cf807
Add convenience overload of then/let
vector-of-bool 10665f7
Fix more generic signatures for BSON views and values
vector-of-bool d3eeadf
Support and simplify many more generic function signatures
vector-of-bool 4420d49
Tweak defs of some BSON generic functions to cast-to-view first
vector-of-bool 2b6d549
Add compile-time tests for our generic function signatures
vector-of-bool 089f715
Rename the "connect" how-to to "communicate"
vector-of-bool 9083209
detach_start() convenience API
vector-of-bool d2669b3
Allow omitting alloc arg in detach()
vector-of-bool 4415f13
Write a "connect" tutorial
vector-of-bool 7ab2a0c
More doc words to highlight
vector-of-bool 920e430
Remove guideline: Never add ctors to C types
vector-of-bool 4d5ff0e
Support handlers from allocator-carrying funcs
vector-of-bool 1695ba2
Don't enable message tracing by default
vector-of-bool File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -6,5 +6,5 @@ How-to Guides | |
:caption: Guides | ||
:maxdepth: 2 | ||
|
||
connect | ||
communicate | ||
looping |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <amongoc/amongoc.h> // Make all APIs visible | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
// end:headers | ||
|
||
amongoc_box on_connect(amongoc_box userdata, amongoc_status* status, amongoc_box result); | ||
|
||
int main(void) { | ||
amongoc_loop loop; | ||
amongoc_default_loop_init(&loop); | ||
|
||
// Initiate a connection | ||
amongoc_emitter em = amongoc_client_new(&loop, "mongodb://localhost:27017"); | ||
// Set the continuation | ||
em = amongoc_then(em, &on_connect); | ||
// Run the program | ||
amongoc_detach_start(em); | ||
amongoc_default_loop_run(&loop); | ||
// Clean up | ||
amongoc_default_loop_destroy(&loop); | ||
return 0; | ||
} | ||
|
||
// on_connect def | ||
amongoc_box on_connect(amongoc_box userdata, amongoc_status* status, amongoc_box result) { | ||
// We don't use the userdata | ||
(void)userdata; | ||
// Check for an error | ||
if (amongoc_is_error(*status)) { | ||
char* msg = amongoc_status_strdup_message(*status); | ||
fprintf(stderr, "Error while connecting to server: %s\n", msg); | ||
free(msg); | ||
} else { | ||
printf("Successfully connected!\n"); | ||
amongoc_client* client; | ||
amongoc_box_take(client, result); | ||
// `cl` now stores a valid client. We don't do anything else, so just delete it: | ||
amongoc_client_delete(client); | ||
} | ||
amongoc_box_destroy(result); | ||
return amongoc_nil; | ||
} | ||
// on_connect end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest disabling the default enabled tracing. This example currently prints the full OPMSG sent and received:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how that got in. Oop.