A websocket implementation for zig
0

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #81 from xtexx/gpa-fixes

server: Wait for threads to exit when stopping

authored by

Karl Seguin and committed by
GitHub
(Sep 23, 2025, 5:49 PM +0800) 2d9ae9b0 4deaaef2

+15 -7
+15 -7
src/server/server.zig
··· 269 269 thrd.join(); 270 270 } 271 271 } 272 + self._cond.signal(); 272 273 } 273 274 274 275 pub fn stop(self: *Self) void { ··· 283 284 } 284 285 posix.close(s); 285 286 } 287 + self._cond.wait(&self._mut); 286 288 } 287 289 }; 288 290 } ··· 647 649 // Else, we'll need to throw a bunch of locking around HC just to handle shutdown. 648 650 fn dataAvailable(self: *Self, hc: *HandlerConn(H), thread_buf: []u8) void { 649 651 var success = false; 650 - if (hc.handler == null) { 651 - success = self.dataForHandshake(hc) catch |err| blk: { 652 - log.err("({f}) error processing handshake: {}", .{ hc.conn.address, err }); 653 - break :blk false; 654 - }; 655 - } else { 656 - success = self.base.dataAvailable(hc, thread_buf); 652 + { 653 + hc.cleanup.lock(); 654 + defer hc.cleanup.unlock(); 655 + if (hc.handler == null) { 656 + success = self.dataForHandshake(hc) catch |err| blk: { 657 + log.err("({f}) error processing handshake: {}", .{ hc.conn.address, err }); 658 + break :blk false; 659 + }; 660 + } else { 661 + success = self.base.dataAvailable(hc, thread_buf); 662 + } 657 663 } 658 664 659 665 var conn = &hc.conn; ··· 1287 1293 var next_node = head; 1288 1294 while (next_node) |hc| { 1289 1295 if (comptime std.meta.hasFn(H, "close")) { 1296 + hc.cleanup.lock(); 1297 + defer hc.cleanup.unlock(); 1290 1298 if (hc.handler) |*h| { 1291 1299 h.close(); 1292 1300 hc.handler = null;