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
06d00834
Commit
06d00834
authored
Oct 07, 2016
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/modlwip: Use mp_raise_OSError helper function.
Reduces esp8266 code size by about 230 bytes.
parent
620c4c32
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
extmod/modlwip.c
extmod/modlwip.c
+24
-24
No files found.
extmod/modlwip.c
View file @
06d00834
...
...
@@ -598,11 +598,11 @@ STATIC mp_obj_t lwip_socket_make_new(const mp_obj_type_t *type, mp_uint_t n_args
case
MOD_NETWORK_SOCK_STREAM
:
socket
->
pcb
.
tcp
=
tcp_new
();
break
;
case
MOD_NETWORK_SOCK_DGRAM
:
socket
->
pcb
.
udp
=
udp_new
();
break
;
//case MOD_NETWORK_SOCK_RAW: socket->pcb.raw = raw_new(); break;
default:
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EINVAL
))
);
default:
mp_raise_OSError
(
MP_EINVAL
);
}
if
(
socket
->
pcb
.
tcp
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_ENOMEM
))
);
mp_raise_OSError
(
MP_ENOMEM
);
}
switch
(
socket
->
type
)
{
...
...
@@ -686,7 +686,7 @@ STATIC mp_obj_t lwip_socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
}
if
(
err
!=
ERR_OK
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
error_lookup_table
[
-
err
]))
);
mp_raise_OSError
(
error_lookup_table
[
-
err
]
);
}
return
mp_const_none
;
...
...
@@ -698,15 +698,15 @@ STATIC mp_obj_t lwip_socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) {
mp_int_t
backlog
=
mp_obj_get_int
(
backlog_in
);
if
(
socket
->
pcb
.
tcp
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EBADF
))
);
mp_raise_OSError
(
MP_EBADF
);
}
if
(
socket
->
type
!=
MOD_NETWORK_SOCK_STREAM
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EOPNOTSUPP
))
);
mp_raise_OSError
(
MP_EOPNOTSUPP
);
}
struct
tcp_pcb
*
new_pcb
=
tcp_listen_with_backlog
(
socket
->
pcb
.
tcp
,
(
u8_t
)
backlog
);
if
(
new_pcb
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_ENOMEM
))
);
mp_raise_OSError
(
MP_ENOMEM
);
}
socket
->
pcb
.
tcp
=
new_pcb
;
tcp_accept
(
new_pcb
,
_lwip_tcp_accept
);
...
...
@@ -719,15 +719,15 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
lwip_socket_obj_t
*
socket
=
self_in
;
if
(
socket
->
pcb
.
tcp
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EBADF
))
);
mp_raise_OSError
(
MP_EBADF
);
}
if
(
socket
->
type
!=
MOD_NETWORK_SOCK_STREAM
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EOPNOTSUPP
))
);
mp_raise_OSError
(
MP_EOPNOTSUPP
);
}
// I need to do this because "tcp_accepted", later, is a macro.
struct
tcp_pcb
*
listener
=
socket
->
pcb
.
tcp
;
if
(
listener
->
state
!=
LISTEN
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EINVAL
))
);
mp_raise_OSError
(
MP_EINVAL
);
}
// accept incoming connection
...
...
@@ -738,7 +738,7 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
if
(
socket
->
incoming
.
connection
!=
NULL
)
break
;
}
if
(
socket
->
incoming
.
connection
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_ETIMEDOUT
))
);
mp_raise_OSError
(
MP_ETIMEDOUT
);
}
}
else
{
while
(
socket
->
incoming
.
connection
==
NULL
)
{
...
...
@@ -785,7 +785,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
lwip_socket_obj_t
*
socket
=
self_in
;
if
(
socket
->
pcb
.
tcp
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EBADF
))
);
mp_raise_OSError
(
MP_EBADF
);
}
// get address
...
...
@@ -800,9 +800,9 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
case
MOD_NETWORK_SOCK_STREAM
:
{
if
(
socket
->
state
!=
STATE_NEW
)
{
if
(
socket
->
state
==
STATE_CONNECTED
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EALREADY
))
);
mp_raise_OSError
(
MP_EALREADY
);
}
else
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EINPROGRESS
))
);
mp_raise_OSError
(
MP_EINPROGRESS
);
}
}
// Register our recieve callback.
...
...
@@ -811,7 +811,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
err
=
tcp_connect
(
socket
->
pcb
.
tcp
,
&
dest
,
port
,
_lwip_tcp_connected
);
if
(
err
!=
ERR_OK
)
{
socket
->
state
=
STATE_NEW
;
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
error_lookup_table
[
-
err
]))
);
mp_raise_OSError
(
error_lookup_table
[
-
err
]
);
}
socket
->
peer_port
=
(
mp_uint_t
)
port
;
memcpy
(
socket
->
peer
,
&
dest
,
sizeof
(
socket
->
peer
));
...
...
@@ -822,7 +822,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
if
(
socket
->
state
!=
STATE_CONNECTING
)
break
;
}
if
(
socket
->
state
==
STATE_CONNECTING
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_ETIMEDOUT
))
);
mp_raise_OSError
(
MP_ETIMEDOUT
);
}
}
else
{
while
(
socket
->
state
==
STATE_CONNECTING
)
{
...
...
@@ -843,7 +843,7 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
}
if
(
err
!=
ERR_OK
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
error_lookup_table
[
-
err
]))
);
mp_raise_OSError
(
error_lookup_table
[
-
err
]
);
}
return
mp_const_none
;
...
...
@@ -855,7 +855,7 @@ STATIC void lwip_socket_check_connected(lwip_socket_obj_t *socket) {
// not connected
int
_errno
=
error_lookup_table
[
-
socket
->
state
];
socket
->
state
=
_ERR_BADF
;
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
}
...
...
@@ -880,7 +880,7 @@ STATIC mp_obj_t lwip_socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
}
}
if
(
ret
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
return
mp_obj_new_int_from_uint
(
ret
);
...
...
@@ -909,7 +909,7 @@ STATIC mp_obj_t lwip_socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
}
}
if
(
ret
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
if
(
ret
==
0
)
{
...
...
@@ -944,7 +944,7 @@ STATIC mp_obj_t lwip_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t
}
}
if
(
ret
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
return
mp_obj_new_int_from_uint
(
ret
);
...
...
@@ -977,7 +977,7 @@ STATIC mp_obj_t lwip_socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
}
}
if
(
ret
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
mp_obj_t
tuple
[
2
];
...
...
@@ -1010,7 +1010,7 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
// most useful behavior is: check whether we will be able to send all of input
// data without EAGAIN, and if won't be, raise it without sending any.
if
(
bufinfo
.
len
>
tcp_sndbuf
(
socket
->
pcb
.
tcp
))
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EAGAIN
))
);
mp_raise_OSError
(
MP_EAGAIN
);
}
}
// TODO: In CPython3.5, socket timeout should apply to the
...
...
@@ -1018,7 +1018,7 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
while
(
bufinfo
.
len
!=
0
)
{
ret
=
lwip_tcp_send
(
socket
,
bufinfo
.
buf
,
bufinfo
.
len
,
&
_errno
);
if
(
ret
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
bufinfo
.
len
-=
ret
;
bufinfo
.
buf
=
(
char
*
)
bufinfo
.
buf
+
ret
;
...
...
@@ -1259,7 +1259,7 @@ STATIC mp_obj_t lwip_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
if
(
state
.
status
<
0
)
{
// TODO: CPython raises gaierror, we raise with native lwIP negative error
// values, to differentiate from normal errno's at least in such way.
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
state
.
status
))
);
mp_raise_OSError
(
state
.
status
);
}
mp_obj_tuple_t
*
tuple
=
mp_obj_new_tuple
(
5
,
NULL
);
...
...
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