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 Header = InMessage.Header;
|
||||||
const fifo = client.pooler.fifo(.in);
|
const fifo = client.pooler.fifo(.in);
|
||||||
|
|
||||||
while (try client.pooler.poll()) {
|
var first_run = true;
|
||||||
const buf = fifo.readableSlice(0);
|
var header: ?Header = null;
|
||||||
assert(fifo.readableLength() == buf.len);
|
while (first_run or try client.pooler.poll()) {
|
||||||
if (buf.len >= @sizeOf(Header)) {
|
first_run = false;
|
||||||
// workaround for https://github.com/ziglang/zig/issues/14904
|
|
||||||
|
if (header == null) {
|
||||||
|
if (fifo.readableLength() < @sizeOf(Header)) continue;
|
||||||
|
const buf = fifo.readableSlice(0);
|
||||||
const bytes_len = bswap_and_workaround_u32(buf[4..][0..4]);
|
const bytes_len = bswap_and_workaround_u32(buf[4..][0..4]);
|
||||||
const tag = bswap_and_workaround_tag(buf[0..][0..4]);
|
const tag = bswap_and_workaround_tag(buf[0..][0..4]);
|
||||||
|
header = Header{
|
||||||
if (buf.len - @sizeOf(Header) >= bytes_len) {
|
.tag = tag,
|
||||||
fifo.discard(@sizeOf(Header));
|
.bytes_len = bytes_len,
|
||||||
return .{
|
};
|
||||||
.tag = tag,
|
fifo.discard(@sizeOf(Header));
|
||||||
.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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const write_buffer = try fifo.writableWithSize(256);
|
if (header) |h| {
|
||||||
const amt = try client.in.read(write_buffer);
|
if (fifo.readableLength() < h.bytes_len) continue;
|
||||||
fifo.update(amt);
|
return h;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return error.Timeout;
|
return error.Timeout;
|
||||||
}
|
}
|
||||||
|
@ -236,12 +236,10 @@ pub fn translate(
|
|||||||
const body_size = @sizeOf(std.zig.Server.Message.EmitBinPath);
|
const body_size = @sizeOf(std.zig.Server.Message.EmitBinPath);
|
||||||
if (header.bytes_len <= body_size) return error.InvalidResponse;
|
if (header.bytes_len <= body_size) return error.InvalidResponse;
|
||||||
|
|
||||||
const trailing_size = header.bytes_len - body_size;
|
|
||||||
|
|
||||||
_ = try zcs.receiveEmitBinPath();
|
_ = try zcs.receiveEmitBinPath();
|
||||||
|
|
||||||
const result_path = try zcs.receiveBytes(allocator, trailing_size);
|
const trailing_size = header.bytes_len - body_size;
|
||||||
defer allocator.free(result_path);
|
const result_path = zcs.pooler.fifo(.in).readableSliceOfLen(trailing_size);
|
||||||
|
|
||||||
return Result{ .success = try URI.fromPath(allocator, std.mem.sliceTo(result_path, '\n')) };
|
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;
|
const allocator: std.mem.Allocator = std.testing.allocator;
|
||||||
|
|
||||||
test "zig compile server - translate c" {
|
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(
|
var result1 = try testTranslate(
|
||||||
\\void foo(int);
|
\\void foo(int);
|
||||||
\\void bar(float*);
|
\\void bar(float*);
|
||||||
|
Loading…
Reference in New Issue
Block a user