fix timeout in ZCS receiveMessage (#1264)
This commit is contained in:
parent
0b1fc7eb6a
commit
4dc7652aa2
@ -32,32 +32,27 @@ pub fn receiveMessage(client: *Client) !InMessage.Header {
|
||||
const Header = InMessage.Header;
|
||||
const fifo = client.pooler.fifo(.in);
|
||||
|
||||
while (try client.pooler.poll()) {
|
||||
var first_run = true;
|
||||
var header: ?Header = null;
|
||||
while (first_run or try client.pooler.poll()) {
|
||||
first_run = false;
|
||||
|
||||
if (header == null) {
|
||||
if (fifo.readableLength() < @sizeOf(Header)) continue;
|
||||
const buf = fifo.readableSlice(0);
|
||||
assert(fifo.readableLength() == buf.len);
|
||||
if (buf.len >= @sizeOf(Header)) {
|
||||
// workaround for https://github.com/ziglang/zig/issues/14904
|
||||
const bytes_len = bswap_and_workaround_u32(buf[4..][0..4]);
|
||||
const tag = bswap_and_workaround_tag(buf[0..][0..4]);
|
||||
|
||||
if (buf.len - @sizeOf(Header) >= bytes_len) {
|
||||
fifo.discard(@sizeOf(Header));
|
||||
return .{
|
||||
header = Header{
|
||||
.tag = tag,
|
||||
.bytes_len = bytes_len,
|
||||
};
|
||||
} else {
|
||||
const needed = bytes_len - (buf.len - @sizeOf(Header));
|
||||
const write_buffer = try fifo.writableWithSize(needed);
|
||||
const amt = try client.in.readAll(write_buffer);
|
||||
fifo.update(amt);
|
||||
continue;
|
||||
}
|
||||
fifo.discard(@sizeOf(Header));
|
||||
}
|
||||
|
||||
const write_buffer = try fifo.writableWithSize(256);
|
||||
const amt = try client.in.read(write_buffer);
|
||||
fifo.update(amt);
|
||||
if (header) |h| {
|
||||
if (fifo.readableLength() < h.bytes_len) continue;
|
||||
return h;
|
||||
}
|
||||
}
|
||||
return error.Timeout;
|
||||
}
|
||||
|
@ -236,12 +236,10 @@ pub fn translate(
|
||||
const body_size = @sizeOf(std.zig.Server.Message.EmitBinPath);
|
||||
if (header.bytes_len <= body_size) return error.InvalidResponse;
|
||||
|
||||
const trailing_size = header.bytes_len - body_size;
|
||||
|
||||
_ = try zcs.receiveEmitBinPath();
|
||||
|
||||
const result_path = try zcs.receiveBytes(allocator, trailing_size);
|
||||
defer allocator.free(result_path);
|
||||
const trailing_size = header.bytes_len - body_size;
|
||||
const result_path = zcs.pooler.fifo(.in).readableSliceOfLen(trailing_size);
|
||||
|
||||
return Result{ .success = try URI.fromPath(allocator, std.mem.sliceTo(result_path, '\n')) };
|
||||
},
|
||||
|
@ -9,9 +9,6 @@ const translate_c = zls.translate_c;
|
||||
const allocator: std.mem.Allocator = std.testing.allocator;
|
||||
|
||||
test "zig compile server - translate c" {
|
||||
// FIXME: Disabled due to https://github.com/zigtools/zls/issues/1252
|
||||
if (@import("builtin").os.tag == .windows) return error.SkipZigTest;
|
||||
|
||||
var result1 = try testTranslate(
|
||||
\\void foo(int);
|
||||
\\void bar(float*);
|
||||
|
Loading…
Reference in New Issue
Block a user