Skip to content

Commit b0ff325

Browse files
server: move to TCP conn
Signed-off-by: Francis Bouvier <[email protected]>
1 parent c35c09d commit b0ff325

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/main.zig

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const apiweb = @import("apiweb.zig");
3030
pub const Types = jsruntime.reflect(apiweb.Interfaces);
3131
pub const UserContext = apiweb.UserContext;
3232

33-
const socket_path = "/tmp/browsercore-server.sock";
33+
// TODO: move to cli options
34+
const host = "127.0.0.1";
35+
const port = 3245;
3436

3537
// Inspired by std.net.StreamServer in Zig < 0.12
3638
pub const StreamServer = struct {
@@ -138,18 +140,8 @@ pub fn main() !void {
138140
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
139141
defer arena.deinit();
140142

141-
// remove socket file of internal server
142-
// reuse_address (SO_REUSEADDR flag) does not seems to work on unix socket
143-
// see: https://gavv.net/articles/unix-socket-reuse/
144-
// TODO: use a lock file instead
145-
std.posix.unlink(socket_path) catch |err| {
146-
if (err != error.FileNotFound) {
147-
return err;
148-
}
149-
};
150-
151143
// server
152-
const addr = try std.net.Address.initUnix(socket_path);
144+
const addr = try std.net.Address.parseIp4(host, port);
153145
var srv = StreamServer.init(.{
154146
.reuse_address = true,
155147
.reuse_port = true,
@@ -159,7 +151,7 @@ pub fn main() !void {
159151

160152
try srv.listen(addr);
161153
defer srv.close();
162-
std.debug.print("Listening on: {s}...\n", .{socket_path});
154+
std.log.info("Listening on: {s}:{d}...", .{ host, port });
163155

164156
var loop = try jsruntime.Loop.init(arena.allocator());
165157
defer loop.deinit();

0 commit comments

Comments
 (0)