mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
libuv: expose WriteReq
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
const stream = @import("stream.zig");
|
||||
|
||||
pub const Loop = @import("Loop.zig");
|
||||
pub const Async = @import("Async.zig");
|
||||
pub const Pipe = @import("Pipe.zig");
|
||||
@ -6,12 +8,13 @@ pub const Tty = @import("Tty.zig");
|
||||
pub const Sem = @import("Sem.zig");
|
||||
pub const Thread = @import("Thread.zig");
|
||||
pub const Error = @import("error.zig").Error;
|
||||
pub const WriteReq = stream.WriteReq;
|
||||
|
||||
pub const Embed = @import("Embed.zig");
|
||||
|
||||
test {
|
||||
_ = @import("stream.zig");
|
||||
_ = @import("tests.zig");
|
||||
_ = stream;
|
||||
|
||||
_ = Loop;
|
||||
_ = Async;
|
||||
|
@ -142,7 +142,11 @@ pub fn Stream(comptime T: type) type {
|
||||
/// behaviour. It is safe to reuse the uv_write_t object only after the
|
||||
/// callback passed to uv_write is fired.
|
||||
pub const WriteReq = struct {
|
||||
req: *c.uv_write_t,
|
||||
/// This is the underlying type that WriteReq wraps. This is exposed
|
||||
/// so that you can pre-allocate the type and wrap it in a WrapReq.
|
||||
pub const T = c.uv_write_t;
|
||||
|
||||
req: *T,
|
||||
|
||||
pub fn init(alloc: Allocator) !WriteReq {
|
||||
var req = try alloc.create(c.uv_write_t);
|
||||
@ -157,12 +161,12 @@ pub const WriteReq = struct {
|
||||
|
||||
/// Pointer to the stream where this write request is running.
|
||||
/// T should be a high-level handle type such as "Pipe".
|
||||
pub fn handle(self: WriteReq, comptime T: type) ?T {
|
||||
const tInfo = @typeInfo(T).Struct;
|
||||
pub fn handle(self: WriteReq, comptime HT: type) ?HT {
|
||||
const tInfo = @typeInfo(HT).Struct;
|
||||
const HandleType = tInfo.fields[0].field_type;
|
||||
|
||||
return if (self.req.handle) |ptr|
|
||||
return T{ .handle = @ptrCast(HandleType, ptr) }
|
||||
return HT{ .handle = @ptrCast(HandleType, ptr) }
|
||||
else
|
||||
null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user