Test / RFC: Reformat a few files using clang-format

Does it compile? Does it look good (enough)?
This commit is contained in:
Dirk Ziegelmeier
2018-07-17 21:15:48 +02:00
parent 4e74421dac
commit 8b4a8159a8
25 changed files with 3021 additions and 2721 deletions

View File

@@ -63,11 +63,11 @@
#include "lwip/memp.h"
#include "lwip/ip.h"
#include "lwip/raw.h"
#include "lwip/udp.h"
#include "lwip/priv/api_msg.h"
#include "lwip/priv/tcp_priv.h"
#include "lwip/priv/tcpip_priv.h"
#include "lwip/raw.h"
#include "lwip/udp.h"
#ifdef LWIP_HOOK_FILENAME
#include LWIP_HOOK_FILENAME
@@ -75,11 +75,11 @@
#include <string.h>
#define API_MSG_VAR_REF(name) API_VAR_REF(name)
#define API_MSG_VAR_DECLARE(name) API_VAR_DECLARE(struct api_msg, name)
#define API_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct api_msg, MEMP_API_MSG, name, ERR_MEM)
#define API_MSG_VAR_REF(name) API_VAR_REF(name)
#define API_MSG_VAR_DECLARE(name) API_VAR_DECLARE(struct api_msg, name)
#define API_MSG_VAR_ALLOC(name) API_VAR_ALLOC(struct api_msg, MEMP_API_MSG, name, ERR_MEM)
#define API_MSG_VAR_ALLOC_RETURN_NULL(name) API_VAR_ALLOC(struct api_msg, MEMP_API_MSG, name, NULL)
#define API_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_API_MSG, name)
#define API_MSG_VAR_FREE(name) API_VAR_FREE(MEMP_API_MSG, name)
#if TCP_LISTEN_BACKLOG
/* need to allocate API message for accept so empty message pool does not result in event loss
@@ -92,18 +92,22 @@
#endif /* TCP_LISTEN_BACKLOG */
#if LWIP_NETCONN_FULLDUPLEX
#define NETCONN_RECVMBOX_WAITABLE(conn) (sys_mbox_valid(&(conn)->recvmbox) && (((conn)->flags & NETCONN_FLAG_MBOXINVALID) == 0))
#define NETCONN_ACCEPTMBOX_WAITABLE(conn) (sys_mbox_valid(&(conn)->acceptmbox) && (((conn)->flags & (NETCONN_FLAG_MBOXCLOSED|NETCONN_FLAG_MBOXINVALID)) == 0))
#define NETCONN_RECVMBOX_WAITABLE(conn) \
(sys_mbox_valid(&(conn)->recvmbox) && (((conn)->flags & NETCONN_FLAG_MBOXINVALID) == 0))
#define NETCONN_ACCEPTMBOX_WAITABLE(conn) \
(sys_mbox_valid(&(conn)->acceptmbox) && (((conn)->flags & (NETCONN_FLAG_MBOXCLOSED | NETCONN_FLAG_MBOXINVALID)) == 0))
#define NETCONN_MBOX_WAITING_INC(conn) SYS_ARCH_INC(conn->mbox_threads_waiting, 1)
#define NETCONN_MBOX_WAITING_DEC(conn) SYS_ARCH_INC(conn->mbox_threads_waiting, 1)
#else /* LWIP_NETCONN_FULLDUPLEX */
#define NETCONN_RECVMBOX_WAITABLE(conn) sys_mbox_valid(&(conn)->recvmbox)
#define NETCONN_ACCEPTMBOX_WAITABLE(conn) (sys_mbox_valid(&(conn)->acceptmbox) && (((conn)->flags & NETCONN_FLAG_MBOXCLOSED) == 0))
#define NETCONN_RECVMBOX_WAITABLE(conn) sys_mbox_valid(&(conn)->recvmbox)
#define NETCONN_ACCEPTMBOX_WAITABLE(conn) \
(sys_mbox_valid(&(conn)->acceptmbox) && (((conn)->flags & NETCONN_FLAG_MBOXCLOSED) == 0))
#define NETCONN_MBOX_WAITING_INC(conn)
#define NETCONN_MBOX_WAITING_DEC(conn)
#endif /* LWIP_NETCONN_FULLDUPLEX */
static err_t netconn_close_shutdown(struct netconn *conn, u8_t how);
static err_t
netconn_close_shutdown(struct netconn *conn, u8_t how);
/**
* Call the lower part of a netconn_* function
@@ -282,7 +286,7 @@ netconn_getaddr(struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local)
err = netconn_apimsg(lwip_netconn_do_getaddr, &API_MSG_VAR_REF(msg));
*addr = msg->msg.ad.ipaddr;
*port = msg->msg.ad.port;
#else /* LWIP_MPU_COMPATIBLE */
#else /* LWIP_MPU_COMPATIBLE */
msg.msg.ad.ipaddr = addr;
msg.msg.ad.port = port;
err = netconn_apimsg(lwip_netconn_do_getaddr, &msg);
@@ -322,8 +326,7 @@ netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port)
/* "Socket API like" dual-stack support: If IP to bind to is IP6_ADDR_ANY,
* and NETCONN_FLAG_IPV6_V6ONLY is 0, use IP_ANY_TYPE to bind
*/
if ((netconn_get_ipv6only(conn) == 0) &&
ip_addr_cmp(addr, IP6_ADDR_ANY)) {
if ((netconn_get_ipv6only(conn) == 0) && ip_addr_cmp(addr, IP6_ADDR_ANY)) {
addr = IP_ANY_TYPE;
}
#endif /* LWIP_IPV4 && LWIP_IPV6 */
@@ -451,7 +454,7 @@ netconn_listen_with_backlog(struct netconn *conn, u8_t backlog)
API_MSG_VAR_FREE(msg);
return err;
#else /* LWIP_TCP */
#else /* LWIP_TCP */
LWIP_UNUSED_ARG(conn);
LWIP_UNUSED_ARG(backlog);
return ERR_ARG;
@@ -478,9 +481,9 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn)
API_MSG_VAR_DECLARE(msg);
#endif /* TCP_LISTEN_BACKLOG */
LWIP_ERROR("netconn_accept: invalid pointer", (new_conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_accept: invalid pointer", (new_conn != NULL), return ERR_ARG;);
*new_conn = NULL;
LWIP_ERROR("netconn_accept: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_accept: invalid conn", (conn != NULL), return ERR_ARG;);
/* NOTE: Although the opengroup spec says a pending error shall be returned to
send/recv/getsockopt(SO_ERROR) only, we return it for listening
@@ -552,7 +555,7 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn)
*new_conn = newconn;
/* don't set conn->last_err: it's only ERR_OK, anyway */
return ERR_OK;
#else /* LWIP_TCP */
#else /* LWIP_TCP */
LWIP_UNUSED_ARG(conn);
LWIP_UNUSED_ARG(new_conn);
return ERR_ARG;
@@ -583,7 +586,7 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
LWIP_ERROR("netconn_recv: invalid pointer", (new_buf != NULL), return ERR_ARG;);
*new_buf = NULL;
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
if (!NETCONN_RECVMBOX_WAITABLE(conn)) {
err_t err = netconn_err(conn);
@@ -595,8 +598,8 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
}
NETCONN_MBOX_WAITING_INC(conn);
if (netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK) ||
(conn->flags & NETCONN_FLAG_MBOXCLOSED) || (conn->pending_err != ERR_OK)) {
if (netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK) || (conn->flags & NETCONN_FLAG_MBOXCLOSED) ||
(conn->pending_err != ERR_OK)) {
if (sys_arch_mbox_tryfetch(&conn->recvmbox, &buf) == SYS_ARCH_TIMEOUT) {
err_t err;
NETCONN_MBOX_WAITING_DEC(conn);
@@ -665,7 +668,7 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
/* Register event with callback */
API_EVENT(conn, NETCONN_EVT_RCVMINUS, len);
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_recv_data: received %p, len=%"U16_F"\n", buf, len));
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_recv_data: received %p, len=%" U16_F "\n", buf, len));
*new_buf = buf;
/* don't set conn->last_err: it's only ERR_OK, anyway */
@@ -676,8 +679,9 @@ netconn_recv_data(struct netconn *conn, void **new_buf, u8_t apiflags)
static err_t
netconn_tcp_recvd_msg(struct netconn *conn, size_t len, struct api_msg *msg)
{
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn",
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP,
return ERR_ARG;);
msg->conn = conn;
msg->msg.r.len = len;
@@ -690,8 +694,9 @@ netconn_tcp_recvd(struct netconn *conn, size_t len)
{
err_t err;
API_MSG_VAR_DECLARE(msg);
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn",
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP,
return ERR_ARG;);
API_MSG_VAR_ALLOC(msg);
err = netconn_tcp_recvd_msg(conn, len, &API_VAR_REF(msg));
@@ -720,7 +725,7 @@ netconn_recv_data_tcp(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags
if (!(apiflags & NETCONN_NOAUTORCVD)) {
/* need to allocate API message here so empty message pool does not result in event loss
* see bug #47512: MPU_COMPATIBLE may fail on empty pool */
* see bug #47512: MPU_COMPATIBLE may fail on empty pool */
API_MSG_VAR_ALLOC(msg);
}
@@ -737,7 +742,7 @@ netconn_recv_data_tcp(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags
u16_t len = buf ? buf->tot_len : 1;
/* don't care for the return value of lwip_netconn_do_recv */
/* @todo: this should really be fixed, e.g. by retrying in poll on error */
netconn_tcp_recvd_msg(conn, len, &API_VAR_REF(msg));
netconn_tcp_recvd_msg(conn, len, &API_VAR_REF(msg));
API_MSG_VAR_FREE(msg);
}
@@ -749,7 +754,7 @@ netconn_recv_data_tcp(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags
netconn_set_flags(conn, NETCONN_FIN_RX_PENDING);
return ERR_WOULDBLOCK;
} else {
handle_fin:
handle_fin:
API_EVENT(conn, NETCONN_EVT_RCVMINUS, 0);
if (conn->pcb.ip == NULL) {
/* race condition: RST during recv */
@@ -781,8 +786,9 @@ handle_fin:
err_t
netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf)
{
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn",
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP,
return ERR_ARG;);
return netconn_recv_data_tcp(conn, new_buf, 0);
}
@@ -802,8 +808,9 @@ netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf)
err_t
netconn_recv_tcp_pbuf_flags(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags)
{
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) &&
NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;);
LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn",
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP,
return ERR_ARG;);
return netconn_recv_data_tcp(conn, new_buf, apiflags);
}
@@ -821,8 +828,9 @@ netconn_recv_tcp_pbuf_flags(struct netconn *conn, struct pbuf **new_buf, u8_t ap
err_t
netconn_recv_udp_raw_netbuf(struct netconn *conn, struct netbuf **new_buf)
{
LWIP_ERROR("netconn_recv_udp_raw_netbuf: invalid conn", (conn != NULL) &&
NETCONNTYPE_GROUP(netconn_type(conn)) != NETCONN_TCP, return ERR_ARG;);
LWIP_ERROR("netconn_recv_udp_raw_netbuf: invalid conn",
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) != NETCONN_TCP,
return ERR_ARG;);
return netconn_recv_data(conn, (void **)new_buf, 0);
}
@@ -841,8 +849,9 @@ netconn_recv_udp_raw_netbuf(struct netconn *conn, struct netbuf **new_buf)
err_t
netconn_recv_udp_raw_netbuf_flags(struct netconn *conn, struct netbuf **new_buf, u8_t apiflags)
{
LWIP_ERROR("netconn_recv_udp_raw_netbuf: invalid conn", (conn != NULL) &&
NETCONNTYPE_GROUP(netconn_type(conn)) != NETCONN_TCP, return ERR_ARG;);
LWIP_ERROR("netconn_recv_udp_raw_netbuf: invalid conn",
(conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) != NETCONN_TCP,
return ERR_ARG;);
return netconn_recv_data(conn, (void **)new_buf, apiflags);
}
@@ -866,7 +875,7 @@ netconn_recv(struct netconn *conn, struct netbuf **new_buf)
LWIP_ERROR("netconn_recv: invalid pointer", (new_buf != NULL), return ERR_ARG;);
*new_buf = NULL;
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
#if LWIP_TCP
#if (LWIP_UDP || LWIP_RAW)
@@ -943,9 +952,9 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
API_MSG_VAR_DECLARE(msg);
err_t err;
LWIP_ERROR("netconn_send: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_send: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %"U16_F" bytes\n", buf->p->tot_len));
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %" U16_F " bytes\n", buf->p->tot_len));
API_MSG_VAR_ALLOC(msg);
API_MSG_VAR_REF(msg).conn = conn;
@@ -971,8 +980,7 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
* @return ERR_OK if data was sent, any other err_t on error
*/
err_t
netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
u8_t apiflags, size_t *bytes_written)
netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size, u8_t apiflags, size_t *bytes_written)
{
struct netvector vector;
vector.ptr = dataptr;
@@ -994,8 +1002,11 @@ netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
* @return ERR_OK if data was sent, any other err_t on error
*/
err_t
netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u16_t vectorcnt,
u8_t apiflags, size_t *bytes_written)
netconn_write_vectors_partly(struct netconn *conn,
struct netvector *vectors,
u16_t vectorcnt,
u8_t apiflags,
size_t *bytes_written)
{
API_MSG_VAR_DECLARE(msg);
err_t err;
@@ -1003,8 +1014,8 @@ netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u1
size_t size;
int i;
LWIP_ERROR("netconn_write: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_write: invalid conn->type", (NETCONNTYPE_GROUP(conn->type) == NETCONN_TCP), return ERR_VAL;);
LWIP_ERROR("netconn_write: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_write: invalid conn->type", (NETCONNTYPE_GROUP(conn->type) == NETCONN_TCP), return ERR_VAL;);
dontblock = netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK);
#if LWIP_SO_SNDTIMEO
if (conn->send_timeout != 0) {
@@ -1092,7 +1103,7 @@ netconn_close_shutdown(struct netconn *conn, u8_t how)
err_t err;
LWIP_UNUSED_ARG(how);
LWIP_ERROR("netconn_close: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_close: invalid conn", (conn != NULL), return ERR_ARG;);
API_MSG_VAR_ALLOC(msg);
API_MSG_VAR_REF(msg).conn = conn;
@@ -1103,7 +1114,7 @@ netconn_close_shutdown(struct netconn *conn, u8_t how)
/* get the time we started, which is later compared to
sys_now() + conn->send_timeout */
API_MSG_VAR_REF(msg).msg.sd.time_started = sys_now();
#else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
#else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
API_MSG_VAR_REF(msg).msg.sd.polls_left =
((LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT + TCP_SLOW_INTERVAL - 1) / TCP_SLOW_INTERVAL) + 1;
#endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
@@ -1186,7 +1197,7 @@ netconn_join_leave_group(struct netconn *conn,
API_MSG_VAR_DECLARE(msg);
err_t err;
LWIP_ERROR("netconn_join_leave_group: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_join_leave_group: invalid conn", (conn != NULL), return ERR_ARG;);
API_MSG_VAR_ALLOC(msg);
@@ -1228,7 +1239,7 @@ netconn_join_leave_group_netif(struct netconn *conn,
API_MSG_VAR_DECLARE(msg);
err_t err;
LWIP_ERROR("netconn_join_leave_group: invalid conn", (conn != NULL), return ERR_ARG;);
LWIP_ERROR("netconn_join_leave_group: invalid conn", (conn != NULL), return ERR_ARG;);
API_MSG_VAR_ALLOC(msg);
@@ -1303,7 +1314,7 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr)
#if LWIP_MPU_COMPATIBLE
strncpy(API_VAR_REF(msg).name, name, DNS_MAX_NAME_LENGTH - 1);
API_VAR_REF(msg).name[DNS_MAX_NAME_LENGTH - 1] = 0;
#else /* LWIP_MPU_COMPATIBLE */
#else /* LWIP_MPU_COMPATIBLE */
msg.err = &err;
msg.sem = &sem;
API_VAR_REF(msg).addr = API_VAR_REF(addr);
@@ -1314,7 +1325,7 @@ netconn_gethostbyname(const char *name, ip_addr_t *addr)
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#if LWIP_NETCONN_SEM_PER_THREAD
API_VAR_REF(msg).sem = LWIP_NETCONN_THREAD_SEM_GET();
#else /* LWIP_NETCONN_SEM_PER_THREAD*/
#else /* LWIP_NETCONN_SEM_PER_THREAD*/
err = sys_sem_new(API_EXPR_REF(API_VAR_REF(msg).sem), 0);
if (err != ERR_OK) {
API_VAR_FREE(MEMP_DNS_API_MSG, msg);