Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
982e6769
Commit
982e6769
authored
May 24, 2017
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zephyr/modusocket: getaddrinfo: Raise OSError on resolution timeout, etc.
parent
1c9ee497
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletion
+12
-1
zephyr/modusocket.c
zephyr/modusocket.c
+12
-1
No files found.
zephyr/modusocket.c
View file @
982e6769
...
...
@@ -533,12 +533,18 @@ typedef struct _getaddrinfo_state_t {
mp_obj_t
result
;
struct
k_sem
sem
;
mp_obj_t
port
;
int
status
;
}
getaddrinfo_state_t
;
void
dns_resolve_cb
(
enum
dns_resolve_status
status
,
struct
dns_addrinfo
*
info
,
void
*
user_data
)
{
getaddrinfo_state_t
*
state
=
user_data
;
DEBUG_printf
(
"dns status: %d
\n
"
,
status
);
if
(
info
==
NULL
)
{
if
(
status
==
DNS_EAI_ALLDONE
)
{
status
=
0
;
}
state
->
status
=
status
;
k_sem_give
(
&
state
->
sem
);
return
;
}
...
...
@@ -569,7 +575,6 @@ STATIC mp_obj_t mod_getaddrinfo(size_t n_args, const mp_obj_t *args) {
state
.
result
=
mp_obj_new_list
(
0
,
NULL
);
k_sem_init
(
&
state
.
sem
,
0
,
UINT_MAX
);
int
status
;
for
(
int
i
=
2
;
i
--
;)
{
int
type
=
(
family
!=
AF_INET6
?
DNS_QUERY_TYPE_A
:
DNS_QUERY_TYPE_AAAA
);
RAISE_ERRNO
(
dns_get_addr_info
(
host
,
type
,
NULL
,
dns_resolve_cb
,
&
state
,
3000
));
...
...
@@ -580,6 +585,12 @@ STATIC mp_obj_t mod_getaddrinfo(size_t n_args, const mp_obj_t *args) {
family
=
AF_INET6
;
}
// Raise error only if there's nothing to return, otherwise
// it may be IPv4 vs IPv6 differences.
if
(
state
.
status
!=
0
&&
mp_obj_len
(
state
.
result
)
==
0
)
{
mp_raise_OSError
(
state
.
status
);
}
return
state
.
result
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mod_getaddrinfo_obj
,
2
,
3
,
mod_getaddrinfo
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment