2016-10-20 19:15:09 -07:00
|
|
|
var Efl.Net.Server.Error.COULDNT_RESOLVE_HOST: Eina.Error; [[The server could not resolve the given host name or port given as address.]]
|
|
|
|
|
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
|
|
|
interface Efl.Net.Server {
|
|
|
|
[[The basic server interface.
|
|
|
|
|
|
|
|
It will start serving and accepting clients once @.serve is
|
|
|
|
called and the "serving" event is dispatched.
|
|
|
|
|
|
|
|
When new clients are accepted, then "client,add" event is
|
|
|
|
dispatched with a child object implementing @Efl.Net.Socket
|
|
|
|
interface. These implement the standard @Efl.Io.Reader,
|
|
|
|
@Efl.Io.Writer and @Efl.Io.Closer interfaces, thus can be used
|
|
|
|
with utilities such as @Efl.Io.Copier.
|
|
|
|
|
|
|
|
@since 1.19
|
|
|
|
]]
|
|
|
|
|
|
|
|
events {
|
|
|
|
client,add @hot: Efl.Net.Socket; [[A new client socket was created.
|
|
|
|
|
|
|
|
The socket will have the
|
|
|
|
server as parent and can be
|
|
|
|
closed by both the server
|
|
|
|
or the user using
|
|
|
|
@Efl.Io.Closer.
|
|
|
|
]]
|
|
|
|
client,rejected: string; [[Notifies a client was rejected due
|
|
|
|
excess, see @.clients_limit.
|
|
|
|
]]
|
|
|
|
|
|
|
|
error: Eina.Error; [[Some error happened and the server needs
|
|
|
|
to be stopped.
|
|
|
|
]]
|
|
|
|
serving; [[Notifies the server is ready to accept clients.
|
|
|
|
See property @.serving]]
|
|
|
|
}
|
|
|
|
|
|
|
|
methods {
|
|
|
|
serve {
|
|
|
|
[[Starts serving requests.
|
|
|
|
|
|
|
|
This method starts the server, resolving address and
|
|
|
|
then proceeding to the actual listen(2)/bind(2)
|
|
|
|
equivalent..
|
|
|
|
|
|
|
|
Once the connection is fully setup, "serving" event is
|
|
|
|
dispatched.
|
|
|
|
]]
|
|
|
|
params {
|
|
|
|
address: string @nonull;
|
|
|
|
}
|
|
|
|
return: Eina.Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
@property address {
|
|
|
|
[[The address the server is bound to.
|
|
|
|
|
|
|
|
The actual value depends on the type of server, like an
|
|
|
|
IPv4 (ip:port) or IPv6 ([ip]:port) formatted for a
|
|
|
|
TCP/UDP server, the path if an Unix Local...
|
|
|
|
|
|
|
|
It's always resolved, then if operations are working
|
|
|
|
with domain names or URL, this is the values the kernel
|
|
|
|
reports. It's similar to getsockname() in behavior.
|
|
|
|
]]
|
|
|
|
get { }
|
|
|
|
set @protected { }
|
|
|
|
values {
|
|
|
|
address: string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@property clients_count {
|
|
|
|
[[Number of concurrent clients accepted by this server.]]
|
|
|
|
get { }
|
|
|
|
set @protected { }
|
|
|
|
values {
|
|
|
|
count: uint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@property clients_limit {
|
|
|
|
[[Number of maximum concurrent clients allowed by this server.
|
|
|
|
|
|
|
|
If reject_excess is set to true, then the connection
|
|
|
|
will be accepted and immediately closed.
|
|
|
|
|
|
|
|
If reject_excess is set to false (default), then
|
|
|
|
accept(2) won't be called and clients will be queued at
|
|
|
|
the kernel side, usually up to 4096 pending clients.
|
|
|
|
|
|
|
|
Whenever changed, this property will only apply to new
|
|
|
|
connections, that is, if the current connection count
|
|
|
|
alredy exceeds the limit, no connections will be closed.
|
|
|
|
]]
|
|
|
|
values {
|
|
|
|
limit: uint;
|
|
|
|
reject_excess: bool @optional;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@property serving {
|
|
|
|
[[Returns whenever the server is ready to accept clients or not.
|
|
|
|
|
|
|
|
Whenever this property becomes true, "serving" event
|
|
|
|
should be dispatched.
|
|
|
|
]]
|
|
|
|
get { }
|
|
|
|
set @protected { }
|
|
|
|
values {
|
|
|
|
serving: bool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|