#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"
#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"
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
#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
_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;
}
}
- 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;
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
+import efl_net_ip_address;
+
class Efl.Net.Socket.Udp (Efl.Net.Socket.Fd) {
[[A base UDP socket.
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 {