Mojo · Files and Streams

Files and Streams

from ucall import FileRange, ReplyStream 1.0.0-rc.1 · 60202332

request^.detach() hands the request to a DetachedRequest, which reads the same way, moves to any thread, and answers 500 when dropped unreplied. It alone offers the replies that may finish later:

var detached = request^.detach()
var parts = [ReplyPart.bytes(header), ReplyPart.bytes(payload)]
if case .Some(deferred) = detached^.reply_parts(HTTPStatus.OK, no_headers, parts):
    deferred^.wait()  # off the polling thread, which is the one sending the file parts

var stream = other^.reply_stream(HTTPStatus.OK, no_headers)
stream.append(parts)
_ = stream^.end()  # Optional[Deferred] while file or path parts still send

body_chunk pulls a streamed body, waiting for the next bytes; on a buffered route the first pull is the whole body. A Deferred reads DEFERRED from status until the reply is final, and wait blocks through ucall_outcome_wait and raises the reply’s failure. Dropping an unfinished Deferred waits for it.

API

StructFileRangeA byte range of a regular file the caller opened with O_DIRECT, ucall_file_range_t in C.
struct FileRange

Fields

file_descriptorc_intThe open file, borrowed and never closed by UCall, until the reply is final.
offsetUInt64The range's first byte.
lengthUInt64The range's byte count; zero sends through the end of the file.

Conforms to

Copyable, Deinitable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable
StructReplyStreamA reply whose head left and whose body is appended part by part, from one thread at a time, until end; dropping it ends it, waiting for its file parts to send.4
struct ReplyStream

Conforms to

Deinitable, Movable
__init__
def __init__(out self, var shared: ArcPointer[_ServerCore], request: Int)
__deinit__Ends the body, waiting for its file parts. Calls ucall_server_reply_end.
def __deinit__(deinit self)
appendQueues parts on the body together, or none of them. Calls ucall_server_reply_append.
def append[origin: ImmOrigin](self, parts: Span[ReplyPart[origin]])

Raises

Error with WOULD_BLOCK, queueing nothing, while the peer lags behind the parts already queued; retry once it catches up.
endEnds the body, consuming the request whatever the outcome. Calls ucall_server_reply_end.
def end(deinit self) -> Optional[Deferred]

Returns

None once final, and a Deferred while file or path parts still send.

Raises

Error with MALFORMED for a body short of its declared Content-Length.