net_fetch.h
The engine's HTTPS fetch service. A get runs on its own thread, never blocks a frame, and can wake the app when it lands.
#include "isolenui/platform/net_fetch.h". The guide starts at Fetching over the network.
Options and results
Explained in Fetching over the network.
net_errornet_oknet_bad_urlnet_insecurenet_offlinenet_timeoutnet_too_bignet_httpnet_tlsnet_cancellednet_no_memorynet_failednet_optsnet_resultnet_fetchFetching
Explained in Fetching over the network.
net_opts_ofnet_getnet_pollnet_takenet_dropnet_error_textExample
feed.cpp
#include "isolenui/app/app.h"
#include "isolenui/platform/net_fetch.h"
#include "isolenui/ui/ui.h"
#include "isolenui/kit/kit.h"
#include <stdio.h>
#include <stdlib.h>
struct feed {
net_fetch* get;
uint8_t* bytes;
size_t size;
char why[96];
};
// runs on the fetch thread, so it only asks the app for a frame
static void feed_wake(void* user)
{
isolen_wake(static_cast<isolen_app*>(user));
}
static void feed_start(isolen_app* a, feed* f)
{
net_opts o = net_opts_of();
o.max_bytes = 4ull << 20;
o.timeout_ms = 10000u;
o.wake = feed_wake;
o.user = a;
f->get = net_get("https://example.com/schedule.json", &o);
}
// polled from the view, the result is stable until the drop
static void feed_poll(feed* f)
{
const net_result* r = net_poll(f->get);
if (!r) {
return;
}
if (r->error == net_ok) {
f->bytes = net_take(f->get, &f->size);
} else {
snprintf(f->why, sizeof(f->why), "%s", r->why);
}
net_drop(f->get);
f->get = nullptr;
}
static void feed_view(ui::ctx* u, feed* f)
{
if (f->get) {
feed_poll(f);
}
if (f->get) {
ui::spinner(u, 20.0f);
} else if (f->bytes) {
ui::textf(u, ui::caption(u), "%zu bytes", f->size);
} else {
ui::text(u, f->why, ui::caption(u));
}
}
// a drop cancels a get still in flight and no wake runs after it
static void feed_close(feed* f)
{
net_drop(f->get);
free(f->bytes);
*f = {};
}