Rename "rawsocket" module to "microsocket".
It's no longer intended to provide just "raw" socket interface, may include some convenience methods for compatibility with CPython socket - but anyway just minimal set required to deal with socket client and servers, not wider network functionality.
This commit is contained in:
parent
0a587b85fb
commit
9945f33886
|
@ -1,5 +1,5 @@
|
||||||
try:
|
try:
|
||||||
import rawsocket as _socket
|
import microsocket as _socket
|
||||||
except:
|
except:
|
||||||
import _socket
|
import _socket
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
try:
|
try:
|
||||||
import rawsocket as socket
|
import microsocket as socket
|
||||||
except:
|
except:
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
extern const mp_obj_fun_native_t mp_builtin_open_obj;
|
extern const mp_obj_fun_native_t mp_builtin_open_obj;
|
||||||
void file_init();
|
void file_init();
|
||||||
void rawsocket_init();
|
void microsocket_init();
|
||||||
void time_init();
|
void time_init();
|
||||||
void ffi_init();
|
void ffi_init();
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ int main(int argc, char **argv) {
|
||||||
rt_store_name(qstr_from_str("qstr_info"), rt_make_function_n(0, qstr_info));
|
rt_store_name(qstr_from_str("qstr_info"), rt_make_function_n(0, qstr_info));
|
||||||
|
|
||||||
file_init();
|
file_init();
|
||||||
rawsocket_init();
|
microsocket_init();
|
||||||
#if MICROPY_MOD_TIME
|
#if MICROPY_MOD_TIME
|
||||||
time_init();
|
time_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,4 +12,4 @@ Q(htons)
|
||||||
Q(inet_aton)
|
Q(inet_aton)
|
||||||
Q(gethostbyname)
|
Q(gethostbyname)
|
||||||
Q(getaddrinfo)
|
Q(getaddrinfo)
|
||||||
Q(rawsocket)
|
Q(microsocket)
|
||||||
|
|
|
@ -24,7 +24,7 @@ typedef struct _mp_obj_socket_t {
|
||||||
int fd;
|
int fd;
|
||||||
} mp_obj_socket_t;
|
} mp_obj_socket_t;
|
||||||
|
|
||||||
static const mp_obj_type_t rawsocket_type;
|
static const mp_obj_type_t microsocket_type;
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
#define RAISE_ERRNO(err_flag, error_val) \
|
#define RAISE_ERRNO(err_flag, error_val) \
|
||||||
|
@ -48,7 +48,7 @@ error:
|
||||||
|
|
||||||
static mp_obj_socket_t *socket_new(int fd) {
|
static mp_obj_socket_t *socket_new(int fd) {
|
||||||
mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t);
|
mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t);
|
||||||
o->base.type = &rawsocket_type;
|
o->base.type = µsocket_type;
|
||||||
o->fd = fd;
|
o->fd = fd;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ static mp_obj_t socket_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
|
||||||
return socket_new(fd);
|
return socket_new(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const mp_method_t rawsocket_type_methods[] = {
|
static const mp_method_t microsocket_type_methods[] = {
|
||||||
{ "read", &mp_stream_read_obj },
|
{ "read", &mp_stream_read_obj },
|
||||||
{ "readall", &mp_stream_readall_obj },
|
{ "readall", &mp_stream_readall_obj },
|
||||||
{ "readline", &mp_stream_unbuffered_readline_obj},
|
{ "readline", &mp_stream_unbuffered_readline_obj},
|
||||||
|
@ -228,7 +228,7 @@ static const mp_method_t rawsocket_type_methods[] = {
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const mp_obj_type_t rawsocket_type = {
|
static const mp_obj_type_t microsocket_type = {
|
||||||
{ &mp_const_type },
|
{ &mp_const_type },
|
||||||
"socket",
|
"socket",
|
||||||
.print = socket_print,
|
.print = socket_print,
|
||||||
|
@ -239,7 +239,7 @@ static const mp_obj_type_t rawsocket_type = {
|
||||||
.read = socket_read,
|
.read = socket_read,
|
||||||
.write = socket_write,
|
.write = socket_write,
|
||||||
},
|
},
|
||||||
.methods = rawsocket_type_methods,
|
.methods = microsocket_type_methods,
|
||||||
};
|
};
|
||||||
|
|
||||||
static mp_obj_t mod_socket_htons(mp_obj_t arg) {
|
static mp_obj_t mod_socket_htons(mp_obj_t arg) {
|
||||||
|
@ -351,9 +351,9 @@ struct sym_entry {
|
||||||
|
|
||||||
#undef C
|
#undef C
|
||||||
|
|
||||||
void rawsocket_init() {
|
void microsocket_init() {
|
||||||
mp_obj_t m = mp_obj_new_module(MP_QSTR_rawsocket);
|
mp_obj_t m = mp_obj_new_module(MP_QSTR_microsocket);
|
||||||
rt_store_attr(m, MP_QSTR_socket, (mp_obj_t)&rawsocket_type);
|
rt_store_attr(m, MP_QSTR_socket, (mp_obj_t)µsocket_type);
|
||||||
#if MICROPY_SOCKET_EXTRA
|
#if MICROPY_SOCKET_EXTRA
|
||||||
rt_store_attr(m, MP_QSTR_sockaddr_in, (mp_obj_t)&sockaddr_in_type);
|
rt_store_attr(m, MP_QSTR_sockaddr_in, (mp_obj_t)&sockaddr_in_type);
|
||||||
rt_store_attr(m, MP_QSTR_htons, (mp_obj_t)&mod_socket_htons_obj);
|
rt_store_attr(m, MP_QSTR_htons, (mp_obj_t)&mod_socket_htons_obj);
|
||||||
|
|
Loading…
Reference in New Issue