Skip to content

Commit

Permalink
connection: deinit it when done
Browse files Browse the repository at this point in the history
  • Loading branch information
vrischmann committed May 30, 2024
1 parent 7ca92c5 commit 790347d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions examples/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,13 @@ pub fn main() anyerror!void {
std.process.exit(1);
}

//
// Connect to the seed node
//

// Define the seed node we will connect to. We use localhost:9042.
const address = net.Address.initIp4([_]u8{ 127, 0, 0, 1 }, 9042);

// Connect to the seed node
//
// The struct InitOptions can be used to control some aspects of the CQL client,
// such as the protocol version, if compression is enabled, etc.

Expand Down Expand Up @@ -362,7 +364,11 @@ pub fn main() anyerror!void {
},
else => return err,
};
defer connection.close();
defer connection.deinit();

//
// Connection established, create the client and do the thing.
//

var client = cassandra.Client.initWithConnection(allocator, &connection, .{});
defer client.deinit();
Expand Down
3 changes: 2 additions & 1 deletion src/connection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ pub const Connection = struct {
try self.handshake(diags);
}

pub fn close(self: *Self) void {
pub fn deinit(self: *Self) void {
self.socket.close();
self.message_writer.deinit();
}

fn handshake(self: *Self, diags: *InitOptions.Diagnostics) !void {
Expand Down

0 comments on commit 790347d

Please sign in to comment.