Skip to content

Commit

Permalink
Try closing writer
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba committed Sep 27, 2023
1 parent ffc4a3e commit a3f736e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/Compute/Fastly/FastlyBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ extension Fastly {
try wasi(fastly_http_body__close(handle))
}

public mutating func abandon() throws {
try wasi(fastly_http_body__abandon(handle))
}

@discardableResult
public mutating func write(_ bytes: [UInt8], location: BodyWriteEnd = .back) throws -> Int {
defer { used = true }
Expand Down
5 changes: 4 additions & 1 deletion Sources/Compute/Fastly/FastlyCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension Fastly {
let state = try trx.getState()

// If state is usable then return the body from cache
if state.contains(.usable) {
guard state.contains(.mustInsertOrUpdate) else {
return trx
}

Expand All @@ -37,6 +37,9 @@ extension Fastly {
try writer.body.write(bytes)
}

// Finish the body
try writer.body.close()

return writer.transaction
} catch {
// Cancel the transaction if something went wrong
Expand Down
2 changes: 2 additions & 0 deletions Sources/Compute/Fastly/FastlyStubs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func fastly_http_body__append(_ dest: WasiHandle, _ src: WasiHandle) -> Int32 {

func fastly_http_body__close(_ handle: WasiHandle) -> Int32 { fatalError() }

func fastly_http_body__abandon(_ handle: WasiHandle) -> Int32 { fatalError() }

func fastly_http_body__write(_ handle: WasiHandle, _ data: UnsafePointer<UInt8>!, _ data_len: Int, _ body_end: Int32, _ nwritten: UnsafeMutablePointer<Int>!) -> Int32 { fatalError() }

func fastly_http_body__read(_ handle: WasiHandle, _ data: UnsafeMutablePointer<UInt8>!, _ data_max_len: Int, _ nwritten: UnsafeMutablePointer<Int>!) -> Int32 { fatalError() }
Expand Down
3 changes: 3 additions & 0 deletions Sources/ComputeRuntime/include/ComputeRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ int fastly_http_body__append(WasiHandle dest, WasiHandle src);
WASM_IMPORT("fastly_http_body", "close")
int fastly_http_body__close(WasiHandle handle);

WASM_IMPORT("fastly_http_body", "abandon")
int fastly_http_body__abandon(WasiHandle handle);

WASM_IMPORT("fastly_http_body", "write")
int fastly_http_body__write(WasiHandle handle, const uint8_t* data, size_t data_len, int body_end, size_t* nwritten);

Expand Down

0 comments on commit a3f736e

Please sign in to comment.