libevent :: Connection :: close_requested
Closing this connection has been requested, but may not yet beclosed
libevent :: Connection :: close_requested=
Closing this connection has been requested, but may not yet beclosed
libevent :: Connection :: defaultinit
libevent :: Connection :: event_callback
Callback method on events: EOF, user-defined timeout and unrecoverable errorslibevent :: Connection :: force_close
Force closing this connection and freeingnative_buffer_event
libevent :: Connection :: native_buffer_event
The native libevent linked toself
libevent :: Connection :: native_buffer_event=
The native libevent linked toself
libevent :: Connection :: read_callback
Callback method when data is available to readlibevent $ Connection :: SELF
Type of this instance, automatically specialized in every classlibevent $ Connection :: close
Close this connection if possible, otherwise mark it to be closed laterlibevent $ Connection :: write_bytes_from_cstring
Writelen
bytes from ns
binary :: BinaryStream :: big_endian
Use the big-endian convention? otherwise use little-endian.binary :: BinaryStream :: big_endian=
Use the big-endian convention? otherwise use little-endian.core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
libevent :: Connection :: close_requested
Closing this connection has been requested, but may not yet beclosed
libevent :: Connection :: close_requested=
Closing this connection has been requested, but may not yet beclosed
binary :: BinaryStream :: defaultinit
core :: Stream :: defaultinit
core :: Object :: defaultinit
libevent :: Connection :: defaultinit
core :: Writer :: defaultinit
libevent :: Connection :: event_callback
Callback method on events: EOF, user-defined timeout and unrecoverable errorslibevent :: Connection :: force_close
Force closing this connection and freeingnative_buffer_event
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Stream :: last_error=
Error produced by the file streamcore :: Stream :: lookahead=
Lookahead buffer for codecscore :: Stream :: lookahead_capacity
Capacity of the lookaheadcore :: Stream :: lookahead_capacity=
Capacity of the lookaheadcore :: Stream :: lookahead_length
Current occupation of the lookaheadcore :: Stream :: lookahead_length=
Current occupation of the lookaheadlibevent :: Connection :: native_buffer_event
The native libevent linked toself
libevent :: Connection :: native_buffer_event=
The native libevent linked toself
core :: Object :: output_class_name
Display class name on stdout (debug only).libevent :: Connection :: read_callback
Callback method when data is available to readcore :: Writer :: serialize_msgpack
Serializevalue
in MessagePack format
core :: Writer :: write_block
Write the length as a 64 bits integer, then the content oftext
core :: Writer :: write_bool
Write a booleanvalue
on a byte, using 0 for false
and 1 for true
core :: Stream :: write_buffer
Buffer for writing data to a streamcore :: Stream :: write_buffer=
Buffer for writing data to a streamcore :: Writer :: write_bytes_from_cstring
Writelen
bytes from ns
core :: Writer :: write_double
Write a floating pointvalue
on 64 bits
core :: Writer :: write_int64
Writevalue
as a signed integer on 64 bits
core :: Writer :: write_msgpack_array
Write an array header forlen
items in the shortest possible MessagePack array format
core :: Writer :: write_msgpack_array16
Write an array header forlen
items, max of 0xFFFF items
core :: Writer :: write_msgpack_array32
Write an array header forlen
items, max of 0xFFFF_FFFF items
core :: Writer :: write_msgpack_bin
Writedata
in the shortest possible MessagePack bin format
core :: Writer :: write_msgpack_bin16
Writedata
in bin16 format, max of 0xFFFF bytes
core :: Writer :: write_msgpack_bin32
Writedata
in bin32 format, max of 0xFFFF_FFFF bytes
core :: Writer :: write_msgpack_bin8
Writedata
in bin8 format, max of 0xFF bytes
core :: Writer :: write_msgpack_bool
Writebool
in MessagePack format
core :: Writer :: write_msgpack_double
Writevalue
as a MessagePack double
core :: Writer :: write_msgpack_ext
Write an application-specific extension fortyp
and bytes
in the shortest possible MessagePack ext format
core :: Writer :: write_msgpack_ext16
Write the header for an application-specific extension oflen
data bytes
core :: Writer :: write_msgpack_ext32
Write the header for an application-specific extension oflen
data bytes
core :: Writer :: write_msgpack_ext8
Write the header for an application-specific extension oflen
data bytes
core :: Writer :: write_msgpack_fixarray
Write an array header forlen
items, max of 0x0F items
core :: Writer :: write_msgpack_fixext1
Write the header for an application-specific extension of one data bytecore :: Writer :: write_msgpack_fixext16
Write the header for an application-specific extension of 16 data bytescore :: Writer :: write_msgpack_fixext2
Write the header for an application-specific extension of two data bytescore :: Writer :: write_msgpack_fixext4
Write the header for an application-specific extension of 4 data bytescore :: Writer :: write_msgpack_fixext8
Write the header for an application-specific extension of 8 data bytescore :: Writer :: write_msgpack_fixint
Writevalue
as a single byte with metadata
core :: Writer :: write_msgpack_fixmap
Write a map header forlen
key/value pairs, max of 0x0F pairs
core :: Writer :: write_msgpack_fixstr
Writetext
in fixstr format, max of 0x1F bytes
core :: Writer :: write_msgpack_float
Writevalue
as a MessagePack float (losing precision)
core :: Writer :: write_msgpack_int
Write the integervalue
either as the shortest possible MessagePack int
core :: Writer :: write_msgpack_int16
Writevalue
over two signed bytes, following 1 metadata byte
core :: Writer :: write_msgpack_int32
Writevalue
over 4 signed bytes, following 1 metadata byte
core :: Writer :: write_msgpack_int64
Writevalue
over 8 signed bytes, following 1 metadata byte
core :: Writer :: write_msgpack_int8
Writevalue
over one signed byte, following 1 metadata byte
core :: Writer :: write_msgpack_map
Write a map header forlen
keys/value pairs in the shortest possible MessagePack map format
core :: Writer :: write_msgpack_map16
Write a map header forlen
key/value pairs, max of 0xFFFF pairs
core :: Writer :: write_msgpack_map32
Write a map header forlen
key/value pairs, max of 0xFFFF_FFFF pairs
core :: Writer :: write_msgpack_null
Writenull
, or nil, in MessagePack format
core :: Writer :: write_msgpack_str
Writetext
in the shortest possible MessagePack format
core :: Writer :: write_msgpack_str16
Writetext
in str16 format, max of 0xFFFF bytes
core :: Writer :: write_msgpack_str32
Writetext
in str32 format, max of 0xFFFF_FFFF bytes
core :: Writer :: write_msgpack_str8
Writetext
in str8 format, max of 0xFF bytes
core :: Writer :: write_msgpack_uint16
Writevalue
over two unsigned bytes, following 1 metadata byte
core :: Writer :: write_msgpack_uint32
Writevalue
over 4 unsigned bytes, following 1 metadata byte
core :: Writer :: write_msgpack_uint64
Writevalue
over 8 unsigned bytes, following 1 metadata byte
core :: Writer :: write_msgpack_uint8
Writevalue
over one unsigned byte, following 1 metadata byte
# Spawned to manage a specific connection
class Connection
super Writer
# Closing this connection has been requested, but may not yet be `closed`
var close_requested = false
# This connection is closed
var closed = false
# The native libevent linked to `self`
var native_buffer_event: NativeBufferEvent
# Close this connection if possible, otherwise mark it to be closed later
redef fun close
do
if closed then return
var i = native_buffer_event.input_buffer
var o = native_buffer_event.output_buffer
if i.length > 0 or o.length > 0 then
close_requested = true
else
force_close
end
end
# Force closing this connection and freeing `native_buffer_event`
fun force_close
do
if closed then return
native_buffer_event.free
closed = true
end
# Callback method on a write event
fun write_callback
do
if close_requested then close
end
private fun read_callback_native(bev: NativeBufferEvent)
do
var evbuffer = bev.input_buffer
var len = evbuffer.length
var buf = new CString(len)
evbuffer.remove(buf, len)
var str = buf.to_s_with_length(len)
read_callback str
end
# Callback method when data is available to read
fun read_callback(content: String)
do
if close_requested then close
end
# Callback method on events: EOF, user-defined timeout and unrecoverable errors
#
# Returns `true` if the native handles to `self` can be released.
fun event_callback(events: Int): Bool
do
if events & bev_event_error != 0 or events & bev_event_eof != 0 then
if events & bev_event_error != 0 then
var sock_err = evutil_socket_error
# Ignore some normal errors and print the others for debugging
if sock_err == 110 then
# Connection timed out (ETIMEDOUT)
else if sock_err == 104 then
# Connection reset by peer (ECONNRESET)
else
print_error "libevent error event: {evutil_socket_error_to_string(sock_err)} ({sock_err})"
end
end
force_close
return true
end
return false
end
# Write a string to the connection
redef fun write(str)
do
if close_requested then return
native_buffer_event.write(str.to_cstring, str.byte_length)
end
redef fun write_byte(byte)
do
if close_requested then return
native_buffer_event.write_byte(byte)
end
redef fun write_bytes_from_cstring(ns, len)
do
if close_requested then return
native_buffer_event.write(ns, len)
end
# Write a file to the connection
#
# If `not path.file_exists`, the method returns.
fun write_file(path: String)
do
if close_requested then return
var file = new FileReader.open(path)
if file.last_error != null then
var error = new IOError("Failed to open file at '{path}'")
error.cause = file.last_error
self.last_error = error
file.close
return
end
var stat = file.file_stat
if stat == null then
last_error = new IOError("Failed to stat file at '{path}'")
file.close
return
end
var err = native_buffer_event.output_buffer.add_file(file.fd, 0, stat.size)
if err then
last_error = new IOError("Failed to add file at '{path}'")
file.close
end
end
end
lib/libevent/libevent.nit:150,1--280,3