X-Git-Url: http://nitlanguage.org diff --git a/lib/libevent.nit b/lib/libevent.nit index ff9a9f5..58069c8 100644 --- a/lib/libevent.nit +++ b/lib/libevent.nit @@ -115,6 +115,8 @@ end # # TODO, use polls class Connection + super Writer + # Closing this connection has been requested, but may not yet be `closed` var close_requested = false @@ -125,7 +127,7 @@ class Connection var native_buffer_event: NativeBufferEvent # Close this connection if possible, otherwise mark it to be closed later - fun close + redef fun close do var success = native_buffer_event.destroy close_requested = true @@ -153,11 +155,13 @@ class Connection fun event_callback(events: Int) do end # Write a string to the connection - fun write(str: String) + redef fun write(str) do native_buffer_event.write(str.to_cstring, str.length) end + redef fun write_byte(byte) do native_buffer_event.write_byte(byte) + # Write a file to the connection # # require: `path.file_exists` @@ -181,6 +185,12 @@ extern class NativeBufferEvent `{ struct bufferevent * `} return bufferevent_write(recv, line, length); `} + # Write the byte `value` + fun write_byte(value: Int): Int `{ + unsigned char byt = (unsigned char)value; + return bufferevent_write(recv, &byt, 1); + `} + # Check if we have anything left in our buffers. If so, we set our connection to be closed # on a callback. Otherwise we close it and free it right away. fun destroy: Bool `{