1+ #include "python_socket.h"
2+ #include <string.h>
3+ #include "esp_log.h"
4+ #include "freertos/FreeRTOS.h"
5+ #include "freertos/task.h"
6+ #include "pocketpy/pocketpy.h"
7+ #include "sys/socket.h"
8+
9+ static bool example_func (int argc , py_Ref argv ) {
10+ PY_CHECK_ARGC (1 );
11+ py_f64 secs ;
12+ if (!py_castfloat (argv , & secs )) return false;
13+
14+ printf ("EXAMPLE FUNC\r\n" );
15+
16+ py_newnone (py_retval ());
17+
18+ return true;
19+ }
20+
21+ static bool getaddrinfo (int argc , py_Ref argv ) {
22+ PY_CHECK_ARGC (2 );
23+ PY_CHECK_ARG_TYPE (0 , tp_str ); // Hostname
24+ PY_CHECK_ARG_TYPE (1 , tp_int ); // Port
25+
26+ const char * hostname = py_tostr (py_arg (0 ));
27+ int port = py_toint (py_arg (1 ));
28+
29+ // struct addrinfo hints = {.ai_socktype = SOCK_STREAM};
30+ struct addrinfo * address_info = NULL ;
31+
32+ /*int res = getaddrinfo(hostname, port, &hints, &address_info);
33+ if (res != 0 || address_info == NULL) {
34+ return OSError("Getaddrinfo failed %d", res);
35+ }*/
36+
37+ py_newnone (py_retval ());
38+ return true;
39+ }
40+
41+ void pk__add_module_socket (void ) {
42+ py_Ref mod = py_newmodule ("socket" );
43+ py_bindfunc (mod , "socket" , example_func );
44+ py_bindfunc (mod , "getaddrinfo" , getaddrinfo );
45+ }
46+
47+ /*
48+ py_bindfunc(mod, "bind", example_func);
49+ py_bindfunc(mod, "listen", example_func);
50+ py_bindfunc(mod, "accept", example_func);
51+ py_bindfunc(mod, "connect", example_func);
52+ py_bindfunc(mod, "send", example_func);
53+ py_bindfunc(mod, "sendall", example_func);
54+ py_bindfunc(mod, "recv", example_func);
55+ py_bindfunc(mod, "sendto", example_func);
56+ py_bindfunc(mod, "recvfrom", example_func);
57+ py_bindfunc(mod, "setsockopt", example_func);
58+ py_bindfunc(mod, "makefile", example_func);
59+ py_bindfunc(mod, "settimeout", example_func);
60+ py_bindfunc(mod, "setblocking", example_func);
61+ */
0 commit comments