lib/standard: remove the only `attr-in-refinement` warning
[nit.git] / lib / libevent.nit
index 525915c..58069c8 100644 (file)
@@ -92,8 +92,9 @@ extern class NativeEventBase `{ struct event_base * `}
 
        # Create a new event_base to use with the rest of Libevent
        new `{ return event_base_new(); `}
+
+       # Has `self` been correctly initialized?
        fun is_valid: Bool do return not address_is_null
-       #fun creation_ok
 
        # Event dispatching loop
        #
@@ -114,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
 
@@ -124,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
@@ -152,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
-               var res = native_buffer_event.write(str.to_cstring, str.length)
+               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`
@@ -164,7 +169,7 @@ class Connection
        do
                assert path.file_exists
 
-               var file = new IFStream.open(path)
+               var file = new FileReader.open(path)
                var output = native_buffer_event.output_buffer
                var fd = file.fd
                var length = file.file_stat.size
@@ -175,10 +180,17 @@ end
 
 # A buffer event structure, strongly associated to a connection, an input buffer and an output_buffer
 extern class NativeBufferEvent `{ struct bufferevent * `}
+       # Write `length` bytes of `line`
        fun write(line: NativeString, length: Int): Int `{
                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 `{
@@ -205,6 +217,7 @@ extern class NativeEvBuffer `{ struct evbuffer * `}
        fun length: Int `{ return evbuffer_get_length(recv); `}
 end
 
+# An input buffer
 extern class InputNativeEvBuffer
        super NativeEvBuffer
 
@@ -212,6 +225,7 @@ extern class InputNativeEvBuffer
        fun drain(length: Int) `{ evbuffer_drain(recv, length); `}
 end
 
+# An output buffer
 extern class OutputNativeEvBuffer
        super NativeEvBuffer
 
@@ -270,6 +284,7 @@ end
 
 # Factory to listen on sockets and create new `Connection`
 class ConnectionFactory
+       # The `NativeEventBase` for the dispatch loop of this factory
        var event_base: NativeEventBase
 
        # On new connection, create the handler `Connection` object