summaryrefslogtreecommitdiff
path: root/src/lib/ecore_con
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-12-19 17:11:46 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-12-19 17:11:46 -0200
commita995529a46fe0ceddb28a67fd1d34e0dc456fc66 (patch)
treebca54a770df2d7c064b715739d741fa40416433a /src/lib/ecore_con
parentdb1e2b994ef75163dcd8286ae8b9649d5fb7217e (diff)
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.
Diffstat (limited to 'src/lib/ecore_con')
-rw-r--r--src/lib/ecore_con/Ecore_Con_Eo.h4
-rw-r--r--src/lib/ecore_con/ecore_con_private.h2
-rw-r--r--src/lib/ecore_con/efl_net_dialer_udp.c8
-rw-r--r--src/lib/ecore_con/efl_net_socket_udp.c13
-rw-r--r--src/lib/ecore_con/efl_net_socket_udp.eo9
5 files changed, 26 insertions, 10 deletions
diff --git a/src/lib/ecore_con/Ecore_Con_Eo.h b/src/lib/ecore_con/Ecore_Con_Eo.h
index a5ed29d739..03ade071de 100644
--- a/src/lib/ecore_con/Ecore_Con_Eo.h
+++ b/src/lib/ecore_con/Ecore_Con_Eo.h
@@ -1,5 +1,7 @@
1#include "efl_net_types.eot.h" 1#include "efl_net_types.eot.h"
2 2
3#include "efl_net_ip_address.eo.h"
4
3#include "efl_net_socket.eo.h" 5#include "efl_net_socket.eo.h"
4#include "efl_net_dialer.eo.h" 6#include "efl_net_dialer.eo.h"
5#include "efl_net_server.eo.h" 7#include "efl_net_server.eo.h"
@@ -43,5 +45,3 @@
43#include "efl_net_control_access_point.eo.h" 45#include "efl_net_control_access_point.eo.h"
44#include "efl_net_control.eo.h" 46#include "efl_net_control.eo.h"
45#include "efl_net_session.eo.h" 47#include "efl_net_session.eo.h"
46
47#include "efl_net_ip_address.eo.h"
diff --git a/src/lib/ecore_con/ecore_con_private.h b/src/lib/ecore_con/ecore_con_private.h
index 34478afeba..bcc9deacfe 100644
--- a/src/lib/ecore_con/ecore_con_private.h
+++ b/src/lib/ecore_con/ecore_con_private.h
@@ -171,8 +171,6 @@ void _ecore_con_local_mkpath(const char *path, mode_t mode);
171void _efl_net_server_udp_client_init(Eo *client, SOCKET fd, const struct sockaddr *addr, socklen_t addrlen, const char *str); 171void _efl_net_server_udp_client_init(Eo *client, SOCKET fd, const struct sockaddr *addr, socklen_t addrlen, const char *str);
172void _efl_net_server_udp_client_feed(Eo *client, Eina_Rw_Slice slice); 172void _efl_net_server_udp_client_feed(Eo *client, Eina_Rw_Slice slice);
173 173
174void _efl_net_socket_udp_init(Eo *o, const struct sockaddr *addr, socklen_t addrlen, const char *str);
175
176#ifndef _WIN32 174#ifndef _WIN32
177Eina_Bool efl_net_unix_fmt(char *buf, size_t buflen, SOCKET fd, const struct sockaddr_un *addr, socklen_t addrlen); 175Eina_Bool efl_net_unix_fmt(char *buf, size_t buflen, SOCKET fd, const struct sockaddr_un *addr, socklen_t addrlen);
178#endif 176#endif
diff --git a/src/lib/ecore_con/efl_net_dialer_udp.c b/src/lib/ecore_con/efl_net_dialer_udp.c
index ec7ea9ea69..e493ec9080 100644
--- a/src/lib/ecore_con/efl_net_dialer_udp.c
+++ b/src/lib/ecore_con/efl_net_dialer_udp.c
@@ -1,5 +1,6 @@
1#define EFL_NET_DIALER_UDP_PROTECTED 1 1#define EFL_NET_DIALER_UDP_PROTECTED 1
2#define EFL_NET_DIALER_PROTECTED 1 2#define EFL_NET_DIALER_PROTECTED 1
3#define EFL_NET_SOCKET_UDP_PROTECTED 1
3#define EFL_NET_SOCKET_FD_PROTECTED 1 4#define EFL_NET_SOCKET_FD_PROTECTED 1
4#define EFL_NET_SOCKET_PROTECTED 1 5#define EFL_NET_SOCKET_PROTECTED 1
5#define EFL_IO_READER_PROTECTED 1 6#define EFL_IO_READER_PROTECTED 1
@@ -93,6 +94,7 @@ static Eina_Error
93_efl_net_dialer_udp_resolved_bind(Eo *o, Efl_Net_Dialer_Udp_Data *pd EINA_UNUSED, struct addrinfo *addr) 94_efl_net_dialer_udp_resolved_bind(Eo *o, Efl_Net_Dialer_Udp_Data *pd EINA_UNUSED, struct addrinfo *addr)
94{ 95{
95 Eina_Error err = 0; 96 Eina_Error err = 0;
97 Eo *remote_address;
96 char buf[INET6_ADDRSTRLEN + sizeof("[]:65536")]; 98 char buf[INET6_ADDRSTRLEN + sizeof("[]:65536")];
97 SOCKET fd; 99 SOCKET fd;
98 int family = addr->ai_family; 100 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
160 } 162 }
161 } 163 }
162 164
163 if (efl_net_ip_port_fmt(buf, sizeof(buf), addr->ai_addr)) 165 remote_address = efl_net_ip_address_create_sockaddr(EFL_NET_IP_ADDRESS_CLASS, addr->ai_addr);
166 if (remote_address)
164 { 167 {
165 _efl_net_socket_udp_init(o, addr->ai_addr, addr->ai_addrlen, buf); 168 efl_net_socket_udp_init(o, remote_address);
166 efl_event_callback_call(o, EFL_NET_DIALER_EVENT_RESOLVED, NULL); 169 efl_event_callback_call(o, EFL_NET_DIALER_EVENT_RESOLVED, NULL);
170 efl_del(remote_address);
167 } 171 }
168 efl_net_dialer_connected_set(o, EINA_TRUE); 172 efl_net_dialer_connected_set(o, EINA_TRUE);
169 return 0; 173 return 0;
diff --git a/src/lib/ecore_con/efl_net_socket_udp.c b/src/lib/ecore_con/efl_net_socket_udp.c
index ebce857801..6c74e44256 100644
--- a/src/lib/ecore_con/efl_net_socket_udp.c
+++ b/src/lib/ecore_con/efl_net_socket_udp.c
@@ -53,17 +53,22 @@ typedef struct _Efl_Net_Socket_Udp_Data
53 Eina_Bool reuse_port; 53 Eina_Bool reuse_port;
54} Efl_Net_Socket_Udp_Data; 54} Efl_Net_Socket_Udp_Data;
55 55
56// TODO: once we have Efl_Net_Ip_Address, make this protected and declared in .eo
57void 56void
58_efl_net_socket_udp_init(Eo *o, const struct sockaddr *addr, socklen_t addrlen, const char *str) 57_efl_net_socket_udp_init(Eo *o, Efl_Net_Socket_Udp_Data *pd, Efl_Net_Ip_Address *remote_address)
59{ 58{
60 Efl_Net_Socket_Udp_Data *pd = efl_data_scope_get(o, MY_CLASS); 59 const struct sockaddr *addr = efl_net_ip_address_sockaddr_get(remote_address);
60 socklen_t addrlen;
61
62 EINA_SAFETY_ON_NULL_RETURN(addr);
63
64 if (addr->sa_family == AF_INET) addrlen = sizeof(struct sockaddr_in);
65 else addrlen = sizeof(struct sockaddr_in6);
61 66
62 pd->addr_remote = malloc(addrlen); 67 pd->addr_remote = malloc(addrlen);
63 EINA_SAFETY_ON_NULL_RETURN(pd->addr_remote); 68 EINA_SAFETY_ON_NULL_RETURN(pd->addr_remote);
64 memcpy(pd->addr_remote, addr, addrlen); 69 memcpy(pd->addr_remote, addr, addrlen);
65 pd->addr_remote_len = addrlen; 70 pd->addr_remote_len = addrlen;
66 efl_net_socket_address_remote_set(o, str); 71 efl_net_socket_address_remote_set(o, efl_net_ip_address_string_get(remote_address));
67} 72}
68 73
69static Eina_Error 74static Eina_Error
diff --git a/src/lib/ecore_con/efl_net_socket_udp.eo b/src/lib/ecore_con/efl_net_socket_udp.eo
index c1e0775d1c..13d0c3fff3 100644
--- a/src/lib/ecore_con/efl_net_socket_udp.eo
+++ b/src/lib/ecore_con/efl_net_socket_udp.eo
@@ -1,3 +1,5 @@
1import efl_net_ip_address;
2
1class Efl.Net.Socket.Udp (Efl.Net.Socket.Fd) { 3class Efl.Net.Socket.Udp (Efl.Net.Socket.Fd) {
2 [[A base UDP socket. 4 [[A base UDP socket.
3 5
@@ -162,6 +164,13 @@ class Efl.Net.Socket.Udp (Efl.Net.Socket.Fd) {
162 address: string @nonull; [[Address to bind to]] 164 address: string @nonull; [[Address to bind to]]
163 } 165 }
164 } 166 }
167
168 init @protected {
169 [[Initialize the socket to communicate with given IP address]]
170 params {
171 remote_address: Efl.Net.Ip.Address; [[The remote address this socket will communicate with]]
172 }
173 }
165 } 174 }
166 175
167 implements { 176 implements {