Zig
Zig
Duplicate a Socket Wrapper Sharing the Connection
See more Socket/SSL/TLS Examples
Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.
Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const socket = try chilkat.Socket.init();
defer socket.deinit();
// Connect to the server using TLS.
const b_tls = true;
const max_wait_ms = 5000;
socket.connect("example.com", 5000, b_tls, max_wait_ms) catch {
std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
return;
};
// Create a second Socket wrapper that shares this object's underlying connection. Both wrappers
// operate on the same live connection; the shared connection is reference-counted.
const dup_sock = try chilkat.Socket.init();
defer dup_sock.deinit();
socket.dupSocket(dup_sock) catch {
std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
return;
};
std.debug.print("Duplicate socket wrapper created.\n", .{});
}