mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
libuv: stream try_write
This commit is contained in:
@ -127,6 +127,13 @@ test "Pipe" {
|
||||
// Check our data
|
||||
try testing.expectEqual(@as(usize, 5), data.data.items.len);
|
||||
try testing.expectEqualStrings("hello", data.data.items);
|
||||
data.data.clearRetainingCapacity();
|
||||
|
||||
// Try writing directly
|
||||
_ = try writer.tryWrite(&[_][]const u8{"world"});
|
||||
_ = try loop.run(.once);
|
||||
try testing.expectEqual(@as(usize, 5), data.data.items.len);
|
||||
try testing.expectEqualStrings("world", data.data.items);
|
||||
|
||||
// End
|
||||
reader.readStop();
|
||||
|
@ -63,6 +63,18 @@ pub fn Stream(comptime T: type) type {
|
||||
));
|
||||
}
|
||||
|
||||
/// Same as uv_write(), but won’t queue a write request if it can’t
|
||||
/// be completed immediately.
|
||||
pub fn tryWrite(self: T, bufs: []const []const u8) !usize {
|
||||
const res = c.uv_try_write(
|
||||
@ptrCast(*c.uv_stream_t, self.handle),
|
||||
@ptrCast([*c]const c.uv_buf_t, bufs.ptr),
|
||||
@intCast(c_uint, bufs.len),
|
||||
);
|
||||
try errors.convertError(res);
|
||||
return @intCast(usize, res);
|
||||
}
|
||||
|
||||
/// Read data from an incoming stream. The uv_read_cb callback will
|
||||
/// be made several times until there is no more data to read or
|
||||
/// uv_read_stop() is called.
|
||||
|
Reference in New Issue
Block a user