@@ -16,7 +16,7 @@ As an example, a *handle* should be initialized before any other operation and c
1616
1717## Code Example
1818
19- ```
19+ ``` cpp
2020#include < uvw.hpp>
2121#include < memory>
2222
@@ -86,7 +86,9 @@ Because of that, users have not to install it to compile and execute the tests.
8686This means that including the `uvw.hpp` header or one of the other `uvw/*.hpp` headers is enough to use it.<br/>
8787It's a matter of adding the following line at the top of a file:
8888
89- #include <uvw.hpp>
89+ ```cpp
90+ #include <uvw.hpp>
91+ ```
9092
9193Then pass the proper ` -I ` argument to the compiler to add the ` src ` directory to the include paths.<br />
9294Note that users are demanded to correctly setup include directories and libraries search paths for * libuv* .
@@ -154,49 +156,65 @@ Therefore the rule quickly becomes *feel free to make a request and forget about
154156
155157The first thing to do to use ` uvw ` is to create a loop. In case the default one is enough, it's easy as doing this:
156158
157- auto loop = uvw::Loop::getDefault();
159+ ``` cpp
160+ auto loop = uvw::Loop::getDefault();
161+ ```
158162
159163Note that loop objects don't require to be closed explicitly, even if they offer the ` close ` member function in case an user wants to do that.<br />
160164Loops can be started using the ` run ` member function. The two calls below are equivalent:
161165
162- loop->run();
163- loop->run<uvw::Loop::Mode::DEFAULT>
166+ ``` cpp
167+ loop->run ();
168+ loop->run<uvw::Loop::Mode::DEFAULT>
169+ ```
164170
165171Available modes are: ` DEFAULT ` , ` ONCE ` , ` NOWAIT ` . Please refer to the documentation of * libuv* for further details.
166172
167173In order to create a resource and to bind it to the given loop, just do the following:
168174
169- auto tcp = loop.resource<uvw::TcpHandle>();
175+ ``` cpp
176+ auto tcp = loop.resource<uvw::TcpHandle>();
177+ ```
170178
171179The line above will create and initialize a tcp handle, then a shared pointer to that resource will be returned.<br />
172180Users should check if pointers have been correctly initialized: in case of errors, they won't be.<br />
173181Another way to create a resource is:
174182
175- auto tcp = TcpHandle::create(loop);
176- tcp->init();
183+ ``` cpp
184+ auto tcp = TcpHandle::create(loop);
185+ tcp->init ();
186+ ```
177187
178188Pretty annoying indeed. Using a loop is the recommended approach.
179189
180190The resources also accept arbitrary user-data that won't be touched in any case.<br />
181191Users can set and get them through the ` data ` member function as it follows:
182192
183- resource->data(std::make_shared<int>(42));
184- std::shared_ptr<void> data = resource->data();
193+ ``` cpp
194+ resource->data (std::make_shared<int >(42));
195+ std::shared_ptr<void > data = resource->data();
196+ ```
185197
186198Resources expect a `std::shared_pointer<void>` and return it, therefore any kind of data is welcome.<br/>
187199Users can explicitly specify a type other than `void` when calling the `data` member function:
188200
189- std::shared_ptr<int> data = resource->data<int>();
201+ ```cpp
202+ std::shared_ptr<int> data = resource->data<int>();
203+ ```
190204
191205Remember from the previous section that a handle will keep itself alive until one invokes the ` close ` member function on it.<br />
192206To know what are the handles that are still alive and bound to a given loop, just do the following:
193207
194- loop.walk([](uvw::BaseHandle &){ /* application code here */ });
208+ ``` cpp
209+ loop.walk([](uvw::BaseHandle &){ /* application code here * / });
210+ ```
195211
196212`BaseHandle` exposes a few methods and cannot be used to know the original type of the handle.<br/>
197213Anyway, it can be used to close the handle that originated from it. As an example, all the pending handles can be closed easily as it follows:
198214
199- loop.walk([](uvw::BaseHandle &h){ h.close(); });
215+ ```cpp
216+ loop.walk([](uvw::BaseHandle &h){ h.close(); });
217+ ```
200218
201219No need to keep track of them.
202220
@@ -234,7 +252,7 @@ All the other events are specific for the given resource and documented in the A
234252
235253The code below shows how to create a simple tcp server using ` uvw ` :
236254
237- ```
255+ ``` cpp
238256auto loop = uvw::Loop::getDefault();
239257auto tcp = loop.resource<uvw::TcpHandle>();
240258
0 commit comments