efl.net: socket, server and dialer for TCP.
Efl.Net.Server defines how to accept new connections, doing the
bind(), listen() and accept() for protocols such as TCP.
Efl.Net.Dialer defines to to reach a server.
Both are based on Efl.Net.Socket as communication interface that is
based on Efl.Io.Reader, Efl.Io.Writer and Efl.Io.Closer, thus being
usable with code such as Efl.Io.Copier.
The Server will emit an event "client,add" with the established
Socket, which is a child and can be closed by both the server or the
user.
The Dialer extends the Socket and allows for creating one given an
address, that will be resolved and connected.
TCP is the initial implementation so we an validate the
interfaces. UDP, Unix-Local and SSL will come later as derivate
classes.
The examples are documented and should cover the basic principles:
- efl_io_copier_example can accept "tcp://IP:PORT" and will work as a
"netcat", can send data from socket, file or stdin to a socket,
file, stdout or stderr.
- efl_net_server_example listens for connections and can either reply
"Hello World!" and take some data or work as an echo-server,
looping back all received data to the user.
More complex interactions that require a "chat" between client and
server will be covered with new classes later, such as a queue that
empties itself once data is read.
2016-08-17 21:53:16 -07:00
class Efl.Net.Server.Fd (Efl.Loop.Fd, Efl.Net.Server) {
[[A generic server based on file descriptors.
@since 1.19
]]
methods {
@property family {
[[The address family (AF_*) family of this socket.
It will be one of AF_INET (IPv4), AF_INET6 (IPv6),
AF_UNIX...
It must be set before the @Efl.Loop.Fd.fd.set is called
with a valid file descriptor.
]]
get { }
set @protected { }
values {
family: int;
}
}
@property close_on_exec {
[[Controls Close-on-Exec() using FD_CLOEXEC.
Children socket will inherit the server's setting by
default. One can change the behavior using each instance
2016-09-12 08:23:29 -07:00
@Efl.Io.Closer.close_on_exec.set.
efl.net: socket, server and dialer for TCP.
Efl.Net.Server defines how to accept new connections, doing the
bind(), listen() and accept() for protocols such as TCP.
Efl.Net.Dialer defines to to reach a server.
Both are based on Efl.Net.Socket as communication interface that is
based on Efl.Io.Reader, Efl.Io.Writer and Efl.Io.Closer, thus being
usable with code such as Efl.Io.Copier.
The Server will emit an event "client,add" with the established
Socket, which is a child and can be closed by both the server or the
user.
The Dialer extends the Socket and allows for creating one given an
address, that will be resolved and connected.
TCP is the initial implementation so we an validate the
interfaces. UDP, Unix-Local and SSL will come later as derivate
classes.
The examples are documented and should cover the basic principles:
- efl_io_copier_example can accept "tcp://IP:PORT" and will work as a
"netcat", can send data from socket, file or stdin to a socket,
file, stdout or stderr.
- efl_net_server_example listens for connections and can either reply
"Hello World!" and take some data or work as an echo-server,
looping back all received data to the user.
More complex interactions that require a "chat" between client and
server will be covered with new classes later, such as a queue that
empties itself once data is read.
2016-08-17 21:53:16 -07:00
]]
get { }
set {
return: bool (false); [[$true on success]]
}
values {
close_on_exec: bool;
}
}
@property reuse_address {
[[Controls address reuse() using SO_REUSEADDR]]
get { }
set {
return: bool (false); [[$true on success]]
}
values {
reuse_address: bool;
}
}
@property reuse_port {
[[Controls port reuse() using SO_REUSEPORT (since linux 3.9)]]
get { }
set {
return: bool (false); [[$true on success]]
}
values {
reuse_port: bool;
}
}
2016-10-21 04:24:50 -07:00
process_incoming_data @protected {
[[When the socket has data to be read, process it.
By default this method will call accept() and then
decide if @.client_add or @.client_reject must be
executed, however it may be replaced with something
else, such as in SOCK_DGRAM (UDP) there is no accept(),
only recvfrom().
It is called straight from @Efl.Loop.Fd "read" event
handler and is provided as a method to allow easy
extending of the class for various purposes.
]]
}
efl.net: socket, server and dialer for TCP.
Efl.Net.Server defines how to accept new connections, doing the
bind(), listen() and accept() for protocols such as TCP.
Efl.Net.Dialer defines to to reach a server.
Both are based on Efl.Net.Socket as communication interface that is
based on Efl.Io.Reader, Efl.Io.Writer and Efl.Io.Closer, thus being
usable with code such as Efl.Io.Copier.
The Server will emit an event "client,add" with the established
Socket, which is a child and can be closed by both the server or the
user.
The Dialer extends the Socket and allows for creating one given an
address, that will be resolved and connected.
TCP is the initial implementation so we an validate the
interfaces. UDP, Unix-Local and SSL will come later as derivate
classes.
The examples are documented and should cover the basic principles:
- efl_io_copier_example can accept "tcp://IP:PORT" and will work as a
"netcat", can send data from socket, file or stdin to a socket,
file, stdout or stderr.
- efl_net_server_example listens for connections and can either reply
"Hello World!" and take some data or work as an echo-server,
looping back all received data to the user.
More complex interactions that require a "chat" between client and
server will be covered with new classes later, such as a queue that
empties itself once data is read.
2016-08-17 21:53:16 -07:00
client_add @protected @virtual_pure {
[[Accept a new client, should emit "client,add".
Remember to create the client object with a callback to
EFL_IO_CLOSER_EVENT_CLOSED during the construction and
decrease @Efl.Net.Server.clients_count as well as unref
the client and remove yourself as parent.
The new clients should have the server as parent and
increase the @Efl.Net.Server.clients_count.
Whenever this function fails, it must close the given
client file descriptor.
]]
params {
client_fd: int; [[The file descriptor of the client socket. It comes preconfigured with close_on_exec. On failure, remember to close this socket]]
}
}
client_reject @protected @virtual_pure {
[[Reject a new client, should emit "client,rejected".
Must always close the client socket when it's done.
]]
params {
client_fd: int; [[The file descriptor of the client socket. It comes preconfigured with close_on_exec and should be closed once it's not needed anymore]]
}
}
}
implements {
Efl.Object.finalize;
Efl.Object.constructor;
Efl.Object.destructor;
Efl.Loop.Fd.fd.set;
Efl.Net.Server.address;
Efl.Net.Server.clients_count;
Efl.Net.Server.clients_limit;
Efl.Net.Server.serving;
Efl.Net.Server.serve;
}
}