From 5705806bf72f3d2a06678d21fb739d4351023f22 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 21 Dec 2014 21:42:32 -0500 Subject: [PATCH] lib/socket: intro `flush` and `blocking=` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/socket/socket.nit | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/socket/socket.nit b/lib/socket/socket.nit index f0aaa85..c28a354 100644 --- a/lib/socket/socket.nit +++ b/lib/socket/socket.nit @@ -171,6 +171,14 @@ class TCPStream end end + # Send the data present in the socket buffer + fun flush + do + socket.setsockopt(new NativeSocketOptLevels.tcp, new NativeSocketOptNames.tcp_nodelay, 1) + socket.setsockopt(new NativeSocketOptLevels.tcp, new NativeSocketOptNames.tcp_nodelay, 0) + end +end + # A socket listening on a given `port` for incomming connections # # Create streams to communicate with clients using `accept`. @@ -222,6 +230,14 @@ class TCPServer return new TCPStream.server_side(native) end + # Set whether calls to `accept` are blocking + fun blocking=(value: Bool) + do + # We use the opposite from the native version as the native API + # is closer to the C API. In the Nity API, we use a positive version + # of the name. + socket.non_blocking = not value + end # Close this socket fun close -- 1.7.9.5