2020-12-05 11:26:32 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-11-06 01:03:33 +00:00
|
|
|
#if defined(MG_ENABLE_FREERTOS_TCP) && MG_ENABLE_FREERTOS_TCP
|
2021-03-13 12:34:26 +00:00
|
|
|
|
|
|
|
#include <limits.h>
|
2022-08-14 23:46:33 +01:00
|
|
|
#include <list.h>
|
|
|
|
|
2020-12-05 11:26:32 +00:00
|
|
|
#include <FreeRTOS_IP.h>
|
|
|
|
#include <FreeRTOS_Sockets.h>
|
2023-03-23 17:13:02 -03:00
|
|
|
#include <FreeRTOS_errno_TCP.h> // contents to be moved and file removed, some day
|
2020-12-05 11:26:32 +00:00
|
|
|
|
2022-11-05 10:07:31 +00:00
|
|
|
#define MG_SOCKET_TYPE Socket_t
|
|
|
|
#define MG_INVALID_SOCKET FREERTOS_INVALID_SOCKET
|
|
|
|
|
2021-05-17 17:36:57 +01:00
|
|
|
// Why FreeRTOS-TCP did not implement a clean BSD API, but its own thing
|
|
|
|
// with FreeRTOS_ prefix, is beyond me
|
2020-12-05 11:26:32 +00:00
|
|
|
#define IPPROTO_TCP FREERTOS_IPPROTO_TCP
|
|
|
|
#define IPPROTO_UDP FREERTOS_IPPROTO_UDP
|
|
|
|
#define AF_INET FREERTOS_AF_INET
|
|
|
|
#define SOCK_STREAM FREERTOS_SOCK_STREAM
|
|
|
|
#define SOCK_DGRAM FREERTOS_SOCK_DGRAM
|
|
|
|
#define SO_BROADCAST 0
|
|
|
|
#define SO_ERROR 0
|
|
|
|
#define SOL_SOCKET 0
|
|
|
|
#define SO_REUSEADDR 0
|
2023-03-24 15:21:55 -03:00
|
|
|
|
|
|
|
#define MG_SOCK_ERR(errcode) ((errcode) < 0 ? (errcode) : 0)
|
|
|
|
|
|
|
|
#define MG_SOCK_PENDING(errcode) \
|
|
|
|
((errcode) == -pdFREERTOS_ERRNO_EWOULDBLOCK || \
|
|
|
|
(errcode) == -pdFREERTOS_ERRNO_EISCONN || \
|
|
|
|
(errcode) == -pdFREERTOS_ERRNO_EINPROGRESS || \
|
|
|
|
(errcode) == -pdFREERTOS_ERRNO_EAGAIN)
|
|
|
|
|
|
|
|
#define MG_SOCK_RESET(errcode) ((errcode) == -pdFREERTOS_ERRNO_ENOTCONN)
|
|
|
|
|
|
|
|
// actually only if optional timeout is enabled
|
|
|
|
#define MG_SOCK_INTR(fd) (fd == NULL)
|
|
|
|
|
2020-12-05 11:26:32 +00:00
|
|
|
#define sockaddr_in freertos_sockaddr
|
2021-05-12 08:43:34 +01:00
|
|
|
#define sockaddr freertos_sockaddr
|
2020-12-05 11:26:32 +00:00
|
|
|
#define accept(a, b, c) FreeRTOS_accept((a), (b), (c))
|
|
|
|
#define connect(a, b, c) FreeRTOS_connect((a), (b), (c))
|
|
|
|
#define bind(a, b, c) FreeRTOS_bind((a), (b), (c))
|
|
|
|
#define listen(a, b) FreeRTOS_listen((a), (b))
|
|
|
|
#define socket(a, b, c) FreeRTOS_socket((a), (b), (c))
|
|
|
|
#define send(a, b, c, d) FreeRTOS_send((a), (b), (c), (d))
|
|
|
|
#define recv(a, b, c, d) FreeRTOS_recv((a), (b), (c), (d))
|
|
|
|
#define setsockopt(a, b, c, d, e) FreeRTOS_setsockopt((a), (b), (c), (d), (e))
|
|
|
|
#define sendto(a, b, c, d, e, f) FreeRTOS_sendto((a), (b), (c), (d), (e), (f))
|
|
|
|
#define recvfrom(a, b, c, d, e, f) \
|
|
|
|
FreeRTOS_recvfrom((a), (b), (c), (d), (e), (f))
|
|
|
|
#define closesocket(x) FreeRTOS_closesocket(x)
|
|
|
|
#define gethostbyname(x) FreeRTOS_gethostbyname(x)
|
2022-11-06 01:03:33 +00:00
|
|
|
#define getsockname(a, b, c) mg_getsockname((a), (b), (c))
|
|
|
|
#define getpeername(a, b, c) mg_getpeername((a), (b), (c))
|
2020-12-05 11:26:32 +00:00
|
|
|
|
2022-11-06 01:03:33 +00:00
|
|
|
static inline int mg_getsockname(MG_SOCKET_TYPE fd, void *buf, socklen_t *len) {
|
|
|
|
(void) fd, (void) buf, (void) len;
|
|
|
|
return -1;
|
2021-05-17 17:36:57 +01:00
|
|
|
}
|
|
|
|
|
2022-11-06 01:03:33 +00:00
|
|
|
static inline int mg_getpeername(MG_SOCKET_TYPE fd, void *buf, socklen_t *len) {
|
|
|
|
(void) fd, (void) buf, (void) len;
|
|
|
|
return 0;
|
|
|
|
}
|
2022-10-10 13:41:07 +01:00
|
|
|
#endif
|