Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <assert.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
| 5 | #include <sys/socket.h> |
| 6 | #include <arpa/inet.h> |
| 7 | #include <netdb.h> |
| 8 | #include <errno.h> |
| 9 | |
| 10 | #include "nlr.h" |
| 11 | #include "misc.h" |
| 12 | #include "mpconfig.h" |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 13 | #include "qstr.h" |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 14 | #include "obj.h" |
| 15 | #include "objtuple.h" |
| 16 | #include "objarray.h" |
| 17 | #include "runtime.h" |
| 18 | #include "stream.h" |
| 19 | |
| 20 | #define MICROPY_SOCKET_EXTRA (0) |
| 21 | |
| 22 | typedef struct _mp_obj_socket_t { |
| 23 | mp_obj_base_t base; |
| 24 | int fd; |
| 25 | } mp_obj_socket_t; |
| 26 | |
Paul Sokolovsky | 9945f33 | 2014-02-08 21:10:18 +0200 | [diff] [blame^] | 27 | static const mp_obj_type_t microsocket_type; |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 28 | |
| 29 | // Helper functions |
| 30 | #define RAISE_ERRNO(err_flag, error_val) \ |
| 31 | { if (err_flag == -1) \ |
| 32 | { nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", error_val)); } } |
| 33 | |
| 34 | static void get_buffer(mp_obj_t obj, buffer_info_t *bufinfo) { |
| 35 | mp_obj_base_t *o = (mp_obj_base_t *)obj; |
| 36 | if (o->type->buffer_p.get_buffer == NULL) { |
| 37 | goto error; |
| 38 | } |
| 39 | o->type->buffer_p.get_buffer(o, bufinfo, BUFFER_READ); |
| 40 | if (bufinfo->buf == NULL) { |
| 41 | goto error; |
| 42 | } |
| 43 | return; |
| 44 | |
| 45 | error: |
| 46 | nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "Operation not supported")); |
| 47 | } |
| 48 | |
| 49 | static mp_obj_socket_t *socket_new(int fd) { |
| 50 | mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t); |
Paul Sokolovsky | 9945f33 | 2014-02-08 21:10:18 +0200 | [diff] [blame^] | 51 | o->base.type = µsocket_type; |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 52 | o->fd = fd; |
| 53 | return o; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | static void socket_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { |
| 58 | mp_obj_socket_t *self = self_in; |
| 59 | print(env, "<_socket %d>", self->fd); |
| 60 | } |
| 61 | |
| 62 | static machine_int_t socket_read(mp_obj_t o_in, void *buf, machine_uint_t size, int *errcode) { |
| 63 | mp_obj_socket_t *o = o_in; |
| 64 | machine_int_t r = read(o->fd, buf, size); |
| 65 | if (r == -1) { |
| 66 | *errcode = errno; |
| 67 | } |
| 68 | return r; |
| 69 | } |
| 70 | |
| 71 | static machine_int_t socket_write(mp_obj_t o_in, const void *buf, machine_uint_t size, int *errcode) { |
| 72 | mp_obj_socket_t *o = o_in; |
| 73 | machine_int_t r = write(o->fd, buf, size); |
| 74 | if (r == -1) { |
| 75 | *errcode = errno; |
| 76 | } |
| 77 | return r; |
| 78 | } |
| 79 | |
| 80 | static mp_obj_t socket_close(mp_obj_t self_in) { |
| 81 | mp_obj_socket_t *self = self_in; |
| 82 | close(self->fd); |
| 83 | return mp_const_none; |
| 84 | } |
| 85 | static MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close); |
| 86 | |
| 87 | static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { |
| 88 | mp_obj_socket_t *self = self_in; |
| 89 | buffer_info_t bufinfo; |
| 90 | get_buffer(addr_in, &bufinfo); |
| 91 | int r = connect(self->fd, (const struct sockaddr *)bufinfo.buf, bufinfo.len); |
| 92 | RAISE_ERRNO(r, errno); |
| 93 | return mp_const_none; |
| 94 | } |
| 95 | static MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); |
| 96 | |
| 97 | static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { |
| 98 | mp_obj_socket_t *self = self_in; |
| 99 | buffer_info_t bufinfo; |
| 100 | get_buffer(addr_in, &bufinfo); |
| 101 | int r = bind(self->fd, (const struct sockaddr *)bufinfo.buf, bufinfo.len); |
| 102 | RAISE_ERRNO(r, errno); |
| 103 | return mp_const_none; |
| 104 | } |
| 105 | static MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); |
| 106 | |
| 107 | static mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) { |
| 108 | mp_obj_socket_t *self = self_in; |
| 109 | int r = listen(self->fd, MP_OBJ_SMALL_INT_VALUE(backlog_in)); |
| 110 | RAISE_ERRNO(r, errno); |
| 111 | return mp_const_none; |
| 112 | } |
| 113 | static MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen); |
| 114 | |
| 115 | static mp_obj_t socket_accept(mp_obj_t self_in) { |
| 116 | mp_obj_socket_t *self = self_in; |
| 117 | struct sockaddr addr; |
| 118 | socklen_t addr_len = sizeof(addr); |
| 119 | int fd = accept(self->fd, &addr, &addr_len); |
| 120 | RAISE_ERRNO(fd, errno); |
| 121 | |
| 122 | mp_obj_tuple_t *t = mp_obj_new_tuple(2, NULL); |
| 123 | t->items[0] = socket_new(fd); |
| 124 | t->items[1] = mp_obj_new_bytearray(addr_len, &addr); |
| 125 | |
| 126 | return t; |
| 127 | } |
| 128 | static MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); |
| 129 | |
Paul Sokolovsky | fc35aa6 | 2014-01-20 19:42:39 +0200 | [diff] [blame] | 130 | static mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) { |
| 131 | mp_obj_socket_t *self = args[0]; |
| 132 | int sz = MP_OBJ_SMALL_INT_VALUE(args[1]); |
| 133 | int flags = 0; |
| 134 | |
| 135 | if (n_args > 2) { |
| 136 | flags = MP_OBJ_SMALL_INT_VALUE(args[2]); |
| 137 | } |
| 138 | |
Damien George | 12eacca | 2014-01-21 21:54:15 +0000 | [diff] [blame] | 139 | char *buf = m_new(char, sz); |
Paul Sokolovsky | fc35aa6 | 2014-01-20 19:42:39 +0200 | [diff] [blame] | 140 | int out_sz = recv(self->fd, buf, sz, flags); |
| 141 | RAISE_ERRNO(out_sz, errno); |
| 142 | |
Damien George | 12eacca | 2014-01-21 21:54:15 +0000 | [diff] [blame] | 143 | buf = m_realloc(buf, sz, out_sz); |
| 144 | return MP_OBJ_NEW_QSTR(qstr_from_strn_take(buf, out_sz, out_sz)); |
Paul Sokolovsky | fc35aa6 | 2014-01-20 19:42:39 +0200 | [diff] [blame] | 145 | } |
| 146 | static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_obj, 2, 3, socket_recv); |
| 147 | |
| 148 | static mp_obj_t socket_send(uint n_args, const mp_obj_t *args) { |
| 149 | mp_obj_socket_t *self = args[0]; |
| 150 | int flags = 0; |
| 151 | |
| 152 | if (n_args > 2) { |
| 153 | flags = MP_OBJ_SMALL_INT_VALUE(args[2]); |
| 154 | } |
| 155 | |
Damien George | 5fa93b6 | 2014-01-22 14:35:10 +0000 | [diff] [blame] | 156 | uint sz; |
Damien George | 698ec21 | 2014-02-08 18:17:23 +0000 | [diff] [blame] | 157 | const char *buf = mp_obj_str_get_data(args[1], &sz); |
Paul Sokolovsky | fc35aa6 | 2014-01-20 19:42:39 +0200 | [diff] [blame] | 158 | int out_sz = send(self->fd, buf, sz, flags); |
| 159 | RAISE_ERRNO(out_sz, errno); |
| 160 | |
Damien George | 12eacca | 2014-01-21 21:54:15 +0000 | [diff] [blame] | 161 | return MP_OBJ_NEW_SMALL_INT((machine_int_t)out_sz); |
Paul Sokolovsky | fc35aa6 | 2014-01-20 19:42:39 +0200 | [diff] [blame] | 162 | } |
| 163 | static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_send_obj, 2, 3, socket_send); |
| 164 | |
Paul Sokolovsky | a88c30c | 2014-01-26 01:59:52 +0200 | [diff] [blame] | 165 | static mp_obj_t socket_setsockopt(uint n_args, const mp_obj_t *args) { |
| 166 | mp_obj_socket_t *self = args[0]; |
| 167 | int level = MP_OBJ_SMALL_INT_VALUE(args[1]); |
| 168 | int option = mp_obj_get_int(args[2]); |
| 169 | |
| 170 | const void *optval; |
| 171 | socklen_t optlen; |
| 172 | if (MP_OBJ_IS_INT(args[3])) { |
| 173 | int val = mp_obj_int_get(args[3]); |
| 174 | optval = &val; |
| 175 | optlen = sizeof(val); |
| 176 | } else { |
| 177 | buffer_info_t bufinfo; |
| 178 | get_buffer(args[3], &bufinfo); |
| 179 | optval = bufinfo.buf; |
| 180 | optlen = bufinfo.len; |
| 181 | } |
| 182 | int r = setsockopt(self->fd, level, option, optval, optlen); |
| 183 | RAISE_ERRNO(r, errno); |
| 184 | return mp_const_none; |
| 185 | } |
| 186 | static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt); |
| 187 | |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 188 | static mp_obj_t socket_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { |
| 189 | int family = AF_INET; |
| 190 | int type = SOCK_STREAM; |
| 191 | int proto = 0; |
| 192 | |
| 193 | if (n_args > 0) { |
| 194 | assert(MP_OBJ_IS_SMALL_INT(args[0])); |
| 195 | family = MP_OBJ_SMALL_INT_VALUE(args[0]); |
| 196 | if (n_args > 1) { |
| 197 | assert(MP_OBJ_IS_SMALL_INT(args[1])); |
| 198 | type = MP_OBJ_SMALL_INT_VALUE(args[1]); |
| 199 | if (n_args > 2) { |
| 200 | assert(MP_OBJ_IS_SMALL_INT(args[2])); |
| 201 | proto = MP_OBJ_SMALL_INT_VALUE(args[2]); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | int fd = socket(family, type, proto); |
| 207 | RAISE_ERRNO(fd, errno); |
| 208 | return socket_new(fd); |
| 209 | } |
| 210 | |
Paul Sokolovsky | 9945f33 | 2014-02-08 21:10:18 +0200 | [diff] [blame^] | 211 | static const mp_method_t microsocket_type_methods[] = { |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 212 | { "read", &mp_stream_read_obj }, |
| 213 | { "readall", &mp_stream_readall_obj }, |
| 214 | { "readline", &mp_stream_unbuffered_readline_obj}, |
| 215 | { "write", &mp_stream_write_obj }, |
| 216 | { "connect", &socket_connect_obj }, |
| 217 | { "bind", &socket_bind_obj }, |
| 218 | { "listen", &socket_listen_obj }, |
| 219 | { "accept", &socket_accept_obj }, |
Paul Sokolovsky | fc35aa6 | 2014-01-20 19:42:39 +0200 | [diff] [blame] | 220 | { "recv", &socket_recv_obj }, |
| 221 | { "send", &socket_send_obj }, |
Paul Sokolovsky | a88c30c | 2014-01-26 01:59:52 +0200 | [diff] [blame] | 222 | { "setsockopt", &socket_setsockopt_obj }, |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 223 | { "close", &socket_close_obj }, |
| 224 | #if MICROPY_SOCKET_EXTRA |
| 225 | { "recv", &mp_stream_read_obj }, |
| 226 | { "send", &mp_stream_write_obj }, |
| 227 | #endif |
| 228 | { NULL, NULL }, |
| 229 | }; |
| 230 | |
Paul Sokolovsky | 9945f33 | 2014-02-08 21:10:18 +0200 | [diff] [blame^] | 231 | static const mp_obj_type_t microsocket_type = { |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 232 | { &mp_const_type }, |
| 233 | "socket", |
| 234 | .print = socket_print, |
| 235 | .make_new = socket_make_new, |
| 236 | .getiter = NULL, |
| 237 | .iternext = NULL, |
| 238 | .stream_p = { |
| 239 | .read = socket_read, |
| 240 | .write = socket_write, |
| 241 | }, |
Paul Sokolovsky | 9945f33 | 2014-02-08 21:10:18 +0200 | [diff] [blame^] | 242 | .methods = microsocket_type_methods, |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | static mp_obj_t mod_socket_htons(mp_obj_t arg) { |
Damien George | a8a6db2 | 2014-01-18 23:50:12 +0000 | [diff] [blame] | 246 | return MP_OBJ_NEW_SMALL_INT((machine_int_t)htons(MP_OBJ_SMALL_INT_VALUE(arg))); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 247 | } |
| 248 | static MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_htons_obj, mod_socket_htons); |
| 249 | |
| 250 | static mp_obj_t mod_socket_inet_aton(mp_obj_t arg) { |
| 251 | assert(MP_OBJ_IS_TYPE(arg, &str_type)); |
Damien George | 5fa93b6 | 2014-01-22 14:35:10 +0000 | [diff] [blame] | 252 | const char *s = mp_obj_str_get_str(arg); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 253 | struct in_addr addr; |
| 254 | if (!inet_aton(s, &addr)) { |
| 255 | nlr_jump(mp_obj_new_exception_msg(MP_QSTR_OSError, "Invalid IP address")); |
| 256 | } |
| 257 | |
| 258 | return mp_obj_new_int(addr.s_addr); |
| 259 | } |
| 260 | static MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_inet_aton_obj, mod_socket_inet_aton); |
| 261 | |
| 262 | #if MICROPY_SOCKET_EXTRA |
| 263 | static mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { |
| 264 | assert(MP_OBJ_IS_TYPE(arg, &str_type)); |
Damien George | 5fa93b6 | 2014-01-22 14:35:10 +0000 | [diff] [blame] | 265 | const char *s = mp_obj_str_get_str(arg); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 266 | struct hostent *h = gethostbyname(s); |
| 267 | if (h == NULL) { |
| 268 | nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", errno)); |
| 269 | } |
| 270 | assert(h->h_length == 4); |
| 271 | return mp_obj_new_int(*(int*)*h->h_addr_list); |
| 272 | } |
| 273 | static MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_gethostbyname_obj, mod_socket_gethostbyname); |
| 274 | #endif |
| 275 | |
Damien George | a11ceca | 2014-01-19 16:02:09 +0000 | [diff] [blame] | 276 | static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 277 | // TODO: Implement all args |
| 278 | assert(n_args == 2); |
Damien George | 5fa93b6 | 2014-01-22 14:35:10 +0000 | [diff] [blame] | 279 | assert(MP_OBJ_IS_STR(args[0])); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 280 | |
Damien George | 5fa93b6 | 2014-01-22 14:35:10 +0000 | [diff] [blame] | 281 | const char *host = mp_obj_str_get_str(args[0]); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 282 | const char *serv = NULL; |
| 283 | // getaddrinfo accepts port in string notation, so however |
| 284 | // it may seem stupid, we need to convert int to str |
| 285 | if (MP_OBJ_IS_SMALL_INT(args[1])) { |
| 286 | int port = MP_OBJ_SMALL_INT_VALUE(args[1]); |
| 287 | static char buf[20]; |
| 288 | sprintf(buf, "%d", port); |
| 289 | serv = buf; |
| 290 | } else { |
Damien George | 5fa93b6 | 2014-01-22 14:35:10 +0000 | [diff] [blame] | 291 | serv = mp_obj_str_get_str(args[1]); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | struct addrinfo hints; |
| 295 | struct addrinfo *addr; |
| 296 | memset(&hints, 0, sizeof(hints)); |
| 297 | int res = getaddrinfo(host, serv, NULL/*&hints*/, &addr); |
| 298 | |
| 299 | if (res != 0) { |
| 300 | nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[addrinfo error %d]", res)); |
| 301 | } |
| 302 | assert(addr); |
| 303 | |
| 304 | mp_obj_t list = rt_build_list(0, NULL); |
| 305 | for (; addr; addr = addr->ai_next) { |
| 306 | mp_obj_tuple_t *t = mp_obj_new_tuple(5, NULL); |
Damien George | a8a6db2 | 2014-01-18 23:50:12 +0000 | [diff] [blame] | 307 | t->items[0] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_family); |
| 308 | t->items[1] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_socktype); |
| 309 | t->items[2] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_protocol); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 310 | // "canonname will be a string representing the canonical name of the host |
| 311 | // if AI_CANONNAME is part of the flags argument; else canonname will be empty." ?? |
| 312 | if (addr->ai_canonname) { |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 313 | t->items[3] = MP_OBJ_NEW_QSTR(qstr_from_str(addr->ai_canonname)); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 314 | } else { |
| 315 | t->items[3] = mp_const_none; |
| 316 | } |
| 317 | t->items[4] = mp_obj_new_bytearray(addr->ai_addrlen, addr->ai_addr); |
| 318 | rt_list_append(list, t); |
| 319 | } |
| 320 | return list; |
| 321 | } |
| 322 | static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); |
| 323 | |
| 324 | extern mp_obj_type_t sockaddr_in_type; |
| 325 | |
Paul Sokolovsky | db0b282 | 2014-01-25 20:13:17 +0200 | [diff] [blame] | 326 | #define C(name) { #name, name } |
| 327 | |
| 328 | struct sym_entry { |
| 329 | const char *sym; |
| 330 | int val; |
| 331 | } constants[] = { |
| 332 | C(AF_UNIX), |
| 333 | C(AF_INET), |
| 334 | C(AF_INET6), |
| 335 | C(SOCK_STREAM), |
| 336 | C(SOCK_DGRAM), |
| 337 | C(SOCK_RAW), |
Paul Sokolovsky | 5d362d3 | 2014-01-25 20:31:34 +0200 | [diff] [blame] | 338 | |
| 339 | C(MSG_DONTROUTE), |
| 340 | C(MSG_DONTWAIT), |
| 341 | |
| 342 | C(SOL_SOCKET), |
| 343 | C(SO_BROADCAST), |
| 344 | C(SO_ERROR), |
| 345 | C(SO_KEEPALIVE), |
| 346 | C(SO_LINGER), |
| 347 | C(SO_REUSEADDR), |
| 348 | |
| 349 | {NULL} |
Paul Sokolovsky | db0b282 | 2014-01-25 20:13:17 +0200 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | #undef C |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 353 | |
Paul Sokolovsky | 9945f33 | 2014-02-08 21:10:18 +0200 | [diff] [blame^] | 354 | void microsocket_init() { |
| 355 | mp_obj_t m = mp_obj_new_module(MP_QSTR_microsocket); |
| 356 | rt_store_attr(m, MP_QSTR_socket, (mp_obj_t)µsocket_type); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 357 | #if MICROPY_SOCKET_EXTRA |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 358 | rt_store_attr(m, MP_QSTR_sockaddr_in, (mp_obj_t)&sockaddr_in_type); |
| 359 | rt_store_attr(m, MP_QSTR_htons, (mp_obj_t)&mod_socket_htons_obj); |
| 360 | rt_store_attr(m, MP_QSTR_inet_aton, (mp_obj_t)&mod_socket_inet_aton_obj); |
| 361 | rt_store_attr(m, MP_QSTR_gethostbyname, (mp_obj_t)&mod_socket_gethostbyname_obj); |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 362 | #endif |
Damien George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 363 | rt_store_attr(m, MP_QSTR_getaddrinfo, (mp_obj_t)&mod_socket_getaddrinfo_obj); |
Paul Sokolovsky | db0b282 | 2014-01-25 20:13:17 +0200 | [diff] [blame] | 364 | for (struct sym_entry *p = constants; p->sym != NULL; p++) { |
Damien George | 56bb636 | 2014-01-26 17:52:23 +0000 | [diff] [blame] | 365 | rt_store_attr(m, QSTR_FROM_STR_STATIC(p->sym), MP_OBJ_NEW_SMALL_INT((machine_int_t)p->val)); |
Paul Sokolovsky | db0b282 | 2014-01-25 20:13:17 +0200 | [diff] [blame] | 366 | } |
Paul Sokolovsky | fc92608 | 2014-01-18 23:47:44 +0200 | [diff] [blame] | 367 | } |