Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
5bd56fbf
Commit
5bd56fbf
authored
Jan 26, 2014
by
Damien George
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:micropython/micropython
parents
75abee20
4795c58f
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
examples/unix/sock-server.py
+1
-0
1 addition, 0 deletions
examples/unix/sock-server.py
py/obj.h
+1
-0
1 addition, 0 deletions
py/obj.h
py/objfun.c
+1
-1
1 addition, 1 deletion
py/objfun.c
unix/socket.c
+54
-7
54 additions, 7 deletions
unix/socket.c
with
57 additions
and
8 deletions
examples/unix/sock-server.py
+
1
−
0
View file @
5bd56fbf
...
...
@@ -16,6 +16,7 @@ ai = socket.getaddrinfo("127.0.0.1", 8080)
print
(
"
Bind address info:
"
,
ai
)
addr
=
ai
[
0
][
4
]
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
s
.
bind
(
addr
)
s
.
listen
(
5
)
print
(
"
Listening, connect your browser to http://127.0.0.1:8080/
"
)
...
...
This diff is collapsed.
Click to expand it.
py/obj.h
+
1
−
0
View file @
5bd56fbf
...
...
@@ -40,6 +40,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#define MP_OBJ_IS_QSTR(o) ((((mp_small_int_t)(o)) & 3) == 2)
#define MP_OBJ_IS_OBJ(o) ((((mp_small_int_t)(o)) & 3) == 0)
#define MP_OBJ_IS_TYPE(o, t) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))) // this does not work for checking a string, use below macro for that
#define MP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &int_type))
#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &str_type))
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_small_int_t)(o)) >> 1)
...
...
This diff is collapsed.
Click to expand it.
py/objfun.c
+
1
−
1
View file @
5bd56fbf
...
...
@@ -63,7 +63,7 @@ mp_obj_t fun_native_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_
return
res
;
}
else
if
(
self
->
n_args_min
==
self
->
n_args_max
)
{
}
else
if
(
self
->
n_args_min
<=
3
&&
self
->
n_args_min
==
self
->
n_args_max
)
{
// function requires a fixed number of arguments
// dispatch function call
...
...
This diff is collapsed.
Click to expand it.
unix/socket.c
+
54
−
7
View file @
5bd56fbf
...
...
@@ -162,6 +162,29 @@ static mp_obj_t socket_send(uint n_args, const mp_obj_t *args) {
}
static
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
socket_send_obj
,
2
,
3
,
socket_send
);
static
mp_obj_t
socket_setsockopt
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_socket_t
*
self
=
args
[
0
];
int
level
=
MP_OBJ_SMALL_INT_VALUE
(
args
[
1
]);
int
option
=
mp_obj_get_int
(
args
[
2
]);
const
void
*
optval
;
socklen_t
optlen
;
if
(
MP_OBJ_IS_INT
(
args
[
3
]))
{
int
val
=
mp_obj_int_get
(
args
[
3
]);
optval
=
&
val
;
optlen
=
sizeof
(
val
);
}
else
{
buffer_info_t
bufinfo
;
get_buffer
(
args
[
3
],
&
bufinfo
);
optval
=
bufinfo
.
buf
;
optlen
=
bufinfo
.
len
;
}
int
r
=
setsockopt
(
self
->
fd
,
level
,
option
,
optval
,
optlen
);
RAISE_ERRNO
(
r
,
errno
);
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
socket_setsockopt_obj
,
4
,
4
,
socket_setsockopt
);
static
mp_obj_t
socket_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
int
family
=
AF_INET
;
int
type
=
SOCK_STREAM
;
...
...
@@ -196,6 +219,7 @@ static const mp_method_t rawsocket_type_methods[] = {
{
"accept"
,
&
socket_accept_obj
},
{
"recv"
,
&
socket_recv_obj
},
{
"send"
,
&
socket_send_obj
},
{
"setsockopt"
,
&
socket_setsockopt_obj
},
{
"close"
,
&
socket_close_obj
},
#if MICROPY_SOCKET_EXTRA
{
"recv"
,
&
mp_stream_read_obj
},
...
...
@@ -299,7 +323,33 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod
extern
mp_obj_type_t
sockaddr_in_type
;
#define STORE_INT_CONST(m, name) rt_store_attr(m, QSTR_FROM_STR_STATIC(#name), MP_OBJ_NEW_SMALL_INT(name))
#define C(name) { #name, name }
struct
sym_entry
{
const
char
*
sym
;
int
val
;
}
constants
[]
=
{
C
(
AF_UNIX
),
C
(
AF_INET
),
C
(
AF_INET6
),
C
(
SOCK_STREAM
),
C
(
SOCK_DGRAM
),
C
(
SOCK_RAW
),
C
(
MSG_DONTROUTE
),
C
(
MSG_DONTWAIT
),
C
(
SOL_SOCKET
),
C
(
SO_BROADCAST
),
C
(
SO_ERROR
),
C
(
SO_KEEPALIVE
),
C
(
SO_LINGER
),
C
(
SO_REUSEADDR
),
{
NULL
}
};
#undef C
void
rawsocket_init
()
{
mp_obj_t
m
=
mp_obj_new_module
(
MP_QSTR_rawsocket
);
...
...
@@ -311,10 +361,7 @@ void rawsocket_init() {
rt_store_attr
(
m
,
MP_QSTR_gethostbyname
,
(
mp_obj_t
)
&
mod_socket_gethostbyname_obj
);
#endif
rt_store_attr
(
m
,
MP_QSTR_getaddrinfo
,
(
mp_obj_t
)
&
mod_socket_getaddrinfo_obj
);
STORE_INT_CONST
(
m
,
AF_UNIX
);
STORE_INT_CONST
(
m
,
AF_INET
);
STORE_INT_CONST
(
m
,
AF_INET6
);
STORE_INT_CONST
(
m
,
SOCK_STREAM
);
STORE_INT_CONST
(
m
,
SOCK_DGRAM
);
STORE_INT_CONST
(
m
,
SOCK_RAW
);
for
(
struct
sym_entry
*
p
=
constants
;
p
->
sym
!=
NULL
;
p
++
)
{
rt_store_attr
(
m
,
QSTR_FROM_STR_STATIC
(
p
->
sym
),
MP_OBJ_NEW_SMALL_INT
(
p
->
val
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment