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
600f5afe
Commit
600f5afe
authored
Aug 08, 2017
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zephyr/modusocket: bind, connect, listen, accept: Swtich to native sockets.
parent
6c55cdaf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
+12
-7
zephyr/modusocket.c
zephyr/modusocket.c
+12
-7
No files found.
zephyr/modusocket.c
View file @
600f5afe
...
...
@@ -278,7 +278,9 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
struct
sockaddr
sockaddr
;
parse_inet_addr
(
socket
,
addr_in
,
&
sockaddr
);
RAISE_ERRNO
(
net_context_bind
(
socket
->
ctx
,
&
sockaddr
,
sizeof
(
sockaddr
)));
int
res
=
zsock_bind
(
socket
->
ctx
,
&
sockaddr
,
sizeof
(
sockaddr
));
RAISE_SOCK_ERRNO
(
res
);
// For DGRAM socket, we expect to receive packets after call to bind(),
// but for STREAM socket, next expected operation is listen(), which
// doesn't work if recv callback is set.
...
...
@@ -297,7 +299,9 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
struct
sockaddr
sockaddr
;
parse_inet_addr
(
socket
,
addr_in
,
&
sockaddr
);
RAISE_ERRNO
(
net_context_connect
(
socket
->
ctx
,
&
sockaddr
,
sizeof
(
sockaddr
),
NULL
,
K_FOREVER
,
NULL
));
int
res
=
zsock_connect
(
socket
->
ctx
,
&
sockaddr
,
sizeof
(
sockaddr
));
RAISE_SOCK_ERRNO
(
res
);
DEBUG_printf
(
"Setting recv cb after connect()
\n
"
);
RAISE_ERRNO
(
net_context_recv
(
socket
->
ctx
,
sock_received_cb
,
K_NO_WAIT
,
socket
));
return
mp_const_none
;
...
...
@@ -309,8 +313,9 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) {
socket_check_closed
(
socket
);
mp_int_t
backlog
=
mp_obj_get_int
(
backlog_in
);
RAISE_ERRNO
(
net_context_listen
(
socket
->
ctx
,
backlog
));
RAISE_ERRNO
(
net_context_accept
(
socket
->
ctx
,
sock_accepted_cb
,
K_NO_WAIT
,
socket
));
int
res
=
zsock_listen
(
socket
->
ctx
,
backlog
);
RAISE_SOCK_ERRNO
(
res
);
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
socket_listen_obj
,
socket_listen
);
...
...
@@ -319,9 +324,9 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
socket_obj_t
*
socket
=
self_in
;
socket_check_closed
(
socket
);
struct
net_context
*
ctx
=
k_fifo_get
(
&
SOCK_FIELD
(
socket
,
accept_q
),
K_FOREVER
)
;
// Was overwritten by fifo
ctx
->
refcount
=
1
;
struct
sockaddr
sockaddr
;
socklen_t
addrlen
=
sizeof
(
sockaddr
);
void
*
ctx
=
zsock_accept
(
socket
->
ctx
,
&
sockaddr
,
&
addrlen
)
;
socket_obj_t
*
socket2
=
socket_new
();
socket2
->
ctx
=
ctx
;
...
...
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