2014-05-03 18:27:38 -04:00
|
|
|
/*
|
2017-06-30 03:22:17 -04:00
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
2014-05-03 18:27:38 -04:00
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, 2014 Damien P. George
|
2014-05-13 01:44:45 -04:00
|
|
|
* Copyright (c) 2014 Paul Sokolovsky
|
2014-05-03 18:27:38 -04:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-01-18 16:47:44 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2014-04-19 19:00:12 -04:00
|
|
|
#include <fcntl.h>
|
2014-03-16 02:24:34 -04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2014-01-18 16:47:44 -05:00
|
|
|
#include <sys/socket.h>
|
2014-03-16 02:24:34 -04:00
|
|
|
#include <netinet/in.h>
|
2014-01-18 16:47:44 -05:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2015-01-01 15:40:19 -05:00
|
|
|
#include "py/objtuple.h"
|
|
|
|
#include "py/objstr.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
#include "py/stream.h"
|
|
|
|
#include "py/builtin.h"
|
2016-10-06 23:09:59 -04:00
|
|
|
#include "py/mphal.h"
|
2014-01-18 16:47:44 -05:00
|
|
|
|
2018-08-16 17:21:44 -04:00
|
|
|
#include "supervisor/shared/translate.h"
|
|
|
|
|
2014-05-30 18:48:26 -04:00
|
|
|
/*
|
|
|
|
The idea of this module is to implement reasonable minimum of
|
|
|
|
socket-related functions to write typical clients and servers.
|
2014-10-09 13:43:10 -04:00
|
|
|
The module named "usocket" on purpose, to allow to make
|
2014-05-30 18:48:26 -04:00
|
|
|
Python-level module more (or fully) compatible with CPython
|
|
|
|
"socket", e.g.:
|
|
|
|
---- socket.py ----
|
2014-10-09 13:43:10 -04:00
|
|
|
from usocket import *
|
2014-05-30 18:48:26 -04:00
|
|
|
from socket_more_funcs import *
|
|
|
|
from socket_more_funcs2 import *
|
|
|
|
-------------------
|
|
|
|
I.e. this module should stay lean, and more functions (if needed)
|
2017-05-29 03:08:14 -04:00
|
|
|
should be add to separate modules (C or Python level).
|
2014-05-30 18:48:26 -04:00
|
|
|
*/
|
|
|
|
|
2016-08-06 18:21:42 -04:00
|
|
|
// This type must "inherit" from mp_obj_fdfile_t, i.e. matching subset of
|
|
|
|
// fields should have the same layout.
|
2014-01-18 16:47:44 -05:00
|
|
|
typedef struct _mp_obj_socket_t {
|
|
|
|
mp_obj_base_t base;
|
|
|
|
int fd;
|
|
|
|
} mp_obj_socket_t;
|
|
|
|
|
2016-08-06 18:21:42 -04:00
|
|
|
const mp_obj_type_t mp_type_socket;
|
2014-01-18 16:47:44 -05:00
|
|
|
|
|
|
|
// Helper functions
|
2015-07-13 18:46:40 -04:00
|
|
|
static inline mp_obj_t mp_obj_from_sockaddr(const struct sockaddr *addr, socklen_t len) {
|
|
|
|
return mp_obj_new_bytes((const byte *)addr, len);
|
|
|
|
}
|
|
|
|
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC mp_obj_socket_t *socket_new(int fd) {
|
2014-01-18 16:47:44 -05:00
|
|
|
mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t);
|
2016-08-06 18:21:42 -04:00
|
|
|
o->base.type = &mp_type_socket;
|
2014-01-18 16:47:44 -05:00
|
|
|
o->fd = fd;
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-09 18:56:15 -04:00
|
|
|
STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
2015-01-20 07:47:20 -05:00
|
|
|
(void)kind;
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in);
|
2015-04-09 18:56:15 -04:00
|
|
|
mp_printf(print, "<_socket %d>", self->fd);
|
2014-01-18 16:47:44 -05:00
|
|
|
}
|
|
|
|
|
2014-07-27 17:38:58 -04:00
|
|
|
STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *o = MP_OBJ_TO_PTR(o_in);
|
2014-07-03 08:25:24 -04:00
|
|
|
mp_int_t r = read(o->fd, buf, size);
|
2014-01-18 16:47:44 -05:00
|
|
|
if (r == -1) {
|
|
|
|
*errcode = errno;
|
2014-07-27 17:38:58 -04:00
|
|
|
return MP_STREAM_ERROR;
|
2014-01-18 16:47:44 -05:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-07-27 17:38:58 -04:00
|
|
|
STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *o = MP_OBJ_TO_PTR(o_in);
|
2014-07-03 08:25:24 -04:00
|
|
|
mp_int_t r = write(o->fd, buf, size);
|
2014-01-18 16:47:44 -05:00
|
|
|
if (r == -1) {
|
|
|
|
*errcode = errno;
|
2014-07-27 17:38:58 -04:00
|
|
|
return MP_STREAM_ERROR;
|
2014-01-18 16:47:44 -05:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-03-07 01:48:53 -05:00
|
|
|
STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(o_in);
|
|
|
|
(void)arg;
|
|
|
|
switch (request) {
|
|
|
|
case MP_STREAM_CLOSE:
|
|
|
|
// There's a POSIX drama regarding return value of close in general,
|
|
|
|
// and EINTR error in particular. See e.g.
|
|
|
|
// http://lwn.net/Articles/576478/
|
|
|
|
// http://austingroupbugs.net/view.php?id=529
|
|
|
|
// The rationale MicroPython follows is that close() just releases
|
|
|
|
// file descriptor. If you're interested to catch I/O errors before
|
|
|
|
// closing fd, fsync() it.
|
|
|
|
close(self->fd);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*errcode = MP_EINVAL;
|
|
|
|
return MP_STREAM_ERROR;
|
|
|
|
}
|
2014-01-18 16:47:44 -05:00
|
|
|
}
|
|
|
|
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC mp_obj_t socket_fileno(mp_obj_t self_in) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in);
|
2014-07-31 05:49:14 -04:00
|
|
|
return MP_OBJ_NEW_SMALL_INT(self->fd);
|
2014-02-08 14:15:46 -05:00
|
|
|
}
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno);
|
2014-02-08 14:15:46 -05:00
|
|
|
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in);
|
2014-04-18 17:31:24 -04:00
|
|
|
mp_buffer_info_t bufinfo;
|
2014-04-18 17:59:24 -04:00
|
|
|
mp_get_buffer_raise(addr_in, &bufinfo, MP_BUFFER_READ);
|
2014-01-18 16:47:44 -05:00
|
|
|
int r = connect(self->fd, (const struct sockaddr *)bufinfo.buf, bufinfo.len);
|
|
|
|
RAISE_ERRNO(r, errno);
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
|
2014-01-18 16:47:44 -05:00
|
|
|
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in);
|
2014-04-18 17:31:24 -04:00
|
|
|
mp_buffer_info_t bufinfo;
|
2014-04-18 17:59:24 -04:00
|
|
|
mp_get_buffer_raise(addr_in, &bufinfo, MP_BUFFER_READ);
|
2014-01-18 16:47:44 -05:00
|
|
|
int r = bind(self->fd, (const struct sockaddr *)bufinfo.buf, bufinfo.len);
|
|
|
|
RAISE_ERRNO(r, errno);
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
|
2014-01-18 16:47:44 -05:00
|
|
|
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in);
|
2014-01-18 16:47:44 -05:00
|
|
|
int r = listen(self->fd, MP_OBJ_SMALL_INT_VALUE(backlog_in));
|
|
|
|
RAISE_ERRNO(r, errno);
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen);
|
2014-01-18 16:47:44 -05:00
|
|
|
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in);
|
2016-01-21 16:53:47 -05:00
|
|
|
// sockaddr_storage isn't stack-friendly (129 bytes or so)
|
|
|
|
//struct sockaddr_storage addr;
|
|
|
|
byte addr[32];
|
2014-01-18 16:47:44 -05:00
|
|
|
socklen_t addr_len = sizeof(addr);
|
2016-01-21 16:53:47 -05:00
|
|
|
int fd = accept(self->fd, (struct sockaddr*)&addr, &addr_len);
|
2014-01-18 16:47:44 -05:00
|
|
|
RAISE_ERRNO(fd, errno);
|
|
|
|
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
|
|
|
|
t->items[0] = MP_OBJ_FROM_PTR(socket_new(fd));
|
2014-01-18 16:47:44 -05:00
|
|
|
t->items[1] = mp_obj_new_bytearray(addr_len, &addr);
|
|
|
|
|
2015-11-27 12:01:44 -05:00
|
|
|
return MP_OBJ_FROM_PTR(t);
|
2014-01-18 16:47:44 -05:00
|
|
|
}
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
|
2014-01-18 16:47:44 -05:00
|
|
|
|
2014-05-06 18:51:35 -04:00
|
|
|
// Note: besides flag param, this differs from read() in that
|
|
|
|
// this does not swallow blocking errors (EAGAIN, EWOULDBLOCK) -
|
|
|
|
// these would be thrown as exceptions.
|
2016-01-03 09:21:40 -05:00
|
|
|
STATIC mp_obj_t socket_recv(size_t n_args, const mp_obj_t *args) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
|
2014-01-20 12:42:39 -05:00
|
|
|
int sz = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (n_args > 2) {
|
|
|
|
flags = MP_OBJ_SMALL_INT_VALUE(args[2]);
|
|
|
|
}
|
|
|
|
|
2014-08-10 14:20:40 -04:00
|
|
|
byte *buf = m_new(byte, sz);
|
2014-01-20 12:42:39 -05:00
|
|
|
int out_sz = recv(self->fd, buf, sz, flags);
|
|
|
|
RAISE_ERRNO(out_sz, errno);
|
|
|
|
|
2014-08-10 14:20:40 -04:00
|
|
|
mp_obj_t ret = mp_obj_new_str_of_type(&mp_type_bytes, buf, out_sz);
|
2014-05-25 17:27:57 -04:00
|
|
|
m_del(char, buf, sz);
|
|
|
|
return ret;
|
2014-01-20 12:42:39 -05:00
|
|
|
}
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_obj, 2, 3, socket_recv);
|
2014-01-20 12:42:39 -05:00
|
|
|
|
2016-01-03 09:21:40 -05:00
|
|
|
STATIC mp_obj_t socket_recvfrom(size_t n_args, const mp_obj_t *args) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
|
2015-07-13 18:46:40 -04:00
|
|
|
int sz = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (n_args > 2) {
|
|
|
|
flags = MP_OBJ_SMALL_INT_VALUE(args[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sockaddr_storage addr;
|
|
|
|
socklen_t addr_len = sizeof(addr);
|
|
|
|
|
|
|
|
byte *buf = m_new(byte, sz);
|
|
|
|
int out_sz = recvfrom(self->fd, buf, sz, flags, (struct sockaddr*)&addr, &addr_len);
|
|
|
|
RAISE_ERRNO(out_sz, errno);
|
|
|
|
|
|
|
|
mp_obj_t buf_o = mp_obj_new_str_of_type(&mp_type_bytes, buf, out_sz);
|
|
|
|
m_del(char, buf, sz);
|
|
|
|
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
|
2015-07-13 18:46:40 -04:00
|
|
|
t->items[0] = buf_o;
|
|
|
|
t->items[1] = mp_obj_from_sockaddr((struct sockaddr*)&addr, addr_len);
|
|
|
|
|
2015-11-27 12:01:44 -05:00
|
|
|
return MP_OBJ_FROM_PTR(t);
|
2015-07-13 18:46:40 -04:00
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recvfrom_obj, 2, 3, socket_recvfrom);
|
|
|
|
|
2014-05-06 18:51:35 -04:00
|
|
|
// Note: besides flag param, this differs from write() in that
|
|
|
|
// this does not swallow blocking errors (EAGAIN, EWOULDBLOCK) -
|
|
|
|
// these would be thrown as exceptions.
|
2016-01-03 09:21:40 -05:00
|
|
|
STATIC mp_obj_t socket_send(size_t n_args, const mp_obj_t *args) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
|
2014-01-20 12:42:39 -05:00
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (n_args > 2) {
|
|
|
|
flags = MP_OBJ_SMALL_INT_VALUE(args[2]);
|
|
|
|
}
|
|
|
|
|
2014-04-25 22:53:02 -04:00
|
|
|
mp_buffer_info_t bufinfo;
|
|
|
|
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
|
|
|
|
int out_sz = send(self->fd, bufinfo.buf, bufinfo.len, flags);
|
2014-01-20 12:42:39 -05:00
|
|
|
RAISE_ERRNO(out_sz, errno);
|
|
|
|
|
2014-07-31 05:49:14 -04:00
|
|
|
return MP_OBJ_NEW_SMALL_INT(out_sz);
|
2014-01-20 12:42:39 -05:00
|
|
|
}
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send);
|
2014-01-20 12:42:39 -05:00
|
|
|
|
2016-01-03 09:21:40 -05:00
|
|
|
STATIC mp_obj_t socket_sendto(size_t n_args, const mp_obj_t *args) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
|
2015-07-12 06:51:55 -04:00
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
mp_obj_t dst_addr = args[2];
|
|
|
|
if (n_args > 3) {
|
|
|
|
flags = MP_OBJ_SMALL_INT_VALUE(args[2]);
|
|
|
|
dst_addr = args[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_buffer_info_t bufinfo, addr_bi;
|
|
|
|
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
|
|
|
|
mp_get_buffer_raise(dst_addr, &addr_bi, MP_BUFFER_READ);
|
|
|
|
int out_sz = sendto(self->fd, bufinfo.buf, bufinfo.len, flags,
|
|
|
|
(struct sockaddr *)addr_bi.buf, addr_bi.len);
|
|
|
|
RAISE_ERRNO(out_sz, errno);
|
|
|
|
|
|
|
|
return MP_OBJ_NEW_SMALL_INT(out_sz);
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_sendto_obj, 3, 4, socket_sendto);
|
|
|
|
|
2016-01-03 09:21:40 -05:00
|
|
|
STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
2015-01-20 07:47:20 -05:00
|
|
|
(void)n_args; // always 4
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
|
2014-01-25 18:59:52 -05:00
|
|
|
int level = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
|
|
|
int option = mp_obj_get_int(args[2]);
|
|
|
|
|
|
|
|
const void *optval;
|
|
|
|
socklen_t optlen;
|
2015-10-10 07:59:26 -04:00
|
|
|
int val;
|
2014-01-25 18:59:52 -05:00
|
|
|
if (MP_OBJ_IS_INT(args[3])) {
|
2015-10-10 07:59:26 -04:00
|
|
|
val = mp_obj_int_get_truncated(args[3]);
|
2014-01-25 18:59:52 -05:00
|
|
|
optval = &val;
|
|
|
|
optlen = sizeof(val);
|
|
|
|
} else {
|
2014-04-18 17:31:24 -04:00
|
|
|
mp_buffer_info_t bufinfo;
|
2014-04-18 17:59:24 -04:00
|
|
|
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
|
2014-01-25 18:59:52 -05:00
|
|
|
optval = bufinfo.buf;
|
|
|
|
optlen = bufinfo.len;
|
|
|
|
}
|
|
|
|
int r = setsockopt(self->fd, level, option, optval, optlen);
|
|
|
|
RAISE_ERRNO(r, errno);
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
2014-04-04 13:25:53 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt);
|
2014-01-25 18:59:52 -05:00
|
|
|
|
2014-04-19 19:00:12 -04:00
|
|
|
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(self_in);
|
2014-04-19 19:00:12 -04:00
|
|
|
int val = mp_obj_is_true(flag_in);
|
|
|
|
int flags = fcntl(self->fd, F_GETFL, 0);
|
|
|
|
RAISE_ERRNO(flags, errno);
|
|
|
|
if (val) {
|
|
|
|
flags &= ~O_NONBLOCK;
|
|
|
|
} else {
|
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
}
|
|
|
|
flags = fcntl(self->fd, F_SETFL, flags);
|
|
|
|
RAISE_ERRNO(flags, errno);
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
|
|
|
|
|
2016-01-03 09:21:40 -05:00
|
|
|
STATIC mp_obj_t socket_makefile(size_t n_args, const mp_obj_t *args) {
|
2014-05-24 14:24:37 -04:00
|
|
|
// TODO: CPython explicitly says that closing returned object doesn't close
|
|
|
|
// the original socket (Python2 at all says that fd is dup()ed). But we
|
|
|
|
// save on the bloat.
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_socket_t *self = MP_OBJ_TO_PTR(args[0]);
|
2014-05-24 14:24:37 -04:00
|
|
|
mp_obj_t *new_args = alloca(n_args * sizeof(mp_obj_t));
|
|
|
|
memcpy(new_args + 1, args + 1, (n_args - 1) * sizeof(mp_obj_t));
|
2014-07-31 05:49:14 -04:00
|
|
|
new_args[0] = MP_OBJ_NEW_SMALL_INT(self->fd);
|
2016-04-04 16:43:16 -04:00
|
|
|
return mp_builtin_open(n_args, new_args, (mp_map_t*)&mp_const_empty_map);
|
2014-05-24 14:24:37 -04:00
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_makefile);
|
|
|
|
|
2019-01-18 14:53:09 -05:00
|
|
|
STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
2015-01-20 07:47:20 -05:00
|
|
|
(void)type_in;
|
2019-01-18 14:53:09 -05:00
|
|
|
(void)kw_args;
|
2015-01-20 07:47:20 -05:00
|
|
|
|
2014-01-18 16:47:44 -05:00
|
|
|
int family = AF_INET;
|
|
|
|
int type = SOCK_STREAM;
|
|
|
|
int proto = 0;
|
|
|
|
|
|
|
|
if (n_args > 0) {
|
|
|
|
assert(MP_OBJ_IS_SMALL_INT(args[0]));
|
|
|
|
family = MP_OBJ_SMALL_INT_VALUE(args[0]);
|
|
|
|
if (n_args > 1) {
|
|
|
|
assert(MP_OBJ_IS_SMALL_INT(args[1]));
|
|
|
|
type = MP_OBJ_SMALL_INT_VALUE(args[1]);
|
|
|
|
if (n_args > 2) {
|
|
|
|
assert(MP_OBJ_IS_SMALL_INT(args[2]));
|
|
|
|
proto = MP_OBJ_SMALL_INT_VALUE(args[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int fd = socket(family, type, proto);
|
|
|
|
RAISE_ERRNO(fd, errno);
|
2015-11-27 12:01:44 -05:00
|
|
|
return MP_OBJ_FROM_PTR(socket_new(fd));
|
2014-01-18 16:47:44 -05:00
|
|
|
}
|
|
|
|
|
2015-11-27 08:38:15 -05:00
|
|
|
STATIC const mp_rom_map_elem_t usocket_locals_dict_table[] = {
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_fileno), MP_ROM_PTR(&socket_fileno_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&socket_makefile_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&socket_connect_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&socket_bind_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_listen), MP_ROM_PTR(&socket_listen_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&socket_accept_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&socket_recv_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_recvfrom), MP_ROM_PTR(&socket_recvfrom_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&socket_send_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socket_sendto_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socket_setsockopt_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
|
2018-03-07 01:48:53 -05:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
2014-01-18 16:47:44 -05:00
|
|
|
};
|
|
|
|
|
2014-10-09 13:43:10 -04:00
|
|
|
STATIC MP_DEFINE_CONST_DICT(usocket_locals_dict, usocket_locals_dict_table);
|
2014-03-26 17:47:19 -04:00
|
|
|
|
2014-10-09 13:43:10 -04:00
|
|
|
STATIC const mp_stream_p_t usocket_stream_p = {
|
protocols: Allow them to be (optionally) type-safe
Protocols are nice, but there is no way for C code to verify whether
a type's "protocol" structure actually implements some particular
protocol. As a result, you can pass an object that implements the
"vfs" protocol to one that expects the "stream" protocol, and the
opposite of awesomeness ensues.
This patch adds an OPTIONAL (but enabled by default) protocol identifier
as the first member of any protocol structure. This identifier is
simply a unique QSTR chosen by the protocol designer and used by each
protocol implementer. When checking for protocol support, instead of
just checking whether the object's type has a non-NULL protocol field,
use `mp_proto_get` which implements the protocol check when possible.
The existing protocols are now named:
protocol_framebuf
protocol_i2c
protocol_pin
protocol_stream
protocol_spi
protocol_vfs
(most of these are unused in CP and are just inherited from MP; vfs and
stream are definitely used though)
I did not find any crashing examples, but here's one to give a flavor of what
is improved, using `micropython_coverage`. Before the change,
the vfs "ioctl" protocol is invoked, and the result is not intelligible
as json (but it could have resulted in a hard fault, potentially):
>>> import uos, ujson
>>> u = uos.VfsPosix('/tmp')
>>> ujson.load(u)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: syntax error in JSON
After the change, the vfs object is correctly detected as not supporting
the stream protocol:
>>> ujson.load(p)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: stream operation not supported
2019-12-03 15:50:37 -05:00
|
|
|
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
2014-04-05 18:02:23 -04:00
|
|
|
.read = socket_read,
|
|
|
|
.write = socket_write,
|
2018-03-07 01:48:53 -05:00
|
|
|
.ioctl = socket_ioctl,
|
2014-04-05 18:02:23 -04:00
|
|
|
};
|
|
|
|
|
2016-08-06 18:21:42 -04:00
|
|
|
const mp_obj_type_t mp_type_socket = {
|
2014-02-15 11:10:44 -05:00
|
|
|
{ &mp_type_type },
|
2014-02-15 06:34:50 -05:00
|
|
|
.name = MP_QSTR_socket,
|
2014-01-18 16:47:44 -05:00
|
|
|
.print = socket_print,
|
|
|
|
.make_new = socket_make_new,
|
|
|
|
.getiter = NULL,
|
|
|
|
.iternext = NULL,
|
2016-06-18 11:19:24 -04:00
|
|
|
.protocol = &usocket_stream_p,
|
2015-11-27 12:01:44 -05:00
|
|
|
.locals_dict = (mp_obj_dict_t*)&usocket_locals_dict,
|
2014-01-18 16:47:44 -05:00
|
|
|
};
|
|
|
|
|
2015-07-14 17:05:49 -04:00
|
|
|
#define BINADDR_MAX_LEN sizeof(struct in6_addr)
|
|
|
|
STATIC mp_obj_t mod_socket_inet_pton(mp_obj_t family_in, mp_obj_t addr_in) {
|
|
|
|
int family = mp_obj_get_int(family_in);
|
|
|
|
byte binaddr[BINADDR_MAX_LEN];
|
|
|
|
int r = inet_pton(family, mp_obj_str_get_str(addr_in), binaddr);
|
|
|
|
RAISE_ERRNO(r, errno);
|
|
|
|
if (r == 0) {
|
2016-10-06 23:05:15 -04:00
|
|
|
mp_raise_OSError(MP_EINVAL);
|
2015-07-14 17:05:49 -04:00
|
|
|
}
|
|
|
|
int binaddr_len = 0;
|
|
|
|
switch (family) {
|
|
|
|
case AF_INET:
|
|
|
|
binaddr_len = sizeof(struct in_addr);
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
binaddr_len = sizeof(struct in6_addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return mp_obj_new_bytes(binaddr, binaddr_len);
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_inet_pton_obj, mod_socket_inet_pton);
|
|
|
|
|
2016-01-11 00:37:59 -05:00
|
|
|
STATIC mp_obj_t mod_socket_inet_ntop(mp_obj_t family_in, mp_obj_t binaddr_in) {
|
|
|
|
int family = mp_obj_get_int(family_in);
|
|
|
|
mp_buffer_info_t bufinfo;
|
|
|
|
mp_get_buffer_raise(binaddr_in, &bufinfo, MP_BUFFER_READ);
|
|
|
|
vstr_t vstr;
|
|
|
|
vstr_init_len(&vstr, family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN);
|
|
|
|
if (inet_ntop(family, bufinfo.buf, vstr.buf, vstr.len) == NULL) {
|
2016-10-06 23:05:15 -04:00
|
|
|
mp_raise_OSError(errno);
|
2016-01-11 00:37:59 -05:00
|
|
|
}
|
|
|
|
vstr.len = strlen(vstr.buf);
|
|
|
|
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_inet_ntop_obj, mod_socket_inet_ntop);
|
|
|
|
|
2016-01-03 09:21:40 -05:00
|
|
|
STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
2017-07-11 21:43:35 -04:00
|
|
|
// TODO: Implement 5th and 6th args
|
2014-01-18 16:47:44 -05:00
|
|
|
|
2014-01-22 09:35:10 -05:00
|
|
|
const char *host = mp_obj_str_get_str(args[0]);
|
2014-01-18 16:47:44 -05:00
|
|
|
const char *serv = NULL;
|
2014-06-22 12:14:12 -04:00
|
|
|
struct addrinfo hints;
|
2015-10-10 07:59:26 -04:00
|
|
|
char buf[6];
|
2014-06-22 12:14:12 -04:00
|
|
|
memset(&hints, 0, sizeof(hints));
|
2014-01-18 16:47:44 -05:00
|
|
|
// getaddrinfo accepts port in string notation, so however
|
|
|
|
// it may seem stupid, we need to convert int to str
|
|
|
|
if (MP_OBJ_IS_SMALL_INT(args[1])) {
|
2015-07-10 17:05:46 -04:00
|
|
|
unsigned port = (unsigned short)MP_OBJ_SMALL_INT_VALUE(args[1]);
|
2015-11-21 10:17:25 -05:00
|
|
|
snprintf(buf, sizeof(buf), "%u", port);
|
2014-01-18 16:47:44 -05:00
|
|
|
serv = buf;
|
2014-06-22 12:14:12 -04:00
|
|
|
hints.ai_flags = AI_NUMERICSERV;
|
2014-06-24 14:20:38 -04:00
|
|
|
#ifdef __UCLIBC_MAJOR__
|
2014-06-22 12:14:12 -04:00
|
|
|
#if __UCLIBC_MAJOR__ == 0 && (__UCLIBC_MINOR__ < 9 || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32))
|
2014-09-06 12:46:52 -04:00
|
|
|
// "warning" requires -Wno-cpp which is a relatively new gcc option, so we choose not to use it.
|
|
|
|
//#warning Working around uClibc bug with numeric service name
|
2014-06-22 12:14:12 -04:00
|
|
|
// Older versions og uClibc have bugs when numeric ports in service
|
|
|
|
// arg require also hints.ai_socktype (or hints.ai_protocol) != 0
|
|
|
|
// This actually was fixed in 0.9.32.1, but uClibc doesn't allow to
|
|
|
|
// test for that.
|
|
|
|
// http://git.uclibc.org/uClibc/commit/libc/inet/getaddrinfo.c?id=bc3be18145e4d5
|
|
|
|
// Note that this is crude workaround, precluding UDP socket addresses
|
|
|
|
// to be returned. TODO: set only if not set by Python args.
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
2014-06-24 14:20:38 -04:00
|
|
|
#endif
|
2014-06-22 12:14:12 -04:00
|
|
|
#endif
|
2014-01-18 16:47:44 -05:00
|
|
|
} else {
|
2014-01-22 09:35:10 -05:00
|
|
|
serv = mp_obj_str_get_str(args[1]);
|
2014-01-18 16:47:44 -05:00
|
|
|
}
|
|
|
|
|
2015-07-09 18:48:12 -04:00
|
|
|
if (n_args > 2) {
|
|
|
|
hints.ai_family = MP_OBJ_SMALL_INT_VALUE(args[2]);
|
|
|
|
if (n_args > 3) {
|
|
|
|
hints.ai_socktype = MP_OBJ_SMALL_INT_VALUE(args[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 12:11:34 -04:00
|
|
|
struct addrinfo *addr_list;
|
2014-06-22 12:14:12 -04:00
|
|
|
int res = getaddrinfo(host, serv, &hints, &addr_list);
|
2014-01-18 16:47:44 -05:00
|
|
|
|
|
|
|
if (res != 0) {
|
2014-04-21 16:58:39 -04:00
|
|
|
// CPython: socket.gaierror
|
2018-08-16 17:21:44 -04:00
|
|
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, translate("[addrinfo error %d]"), res));
|
2014-01-18 16:47:44 -05:00
|
|
|
}
|
2014-06-22 12:11:34 -04:00
|
|
|
assert(addr_list);
|
2014-01-18 16:47:44 -05:00
|
|
|
|
2014-03-31 11:28:13 -04:00
|
|
|
mp_obj_t list = mp_obj_new_list(0, NULL);
|
2014-06-22 12:11:34 -04:00
|
|
|
for (struct addrinfo *addr = addr_list; addr; addr = addr->ai_next) {
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(5, NULL));
|
2014-07-31 05:49:14 -04:00
|
|
|
t->items[0] = MP_OBJ_NEW_SMALL_INT(addr->ai_family);
|
|
|
|
t->items[1] = MP_OBJ_NEW_SMALL_INT(addr->ai_socktype);
|
|
|
|
t->items[2] = MP_OBJ_NEW_SMALL_INT(addr->ai_protocol);
|
2014-01-18 16:47:44 -05:00
|
|
|
// "canonname will be a string representing the canonical name of the host
|
|
|
|
// if AI_CANONNAME is part of the flags argument; else canonname will be empty." ??
|
|
|
|
if (addr->ai_canonname) {
|
2014-01-21 16:40:13 -05:00
|
|
|
t->items[3] = MP_OBJ_NEW_QSTR(qstr_from_str(addr->ai_canonname));
|
2014-01-18 16:47:44 -05:00
|
|
|
} else {
|
|
|
|
t->items[3] = mp_const_none;
|
|
|
|
}
|
|
|
|
t->items[4] = mp_obj_new_bytearray(addr->ai_addrlen, addr->ai_addr);
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_list_append(list, MP_OBJ_FROM_PTR(t));
|
2014-01-18 16:47:44 -05:00
|
|
|
}
|
2014-06-22 12:11:34 -04:00
|
|
|
freeaddrinfo(addr_list);
|
2014-01-18 16:47:44 -05:00
|
|
|
return list;
|
|
|
|
}
|
2017-07-11 21:43:35 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 4, mod_socket_getaddrinfo);
|
2014-01-18 16:47:44 -05:00
|
|
|
|
2015-11-20 18:38:59 -05:00
|
|
|
STATIC mp_obj_t mod_socket_sockaddr(mp_obj_t sockaddr_in) {
|
|
|
|
mp_buffer_info_t bufinfo;
|
|
|
|
mp_get_buffer_raise(sockaddr_in, &bufinfo, MP_BUFFER_READ);
|
|
|
|
switch (((struct sockaddr*)bufinfo.buf)->sa_family) {
|
|
|
|
case AF_INET: {
|
|
|
|
struct sockaddr_in *sa = (struct sockaddr_in*)bufinfo.buf;
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
2015-11-20 18:38:59 -05:00
|
|
|
t->items[0] = MP_OBJ_NEW_SMALL_INT(AF_INET);
|
|
|
|
t->items[1] = mp_obj_new_bytes((byte*)&sa->sin_addr, sizeof(sa->sin_addr));
|
|
|
|
t->items[2] = MP_OBJ_NEW_SMALL_INT(ntohs(sa->sin_port));
|
2015-11-27 12:01:44 -05:00
|
|
|
return MP_OBJ_FROM_PTR(t);
|
2015-11-20 18:38:59 -05:00
|
|
|
}
|
2016-01-27 10:23:57 -05:00
|
|
|
case AF_INET6: {
|
|
|
|
struct sockaddr_in6 *sa = (struct sockaddr_in6*)bufinfo.buf;
|
|
|
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(5, NULL));
|
|
|
|
t->items[0] = MP_OBJ_NEW_SMALL_INT(AF_INET6);
|
|
|
|
t->items[1] = mp_obj_new_bytes((byte*)&sa->sin6_addr, sizeof(sa->sin6_addr));
|
|
|
|
t->items[2] = MP_OBJ_NEW_SMALL_INT(ntohs(sa->sin6_port));
|
|
|
|
t->items[3] = MP_OBJ_NEW_SMALL_INT(ntohl(sa->sin6_flowinfo));
|
|
|
|
t->items[4] = MP_OBJ_NEW_SMALL_INT(ntohl(sa->sin6_scope_id));
|
|
|
|
return MP_OBJ_FROM_PTR(t);
|
|
|
|
}
|
2015-11-20 18:38:59 -05:00
|
|
|
default: {
|
|
|
|
struct sockaddr *sa = (struct sockaddr*)bufinfo.buf;
|
2015-11-27 12:01:44 -05:00
|
|
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
|
2015-11-20 18:38:59 -05:00
|
|
|
t->items[0] = MP_OBJ_NEW_SMALL_INT(sa->sa_family);
|
|
|
|
t->items[1] = mp_obj_new_bytes((byte*)sa->sa_data, bufinfo.len - offsetof(struct sockaddr, sa_data));
|
2015-11-27 12:01:44 -05:00
|
|
|
return MP_OBJ_FROM_PTR(t);
|
2015-11-20 18:38:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_sockaddr_obj, mod_socket_sockaddr);
|
|
|
|
|
2015-11-27 08:38:15 -05:00
|
|
|
STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = {
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) },
|
2016-08-06 18:21:42 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_type_socket) },
|
2015-11-27 08:38:15 -05:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_socket_getaddrinfo_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_inet_pton), MP_ROM_PTR(&mod_socket_inet_pton_obj) },
|
2016-01-11 00:37:59 -05:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_inet_ntop), MP_ROM_PTR(&mod_socket_inet_ntop_obj) },
|
2015-11-27 08:38:15 -05:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_sockaddr), MP_ROM_PTR(&mod_socket_sockaddr_obj) },
|
2014-01-25 13:13:17 -05:00
|
|
|
|
2015-11-27 08:38:15 -05:00
|
|
|
#define C(name) { MP_ROM_QSTR(MP_QSTR_ ## name), MP_ROM_INT(name) }
|
2014-01-25 13:13:17 -05:00
|
|
|
C(AF_UNIX),
|
|
|
|
C(AF_INET),
|
|
|
|
C(AF_INET6),
|
|
|
|
C(SOCK_STREAM),
|
|
|
|
C(SOCK_DGRAM),
|
|
|
|
C(SOCK_RAW),
|
2014-01-25 13:31:34 -05:00
|
|
|
|
|
|
|
C(MSG_DONTROUTE),
|
|
|
|
C(MSG_DONTWAIT),
|
|
|
|
|
|
|
|
C(SOL_SOCKET),
|
|
|
|
C(SO_BROADCAST),
|
|
|
|
C(SO_ERROR),
|
|
|
|
C(SO_KEEPALIVE),
|
|
|
|
C(SO_LINGER),
|
|
|
|
C(SO_REUSEADDR),
|
2014-04-17 13:34:04 -04:00
|
|
|
#undef C
|
2014-01-25 13:13:17 -05:00
|
|
|
};
|
|
|
|
|
2014-11-29 09:39:27 -05:00
|
|
|
STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_table);
|
2014-01-18 16:47:44 -05:00
|
|
|
|
2014-04-17 13:34:04 -04:00
|
|
|
const mp_obj_module_t mp_module_socket = {
|
|
|
|
.base = { &mp_type_module },
|
|
|
|
.globals = (mp_obj_dict_t*)&mp_module_socket_globals,
|
|
|
|
};
|