chore: refactor

This commit is contained in:
2025-05-22 15:39:29 +02:00
parent d92ee9c10c
commit fb1059e378
2 changed files with 39 additions and 32 deletions

View File

@@ -37,7 +37,12 @@ pub const HttpHeader = struct {
value: []const u8, value: []const u8,
}; };
pub const HttpContext = struct { client: *const Client, request: *const HttpRequest, response: ?*const HttpResponse = null, finished: bool = false }; pub const HttpContext = struct {
client: *const Client,
request: *const HttpRequest,
response: ?*const HttpResponse = null,
finished: bool = false,
};
fn tcp_recv_callback(context: ?*anyopaque, pcb: ?*cNet.tcp_pcb, p1: ?*cNet.pbuf, _: cNet.err_t) callconv(.C) cNet.err_t { fn tcp_recv_callback(context: ?*anyopaque, pcb: ?*cNet.tcp_pcb, p1: ?*cNet.pbuf, _: cNet.err_t) callconv(.C) cNet.err_t {
if (p1 == null) { if (p1 == null) {
@@ -164,7 +169,9 @@ pub const Client = struct {
print("Client.sendRequest"); print("Client.sendRequest");
var context: HttpContext = .{ .client = client, .request = request }; var context: HttpContext = .{ .client = client, .request = request };
{
cNet.cyw43_arch_lwip_begin(); cNet.cyw43_arch_lwip_begin();
defer cNet.cyw43_arch_lwip_end();
var cached_address = cNet.ip_addr_t{}; var cached_address = cNet.ip_addr_t{};
const host = if (request.url.host) |host| host else unreachable; const host = if (request.url.host) |host| host else unreachable;
@@ -197,7 +204,8 @@ pub const Client = struct {
} }
print("Calling cyw43_arch_lwip_end"); print("Calling cyw43_arch_lwip_end");
cNet.cyw43_arch_lwip_end(); }
print("Ending sendRequest..."); print("Ending sendRequest...");
while (!context.finished) { while (!context.finished) {

View File

@@ -40,7 +40,6 @@ const appSettings: AppSettings = x: {
}; };
}; };
// Basically the pico_w blink sample
export fn main() c_int { export fn main() c_int {
_ = p.stdio_init_all(); _ = p.stdio_init_all();
p.sleep_ms(2000); p.sleep_ms(2000);