mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-20 16:24:50 +00:00
Fix issue returning stack pointer
This commit is contained in:
@@ -124,10 +124,13 @@ fn randomPort() u16 {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sendInitialConnection(payload: []const u8, initial_port: u16) !*SaprusMessage {
|
pub fn sendInitialConnection(
|
||||||
|
payload: []const u8,
|
||||||
|
output_bytes: []align(@alignOf(SaprusMessage)) u8,
|
||||||
|
initial_port: u16,
|
||||||
|
) !*SaprusMessage {
|
||||||
const dest_port = randomPort();
|
const dest_port = randomPort();
|
||||||
var buf: [max_message_size]u8 align(@alignOf(SaprusMessage)) = undefined;
|
const msg_bytes = output_bytes[0..try SaprusMessage.calcSize(
|
||||||
const msg_bytes = buf[0..try SaprusMessage.calcSize(
|
|
||||||
.connection,
|
.connection,
|
||||||
base64Enc.calcSize(payload.len),
|
base64Enc.calcSize(payload.len),
|
||||||
)];
|
)];
|
||||||
@@ -161,13 +164,13 @@ pub fn connect(payload: []const u8) !?SaprusConnection {
|
|||||||
try sock.setReadTimeout(1 * std.time.us_per_s);
|
try sock.setReadTimeout(1 * std.time.us_per_s);
|
||||||
try sock.bind(bind_addr);
|
try sock.bind(bind_addr);
|
||||||
|
|
||||||
const msg = try sendInitialConnection(payload, initial_port);
|
var sent_msg_bytes: [max_message_size]u8 align(@alignOf(SaprusMessage)) = undefined;
|
||||||
|
const msg = try sendInitialConnection(payload, &sent_msg_bytes, initial_port);
|
||||||
|
|
||||||
var response_buf: [max_message_size]u8 align(@alignOf(SaprusMessage)) = undefined;
|
var response_buf: [max_message_size]u8 align(@alignOf(SaprusMessage)) = undefined;
|
||||||
_ = try sock.receive(&response_buf); // Ignore message that I sent.
|
_ = try sock.receive(&response_buf); // Ignore message that I sent.
|
||||||
const len = try sock.receive(&response_buf);
|
const len = try sock.receive(&response_buf);
|
||||||
|
|
||||||
std.debug.print("response bytes: {x}\n", .{response_buf[0..len]});
|
|
||||||
initial_conn_res = try .networkBytesAsValue(response_buf[0..len]);
|
initial_conn_res = try .networkBytesAsValue(response_buf[0..len]);
|
||||||
|
|
||||||
// Complete handshake after awaiting response
|
// Complete handshake after awaiting response
|
||||||
|
|||||||
Reference in New Issue
Block a user