Skip to content

Commit 3481983

Browse files
README updates. (#4)
* README updates.
1 parent d129ce5 commit 3481983

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

README.md

+94
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,100 @@
22

33
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
44

5+
### Currently Included:
6+
7+
* aws-c-common: Cross-platform primitives and data structures.
8+
* aws-c-io: Cross-platform event-loops, non-blocking I/O, and TLS implementations.
9+
* aws-c-mqtt: MQTT client.
10+
11+
More protocols and utilities are coming soon, so stay tuned.
12+
13+
## Building
14+
15+
The C99 libraries are already included for your convenience when you specify the `-DBUILD_DEPS=ON` CMake argument.
16+
17+
If you want to manage these dependencies manually (e.g. you're using them in other projects), simply specify
18+
`-DCMAKE_INSTALL_PREFIX` to point to the directory where you have them installed.
19+
20+
## Dependencies?
21+
22+
### Windows and Apple
23+
There are no non-OS dependencies that AWS does not own, maintain, and ship.
24+
25+
### Unix
26+
The most likely answer is: none that you should care about.
27+
28+
We do depend on an openssl compatible libcrypto implementation being in your path if you are on a
29+
unix system. Note: we do not actually use libssl. The most likely scenario is that libcrypto is already installed on your system. However, since
30+
many linux distributions these days do not provide a 32-bit libcrypto package, if you're trying to perform a 32-bit build you will
31+
likely need to build and install libcrypto from source.
32+
33+
## Common Usage
34+
35+
To do anything with IO, you'll need to create a few objects that will be used by the rest of the library.
36+
37+
For example:
38+
39+
````
40+
Aws::Crt::LoadErrorStrings();
41+
````
42+
43+
Will load error strings for debugging purposes. Since the C libraries use error codes, this will allow you to print the corresponding
44+
error string for each error code.
45+
46+
````
47+
Aws::Crt::ApiHandle apiHandle;
48+
````
49+
This performs one-time static initialization of the library. You'll need it to do anything, so don't forget to create one.
50+
51+
````
52+
Aws::Crt::Io::EventLoopGroup eventLoopGroup(<number of threads you want>);
53+
````
54+
To use any of our APIs that perform IO you'll need at least one event-loop. An event-loop group is a collection of event-loops that
55+
protocol implementations will load balance across. If you won't have very many connections (say, more than 100 or so), then you
56+
most likely only want 1 thread. In this case, you want to pass a single instance of this to every client or server implementation of a protocol
57+
you use in your application. In some advanced use cases, you may want to reserve a thread for different types of IO tasks. In that case, you can have an
58+
instance of this class for each reservation.
59+
60+
````
61+
Aws::Crt::Io::TlsContextOptions tlsCtxOptions =
62+
Aws::Crt::Io::TlsContextOptions::InitClientWithMtls(certificatePath.c_str(), keyPath.c_str());
63+
/*
64+
* If we have a custom CA, set that up here.
65+
*/
66+
if (!caFile.empty())
67+
{
68+
tlsCtxOptions.OverrideDefaultTrustStore(nullptr, caFile.c_str());
69+
}
70+
71+
uint16_t port = 8883;
72+
if (Io::TlsContextOptions::IsAlpnSupported())
73+
{
74+
/*
75+
* Use ALPN to negotiate the mqtt protocol on a normal
76+
* TLS port if possible.
77+
*/
78+
tlsCtxOptions.SetAlpnList("x-amzn-mqtt-ca");
79+
port = 443;
80+
}
81+
82+
Aws::Crt::Io::TlsContext tlsCtx(tlsCtxOptions, Io::TlsMode::CLIENT);
83+
````
84+
85+
If you plan on using TLS, you will need a TlsContext. These are NOT CHEAP, so use as few as possible to perform your task.
86+
If you're in client mode and not doing anything fancy (e.g. mutual TLS), then you can likely get away with using a single
87+
instance for the entire application.
88+
89+
````
90+
Aws::Crt::Io::ClientBootstrap bootstrap(eventLoopGroup);
91+
````
92+
93+
Lastly, you will need a client or server bootstrap to use a client or server protocol implementation. Since everything is
94+
non-blocking and event driven, this handles most of the "callback hell" inherent in the design. Assuming you aren't partitioning
95+
threads for particular use-cases, you can have a single instance of this that you pass to multiple clients.
96+
97+
For a working Mqtt example, see samples/mqtt_pub_sub/main.cpp.
98+
599
## License
6100

7101
This library is licensed under the Apache 2.0 License.

0 commit comments

Comments
 (0)