Example Programs
Every example is one source file and is built and tested with this release.
Building and Running
Object database
TLS networking
General support
Plain text diagnostics
Building and Running
The examples are in the examples folder and are built with the library by CMake:
cmake -S . -B cmake-build -DCMAKE_BUILD_TYPE=Release cmake --build cmake-build -j cmake-build/examples/db_infohog # Linux cmake-build\examples\Release\db_infohog # Windows
The database examples pause for Enter between steps; give them empty input (< /dev/null or < nul) to run straight through. The TLS servers need a certificate and key; see Certificates for making test ones. tests/run_tests.sh builds everything and runs the examples against each other and against mock mail and FTPS servers.
Object database
examples/database/simple/testprog.cppdb_simple: gxDatabase basics: create a file, allocate, write, read and delete blocks, file statistics.
examples/database/database/testprog.cppdb_database: Store and find fixed-size objects in a gxDatabase file.
examples/database/btree/testprog.cppdb_btree: gxBtree index with a custom key class: insert, find, walk in order, delete.
examples/database/btree_cached/testprog.cppdb_btree_cached: The same B-tree operations through a BtreeCache.
examples/database/btree_node/testprog.cppdb_btree_node: Inside a B-tree node: key layout and branches.
examples/database/database_cache/testprog.cppdb_database_cache: gxDatabaseCache write-back cache over a database file.
examples/database/defrag/testprog.cppdb_defrag: Free-space reuse and rebuilding (defragmenting) a database file.
examples/database/pod/testprog.cppdb_pod: POD: a data file with one or several index files opened together.
examples/database/infohog/infohog.cppdb_infohog: InfoHog object database: records with a key and variable members, add, find, change, delete, list and reopen.
examples/database/rdbms/rdbms.cppdb_rdbms: gxRDBMS relational table: primary and secondary keys, find, change, search and a sorted listing.
TLS networking
examples/tls/tls_echo_server.cpptls_echo_server: TLS server using gxsTLSServer and a ThreadPool. Usage: tls_echo_server port cert.pem key.pem
examples/tls/tls_echo_client.cpptls_echo_client: TLS client with certificate checking. Usage: tls_echo_client host port [--ca ca.pem] [--insecure]
examples/tls/https_get.cpphttps_get: Fetch a URL or download a file with gxsHTTPClient. Usage: https_get url [file] [--ca ca.pem]
examples/tls/https_server.cpphttps_server: Small HTTPS file server built on gxsHTTPReadRequest() and gxsHTTPWriteResponse().
examples/tls/smtp_send.cppsmtp_send: Send mail over implicit TLS or STARTTLS.
examples/tls/pop3_list.cpppop3_list: List and read a POP3 mailbox over TLS.
examples/tls/ftps_client.cppftps_client: List, download and upload with FTPS.
examples/tls/stream_server.cppstream_server: gxStream server that stores client blocks in a gxDatabase file.
examples/tls/stream_client.cppstream_client: gxStream client that stores and reads back blocks over TLS.
General support
examples/general/config_file.cppconfig_file: gxConfig: write, read and change a configuration file.
examples/general/logfile.cpplogfile: LogFile shared by several threads.
examples/general/thread_pool.cppthread_pool: ThreadPool tasks, results and exceptions.
Plain text diagnostics
examples/diagnostics/ping.cppping: ICMP and ICMPv6 echo. Usage: ping host [count] [-4|-6]
examples/diagnostics/telnet_client.cpptelnet_client: Telnet login and command (plain text; trusted networks only).