efl_net_socket_udp: expose init() as protected method.

remove one more TODO: since Efl.Net.Ip.Address was introduced we can
now expose Efl.Net.Socket.Udp.init as a protected method that will
configure the internal address we use for the remote peer. This allow
subclasses to override or call such methods.
This commit is contained in:
Gustavo Sverzut Barbieri 2016-12-19 17:11:46 -02:00
parent db1e2b994e
commit a995529a46
5 changed files with 26 additions and 10 deletions

View File

@ -1,5 +1,7 @@
#include "efl_net_types.eot.h"
#include "efl_net_ip_address.eo.h"
#include "efl_net_socket.eo.h"
#include "efl_net_dialer.eo.h"
#include "efl_net_server.eo.h"
@ -43,5 +45,3 @@
#include "efl_net_control_access_point.eo.h"
#include "efl_net_control.eo.h"
#include "efl_net_session.eo.h"
#include "efl_net_ip_address.eo.h"

View File

@ -171,8 +171,6 @@ void _ecore_con_local_mkpath(const char *path, mode_t mode);
void _efl_net_server_udp_client_init(Eo *client, SOCKET fd, const struct sockaddr *addr, socklen_t addrlen, const char *str);
void _efl_net_server_udp_client_feed(Eo *client, Eina_Rw_Slice slice);
void _efl_net_socket_udp_init(Eo *o, const struct sockaddr *addr, socklen_t addrlen, const char *str);
#ifndef _WIN32
Eina_Bool efl_net_unix_fmt(char *buf, size_t buflen, SOCKET fd, const struct sockaddr_un *addr, socklen_t addrlen);
#endif

View File

@ -1,5 +1,6 @@
#define EFL_NET_DIALER_UDP_PROTECTED 1
#define EFL_NET_DIALER_PROTECTED 1
#define EFL_NET_SOCKET_UDP_PROTECTED 1
#define EFL_NET_SOCKET_FD_PROTECTED 1
#define EFL_NET_SOCKET_PROTECTED 1
#define EFL_IO_READER_PROTECTED 1
@ -93,6 +94,7 @@ static Eina_Error
_efl_net_dialer_udp_resolved_bind(Eo *o, Efl_Net_Dialer_Udp_Data *pd EINA_UNUSED, struct addrinfo *addr)
{
Eina_Error err = 0;
Eo *remote_address;
char buf[INET6_ADDRSTRLEN + sizeof("[]:65536")];
SOCKET fd;
int family = addr->ai_family;
@ -160,10 +162,12 @@ _efl_net_dialer_udp_resolved_bind(Eo *o, Efl_Net_Dialer_Udp_Data *pd EINA_UNUSED
}
}
if (efl_net_ip_port_fmt(buf, sizeof(buf), addr->ai_addr))
remote_address = efl_net_ip_address_create_sockaddr(EFL_NET_IP_ADDRESS_CLASS, addr->ai_addr);
if (remote_address)
{
_efl_net_socket_udp_init(o, addr->ai_addr, addr->ai_addrlen, buf);
efl_net_socket_udp_init(o, remote_address);
efl_event_callback_call(o, EFL_NET_DIALER_EVENT_RESOLVED, NULL);
efl_del(remote_address);
}
efl_net_dialer_connected_set(o, EINA_TRUE);
return 0;

View File

@ -53,17 +53,22 @@ typedef struct _Efl_Net_Socket_Udp_Data
Eina_Bool reuse_port;
} Efl_Net_Socket_Udp_Data;
// TODO: once we have Efl_Net_Ip_Address, make this protected and declared in .eo
void
_efl_net_socket_udp_init(Eo *o, const struct sockaddr *addr, socklen_t addrlen, const char *str)
_efl_net_socket_udp_init(Eo *o, Efl_Net_Socket_Udp_Data *pd, Efl_Net_Ip_Address *remote_address)
{
Efl_Net_Socket_Udp_Data *pd = efl_data_scope_get(o, MY_CLASS);
const struct sockaddr *addr = efl_net_ip_address_sockaddr_get(remote_address);
socklen_t addrlen;
EINA_SAFETY_ON_NULL_RETURN(addr);
if (addr->sa_family == AF_INET) addrlen = sizeof(struct sockaddr_in);
else addrlen = sizeof(struct sockaddr_in6);
pd->addr_remote = malloc(addrlen);
EINA_SAFETY_ON_NULL_RETURN(pd->addr_remote);
memcpy(pd->addr_remote, addr, addrlen);
pd->addr_remote_len = addrlen;
efl_net_socket_address_remote_set(o, str);
efl_net_socket_address_remote_set(o, efl_net_ip_address_string_get(remote_address));
}
static Eina_Error

View File

@ -1,3 +1,5 @@
import efl_net_ip_address;
class Efl.Net.Socket.Udp (Efl.Net.Socket.Fd) {
[[A base UDP socket.
@ -162,6 +164,13 @@ class Efl.Net.Socket.Udp (Efl.Net.Socket.Fd) {
address: string @nonull; [[Address to bind to]]
}
}
init @protected {
[[Initialize the socket to communicate with given IP address]]
params {
remote_address: Efl.Net.Ip.Address; [[The remote address this socket will communicate with]]
}
}
}
implements {