Libasync tutorial



This tutorial demonstrates the use of libasync through simple and less simple examples. For a thorough discussion of all the nuts and bolts in libasync (and more examples), consult Using libasync.

Roughly, libasync allows you to respond to events (usually on file descriptors) through callbacks. A callback is just a C/C++ function or method. The programmer defines what callback is associated with which event and libasync invokes that callback function when the event occurs.

There are many examples in this tutorial. All files are available in the examples/ directory. Also, you can click on the filename above each example.

Lesson index

This is a summary of the wisdom that awaits you.

Lesson 1: Hello, World!
Simple callback example using delaycb and wrap.

Lesson 2: Callbacks with parameters
Passing parameters to callback functions.

Lesson 3: Callbacks as parameters
Introduces the callback<...> type, explains how to pass callback functions as parameters to callback functions, and demonstrates how to pass parameters to callback functions that are passed as parameters to callback funtions. Did I make myself clear at all?

Lesson 4: Gory details: strbuf, ptr, and ref
Nasty details you need to know related to garbage collection.

Lesson 5: Client sockets
How to create a client socket (using tcpconnect) and how to read/write from/to that socket.

Lesson 6: Server sockets
How to create a server socket (using inetsocket) and how to read/write from/to that socket.

Ready, set...

GO! ( Lesson 1)

Back to main.