mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
insert freertos and lwip platform for network
This commit is contained in:
parent
a67a71f944
commit
ebe10bc5f4
@ -108,20 +108,34 @@ int platform_net_socket_close(int fd) {
|
||||
return __platform_close(fd);
|
||||
}
|
||||
|
||||
int platform_net_socket_set_block(int fd) {
|
||||
PIKA_WEAK int platform_net_socket_set_block(int fd) {
|
||||
#ifdef __linux
|
||||
return __platform_fcntl(
|
||||
fd, F_SETFL, __platform_fcntl(fd, F_GETFL, F_GETFL) & ~O_NONBLOCK);
|
||||
#elif PIKA_LWIP_ENABLE
|
||||
unsigned long mode = 0;
|
||||
return ioctlsocket(fd, FIONBIO, &mode);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
int platform_net_socket_set_nonblock(int fd) {
|
||||
PIKA_WEAK int platform_net_socket_set_nonblock(int fd) {
|
||||
#ifdef __linux
|
||||
return __platform_fcntl(
|
||||
fd, F_SETFL, __platform_fcntl(fd, F_GETFL, F_GETFL) | O_NONBLOCK);
|
||||
#elif PIKA_LWIP_ENABLE
|
||||
unsigned long mode = 1;
|
||||
return ioctlsocket(fd, FIONBIO, &mode);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
int platform_net_socket_setsockopt(int fd,
|
||||
int level,
|
||||
int optname,
|
||||
const void* optval,
|
||||
socklen_t optlen) {
|
||||
PIKA_WEAK int platform_net_socket_setsockopt(int fd,
|
||||
int level,
|
||||
int optname,
|
||||
const void* optval,
|
||||
socklen_t optlen) {
|
||||
return __platform_setsockopt(fd, level, optname, optval, optlen);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
PIKA_WEAK int __platform_socket(int __domain, int __type, int __protocol) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return socket(__domain, __type, __protocol);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -15,7 +15,7 @@ PIKA_WEAK int __platform_socket(int __domain, int __type, int __protocol) {
|
||||
PIKA_WEAK int __platform_bind(int __fd,
|
||||
const struct sockaddr* __addr,
|
||||
socklen_t __addr_len) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return bind(__fd, __addr, __addr_len);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -23,7 +23,7 @@ PIKA_WEAK int __platform_bind(int __fd,
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_listen(int __fd, int __n) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return listen(__fd, __n);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -33,7 +33,7 @@ PIKA_WEAK int __platform_listen(int __fd, int __n) {
|
||||
PIKA_WEAK int __platform_accept(int __fd,
|
||||
struct sockaddr* __addr,
|
||||
socklen_t* __addr_len) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return accept(__fd, __addr, __addr_len);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -43,7 +43,7 @@ PIKA_WEAK int __platform_accept(int __fd,
|
||||
PIKA_WEAK int __platform_connect(int __fd,
|
||||
const struct sockaddr* __addr,
|
||||
socklen_t __addr_len) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return connect(__fd, __addr, __addr_len);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -54,7 +54,7 @@ PIKA_WEAK int __platform_send(int __fd,
|
||||
const void* __buf,
|
||||
size_t __n,
|
||||
int __flags) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return send(__fd, __buf, __n, __flags);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -62,7 +62,7 @@ PIKA_WEAK int __platform_send(int __fd,
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_recv(int __fd, void* __buf, size_t __n, int __flags) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return recv(__fd, __buf, __n, __flags);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -71,7 +71,7 @@ PIKA_WEAK int __platform_recv(int __fd, void* __buf, size_t __n, int __flags) {
|
||||
|
||||
/* gethostname */
|
||||
PIKA_WEAK int __platform_gethostname(char* __name, size_t __len) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return gethostname(__name, __len);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -82,7 +82,7 @@ PIKA_WEAK int __platform_getaddrinfo(const char* __name,
|
||||
const char* __service,
|
||||
const struct addrinfo* __req,
|
||||
struct addrinfo** __pai) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return getaddrinfo(__name, __service, __req, __pai);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -90,7 +90,7 @@ PIKA_WEAK int __platform_getaddrinfo(const char* __name,
|
||||
}
|
||||
|
||||
PIKA_WEAK void __platform_freeaddrinfo(struct addrinfo* __ai) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
freeaddrinfo(__ai);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -102,7 +102,7 @@ PIKA_WEAK int __platform_setsockopt(int __fd,
|
||||
int __optname,
|
||||
const void* __optval,
|
||||
socklen_t __optlen) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return setsockopt(__fd, __level, __optname, __optval, __optlen);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -116,3 +116,22 @@ PIKA_WEAK int __platform_fcntl(int fd, int cmd, long arg) {
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* os file API */
|
||||
PIKA_WEAK int __platform_close(int __fd) {
|
||||
#ifdef __linux__
|
||||
return close(__fd);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
return closesocket(__fd);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_write(int __fd, const void* __buf, size_t __nbyte) {
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return write(__fd, __buf, __nbyte);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
@ -5,6 +5,12 @@
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#elif PIKA_LWIP_ENABLE
|
||||
#include <lwip/sockets.h>
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/sys.h"
|
||||
#else
|
||||
/*
|
||||
You need to create the __platform_socket.h for your platform.
|
||||
@ -38,8 +44,6 @@ int __platform_setsockopt(int __fd,
|
||||
socklen_t __optlen);
|
||||
|
||||
/* os file API */
|
||||
int __platform_open(const char* __file, int __oflag, ...);
|
||||
int __platform_close(int fd);
|
||||
int __platform_read(int fd, void* buf, size_t count);
|
||||
int __platform_write(int fd, const void* buf, size_t count);
|
||||
int __platform_fcntl(int fd, int cmd, long arg);
|
||||
|
@ -114,41 +114,3 @@ char* _socket__gethostname(PikaObj* self) {
|
||||
__platform_gethostname(hostname_buff, 128);
|
||||
return obj_cacheStr(self, hostname);
|
||||
}
|
||||
|
||||
/* os file API */
|
||||
|
||||
PIKA_WEAK int __platform_close(int __fd) {
|
||||
#ifdef __linux__
|
||||
return close(__fd);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_open(const char* __file, int __oflag, ...) {
|
||||
#ifdef __linux__
|
||||
va_list args;
|
||||
va_start(args, __oflag);
|
||||
int __mode = va_arg(args, int);
|
||||
va_end(args);
|
||||
return open(__file, __oflag, __mode);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_read(int __fd, void* __buf, size_t __nbyte) {
|
||||
#ifdef __linux__
|
||||
return read(__fd, __buf, __nbyte);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_write(int __fd, const void* __buf, size_t __nbyte) {
|
||||
#ifdef __linux__
|
||||
return write(__fd, __buf, __nbyte);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
@ -108,20 +108,34 @@ int platform_net_socket_close(int fd) {
|
||||
return __platform_close(fd);
|
||||
}
|
||||
|
||||
int platform_net_socket_set_block(int fd) {
|
||||
PIKA_WEAK int platform_net_socket_set_block(int fd) {
|
||||
#ifdef __linux
|
||||
return __platform_fcntl(
|
||||
fd, F_SETFL, __platform_fcntl(fd, F_GETFL, F_GETFL) & ~O_NONBLOCK);
|
||||
#elif PIKA_LWIP_ENABLE
|
||||
unsigned long mode = 0;
|
||||
return ioctlsocket(fd, FIONBIO, &mode);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
int platform_net_socket_set_nonblock(int fd) {
|
||||
PIKA_WEAK int platform_net_socket_set_nonblock(int fd) {
|
||||
#ifdef __linux
|
||||
return __platform_fcntl(
|
||||
fd, F_SETFL, __platform_fcntl(fd, F_GETFL, F_GETFL) | O_NONBLOCK);
|
||||
#elif PIKA_LWIP_ENABLE
|
||||
unsigned long mode = 1;
|
||||
return ioctlsocket(fd, FIONBIO, &mode);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
int platform_net_socket_setsockopt(int fd,
|
||||
int level,
|
||||
int optname,
|
||||
const void* optval,
|
||||
socklen_t optlen) {
|
||||
PIKA_WEAK int platform_net_socket_setsockopt(int fd,
|
||||
int level,
|
||||
int optname,
|
||||
const void* optval,
|
||||
socklen_t optlen) {
|
||||
return __platform_setsockopt(fd, level, optname, optval, optlen);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
PIKA_WEAK int __platform_socket(int __domain, int __type, int __protocol) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return socket(__domain, __type, __protocol);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -15,7 +15,7 @@ PIKA_WEAK int __platform_socket(int __domain, int __type, int __protocol) {
|
||||
PIKA_WEAK int __platform_bind(int __fd,
|
||||
const struct sockaddr* __addr,
|
||||
socklen_t __addr_len) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return bind(__fd, __addr, __addr_len);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -23,7 +23,7 @@ PIKA_WEAK int __platform_bind(int __fd,
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_listen(int __fd, int __n) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return listen(__fd, __n);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -33,7 +33,7 @@ PIKA_WEAK int __platform_listen(int __fd, int __n) {
|
||||
PIKA_WEAK int __platform_accept(int __fd,
|
||||
struct sockaddr* __addr,
|
||||
socklen_t* __addr_len) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return accept(__fd, __addr, __addr_len);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -43,7 +43,7 @@ PIKA_WEAK int __platform_accept(int __fd,
|
||||
PIKA_WEAK int __platform_connect(int __fd,
|
||||
const struct sockaddr* __addr,
|
||||
socklen_t __addr_len) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return connect(__fd, __addr, __addr_len);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -54,7 +54,7 @@ PIKA_WEAK int __platform_send(int __fd,
|
||||
const void* __buf,
|
||||
size_t __n,
|
||||
int __flags) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return send(__fd, __buf, __n, __flags);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -62,7 +62,7 @@ PIKA_WEAK int __platform_send(int __fd,
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_recv(int __fd, void* __buf, size_t __n, int __flags) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return recv(__fd, __buf, __n, __flags);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -71,7 +71,7 @@ PIKA_WEAK int __platform_recv(int __fd, void* __buf, size_t __n, int __flags) {
|
||||
|
||||
/* gethostname */
|
||||
PIKA_WEAK int __platform_gethostname(char* __name, size_t __len) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return gethostname(__name, __len);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -82,7 +82,7 @@ PIKA_WEAK int __platform_getaddrinfo(const char* __name,
|
||||
const char* __service,
|
||||
const struct addrinfo* __req,
|
||||
struct addrinfo** __pai) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return getaddrinfo(__name, __service, __req, __pai);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -90,7 +90,7 @@ PIKA_WEAK int __platform_getaddrinfo(const char* __name,
|
||||
}
|
||||
|
||||
PIKA_WEAK void __platform_freeaddrinfo(struct addrinfo* __ai) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
freeaddrinfo(__ai);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -102,7 +102,7 @@ PIKA_WEAK int __platform_setsockopt(int __fd,
|
||||
int __optname,
|
||||
const void* __optval,
|
||||
socklen_t __optlen) {
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return setsockopt(__fd, __level, __optname, __optval, __optlen);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
@ -116,3 +116,22 @@ PIKA_WEAK int __platform_fcntl(int fd, int cmd, long arg) {
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* os file API */
|
||||
PIKA_WEAK int __platform_close(int __fd) {
|
||||
#ifdef __linux__
|
||||
return close(__fd);
|
||||
#elif PIKA_FREERTOS_ENABLE
|
||||
return closesocket(__fd);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_write(int __fd, const void* __buf, size_t __nbyte) {
|
||||
#if defined(__linux__) || PIKA_LWIP_ENABLE
|
||||
return write(__fd, __buf, __nbyte);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
@ -44,8 +44,6 @@ int __platform_setsockopt(int __fd,
|
||||
socklen_t __optlen);
|
||||
|
||||
/* os file API */
|
||||
int __platform_open(const char* __file, int __oflag, ...);
|
||||
int __platform_close(int fd);
|
||||
int __platform_read(int fd, void* buf, size_t count);
|
||||
int __platform_write(int fd, const void* buf, size_t count);
|
||||
int __platform_fcntl(int fd, int cmd, long arg);
|
||||
|
@ -114,41 +114,3 @@ char* _socket__gethostname(PikaObj* self) {
|
||||
__platform_gethostname(hostname_buff, 128);
|
||||
return obj_cacheStr(self, hostname);
|
||||
}
|
||||
|
||||
/* os file API */
|
||||
|
||||
PIKA_WEAK int __platform_close(int __fd) {
|
||||
#ifdef __linux__
|
||||
return close(__fd);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_open(const char* __file, int __oflag, ...) {
|
||||
#ifdef __linux__
|
||||
va_list args;
|
||||
va_start(args, __oflag);
|
||||
int __mode = va_arg(args, int);
|
||||
va_end(args);
|
||||
return open(__file, __oflag, __mode);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_read(int __fd, void* __buf, size_t __nbyte) {
|
||||
#ifdef __linux__
|
||||
return read(__fd, __buf, __nbyte);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_write(int __fd, const void* __buf, size_t __nbyte) {
|
||||
#ifdef __linux__
|
||||
return write(__fd, __buf, __nbyte);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
@ -336,6 +336,14 @@
|
||||
#define PIKA_EVENT_LIST_SIZE 16
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_LWIP_ENABLE
|
||||
#define PIKA_LWIP_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_FREERTOS_ENABLE
|
||||
#define PIKA_FREERTOS_ENABLE 0
|
||||
#endif
|
||||
|
||||
/* configuration validation */
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user