allow enabling socket API without (public) netconn API - netconn API is still used by sockets, but keeping it private (static) should allow better compiler optimizations

This commit is contained in:
sg 2015-01-17 14:42:50 +01:00
parent 69ee35c909
commit c1804810d8
9 changed files with 100 additions and 61 deletions

View File

@ -6,6 +6,11 @@ HISTORY
++ New features:
2015-01-17: Simon Goldschmidt
* api: allow enabling socket API without (public) netconn API - netconn API is
still used by sockets, but keeping it private (static) should allow better
compiler optimizations
2015-01-16: Simon Goldschmidt
* tcp_in.c: fixed bug #20506 "Initial congestion window is very small" again
by implementing the calculation formula from RFC3390

View File

@ -59,6 +59,18 @@
#include <string.h>
/* If the netconn API is not required publicly, then we include the necessary
files here to get the implementation */
#if !LWIP_NETCONN
#undef LWIP_NETCONN
#define LWIP_NETCONN 1
#include "api_msg.c"
#include "api_lib.c"
#include "netbuf.c"
#undef LWIP_NETCONN
#define LWIP_NETCONN 0
#endif
#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipXaddr, port) do { \
(sin)->sin_len = sizeof(struct sockaddr_in); \
(sin)->sin_family = AF_INET; \

View File

@ -99,12 +99,12 @@ tcpip_thread(void *arg)
continue;
}
switch (msg->type) {
#if LWIP_NETCONN
#if LWIP_NETCONN || LWIP_SOCKET
case TCPIP_MSG_API:
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
msg->msg.apimsg->function(&(msg->msg.apimsg->msg));
break;
#endif /* LWIP_NETCONN */
#endif /* LWIP_NETCONN || LWIP_SOCKET */
#if !LWIP_TCPIP_CORE_LOCKING_INPUT
case TCPIP_MSG_INPKT:
@ -316,7 +316,7 @@ tcpip_untimeout(sys_timeout_handler h, void *arg)
}
#endif /* LWIP_TCPIP_TIMEOUT */
#if LWIP_NETCONN
#if LWIP_NETCONN || LWIP_SOCKET
/**
* Call the lower part of a netconn_* function
* This function is then running in the thread context
@ -351,7 +351,7 @@ tcpip_apimsg(struct api_msg *apimsg)
return ERR_VAL;
}
#endif /* LWIP_NETCONN */
#endif /* LWIP_NETCONN || LWIP_SOCKET */
#if LWIP_NETIF_API
#if !LWIP_TCPIP_CORE_LOCKING

View File

@ -149,9 +149,6 @@
#if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1))
#error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h"
#endif
#if (!LWIP_NETCONN && LWIP_SOCKET)
#error "If you want to use Socket API, you have to define LWIP_NETCONN=1 in your lwipopts.h"
#endif
#if (LWIP_PPP_API && (NO_SYS==1))
#error "If you want to use PPP API, you have to define NO_SYS=0 in your lwipopts.h"
#endif

View File

@ -34,7 +34,14 @@
#include "lwip/opt.h"
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
#if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
/* don't export the netconn functions when socket API is enabled but netconn API is disabled */
#if LWIP_NETCONN
#define LWIP_NETCONN_SCOPE
#else /* LWIP_NETCONN */
#define LWIP_NETCONN_SCOPE static
#endif /* LWIP_NETCONN */
#include <stddef.h> /* for size_t */
@ -240,39 +247,39 @@ struct netconn {
/* Network connection functions: */
#define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
#define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
struct
LWIP_NETCONN_SCOPE struct
netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
netconn_callback callback);
err_t netconn_delete(struct netconn *conn);
LWIP_NETCONN_SCOPE err_t netconn_delete(struct netconn *conn);
/** Get the type of a netconn (as enum netconn_type). */
#define netconn_type(conn) (conn->type)
err_t netconn_getaddr(struct netconn *conn, ip_addr_t *addr,
LWIP_NETCONN_SCOPE err_t netconn_getaddr(struct netconn *conn, ip_addr_t *addr,
u16_t *port, u8_t local);
#define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
#define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
err_t netconn_bind(struct netconn *conn, ip_addr_t *addr, u16_t port);
err_t netconn_connect(struct netconn *conn, ip_addr_t *addr, u16_t port);
err_t netconn_disconnect (struct netconn *conn);
err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
LWIP_NETCONN_SCOPE err_t netconn_bind(struct netconn *conn, ip_addr_t *addr, u16_t port);
LWIP_NETCONN_SCOPE err_t netconn_connect(struct netconn *conn, ip_addr_t *addr, u16_t port);
LWIP_NETCONN_SCOPE err_t netconn_disconnect (struct netconn *conn);
LWIP_NETCONN_SCOPE err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
#define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
err_t netconn_accept(struct netconn *conn, struct netconn **new_conn);
err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf);
err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf);
void netconn_recved(struct netconn *conn, u32_t length);
err_t netconn_sendto(struct netconn *conn, struct netbuf *buf,
LWIP_NETCONN_SCOPE err_t netconn_accept(struct netconn *conn, struct netconn **new_conn);
LWIP_NETCONN_SCOPE err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf);
LWIP_NETCONN_SCOPE err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf);
LWIP_NETCONN_SCOPE void netconn_recved(struct netconn *conn, u32_t length);
LWIP_NETCONN_SCOPE err_t netconn_sendto(struct netconn *conn, struct netbuf *buf,
ip_addr_t *addr, u16_t port);
err_t netconn_send(struct netconn *conn, struct netbuf *buf);
err_t netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
LWIP_NETCONN_SCOPE err_t netconn_send(struct netconn *conn, struct netbuf *buf);
LWIP_NETCONN_SCOPE err_t netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
u8_t apiflags, size_t *bytes_written);
#define netconn_write(conn, dataptr, size, apiflags) \
netconn_write_partly(conn, dataptr, size, apiflags, NULL)
err_t netconn_close(struct netconn *conn);
err_t netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx);
LWIP_NETCONN_SCOPE err_t netconn_close(struct netconn *conn);
LWIP_NETCONN_SCOPE err_t netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx);
#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
err_t netconn_join_leave_group(struct netconn *conn, ip_addr_t *multiaddr,
LWIP_NETCONN_SCOPE err_t netconn_join_leave_group(struct netconn *conn, ip_addr_t *multiaddr,
ip_addr_t *netif_addr, enum netconn_igmp join_or_leave);
#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
#if LWIP_DNS
@ -343,6 +350,6 @@ void netconn_thread_cleanup(void);
}
#endif
#endif /* LWIP_NETCONN */
#endif /* LWIP_NETCONN || LWIP_SOCKET */
#endif /* LWIP_HDR_API_H */

View File

@ -34,7 +34,14 @@
#include "lwip/opt.h"
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
#if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
/* don't export the netconn functions when socket API is enabled but netconn API is disabled */
#if LWIP_NETCONN
#define LWIP_NETCONN_SCOPE
#else /* LWIP_NETCONN */
#define LWIP_NETCONN_SCOPE static
#endif /* LWIP_NETCONN */
#include <stddef.h> /* for size_t */
@ -165,33 +172,33 @@ struct dns_api_msg {
};
#endif /* LWIP_DNS */
void lwip_netconn_do_newconn ( struct api_msg_msg *msg);
void lwip_netconn_do_delconn ( struct api_msg_msg *msg);
void lwip_netconn_do_bind ( struct api_msg_msg *msg);
void lwip_netconn_do_connect ( struct api_msg_msg *msg);
void lwip_netconn_do_disconnect ( struct api_msg_msg *msg);
void lwip_netconn_do_listen ( struct api_msg_msg *msg);
void lwip_netconn_do_send ( struct api_msg_msg *msg);
void lwip_netconn_do_recv ( struct api_msg_msg *msg);
void lwip_netconn_do_write ( struct api_msg_msg *msg);
void lwip_netconn_do_getaddr ( struct api_msg_msg *msg);
void lwip_netconn_do_close ( struct api_msg_msg *msg);
void lwip_netconn_do_shutdown ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_newconn ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_delconn ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_bind ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_connect ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_disconnect ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_listen ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_send ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_recv ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_write ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_getaddr ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_close ( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_shutdown ( struct api_msg_msg *msg);
#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
void lwip_netconn_do_join_leave_group( struct api_msg_msg *msg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_join_leave_group( struct api_msg_msg *msg);
#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
#if LWIP_DNS
void lwip_netconn_do_gethostbyname(void *arg);
LWIP_NETCONN_SCOPE void lwip_netconn_do_gethostbyname(void *arg);
#endif /* LWIP_DNS */
struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
void netconn_free(struct netconn *conn);
LWIP_NETCONN_SCOPE struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
LWIP_NETCONN_SCOPE void netconn_free(struct netconn *conn);
#ifdef __cplusplus
}
#endif
#endif /* LWIP_NETCONN */
#endif /* LWIP_NETCONN || LWIP_SOCKET */
#endif /* LWIP_HDR_API_MSG_H */

View File

@ -51,10 +51,10 @@ LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdat
LWIP_MEMPOOL(FRAG_PBUF, MEMP_NUM_FRAG_PBUF, sizeof(struct pbuf_custom_ref),"FRAG_PBUF")
#endif /* IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */
#if LWIP_NETCONN
#if LWIP_NETCONN || LWIP_SOCKET
LWIP_MEMPOOL(NETBUF, MEMP_NUM_NETBUF, sizeof(struct netbuf), "NETBUF")
LWIP_MEMPOOL(NETCONN, MEMP_NUM_NETCONN, sizeof(struct netconn), "NETCONN")
#endif /* LWIP_NETCONN */
#endif /* LWIP_NETCONN || LWIP_SOCKET */
#if NO_SYS==0
LWIP_MEMPOOL(TCPIP_MSG_API, MEMP_NUM_TCPIP_MSG_API, sizeof(struct tcpip_msg), "TCPIP_MSG_API")

View File

@ -32,6 +32,15 @@
#ifndef LWIP_HDR_NETBUF_H
#define LWIP_HDR_NETBUF_H
#if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
/* don't export the netbuf functions when socket API is enabled but netconn API is disabled */
#if LWIP_NETCONN
#define LWIP_NETCONN_SCOPE
#else /* LWIP_NETCONN */
#define LWIP_NETCONN_SCOPE static
#endif /* LWIP_NETCONN */
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
@ -62,19 +71,19 @@ struct netbuf {
};
/* Network buffer functions: */
struct netbuf * netbuf_new (void);
void netbuf_delete (struct netbuf *buf);
void * netbuf_alloc (struct netbuf *buf, u16_t size);
void netbuf_free (struct netbuf *buf);
err_t netbuf_ref (struct netbuf *buf,
LWIP_NETCONN_SCOPE struct netbuf * netbuf_new (void);
LWIP_NETCONN_SCOPE void netbuf_delete (struct netbuf *buf);
LWIP_NETCONN_SCOPE void * netbuf_alloc (struct netbuf *buf, u16_t size);
LWIP_NETCONN_SCOPE void netbuf_free (struct netbuf *buf);
LWIP_NETCONN_SCOPE err_t netbuf_ref (struct netbuf *buf,
const void *dataptr, u16_t size);
void netbuf_chain (struct netbuf *head,
LWIP_NETCONN_SCOPE void netbuf_chain (struct netbuf *head,
struct netbuf *tail);
err_t netbuf_data (struct netbuf *buf,
LWIP_NETCONN_SCOPE err_t netbuf_data (struct netbuf *buf,
void **dataptr, u16_t *len);
s8_t netbuf_next (struct netbuf *buf);
void netbuf_first (struct netbuf *buf);
LWIP_NETCONN_SCOPE s8_t netbuf_next (struct netbuf *buf);
LWIP_NETCONN_SCOPE void netbuf_first (struct netbuf *buf);
#define netbuf_copy_partial(buf, dataptr, len, offset) \
@ -109,4 +118,6 @@ void netbuf_first (struct netbuf *buf);
}
#endif
#endif /* LWIP_NETCONN || LWIP_SOCKET */
#endif /* LWIP_HDR_NETBUF_H */

View File

@ -137,9 +137,9 @@ struct tcpip_callback_msg;
void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg);
#if LWIP_NETCONN
#if LWIP_NETCONN || LWIP_SOCKET
err_t tcpip_apimsg(struct api_msg *apimsg);
#endif /* LWIP_NETCONN */
#endif /* LWIP_NETCONN || LWIP_SOCKET */
err_t tcpip_input(struct pbuf *p, struct netif *inp);
@ -174,9 +174,9 @@ err_t tcpip_untimeout(sys_timeout_handler h, void *arg);
#endif /* LWIP_TCPIP_TIMEOUT */
enum tcpip_msg_type {
#if LWIP_NETCONN
#if LWIP_NETCONN || LWIP_SOCKET
TCPIP_MSG_API,
#endif /* LWIP_NETCONN */
#endif /* LWIP_NETCONN || LWIP_SOCKET */
TCPIP_MSG_INPKT,
#if LWIP_NETIF_API
TCPIP_MSG_NETIFAPI,
@ -196,9 +196,9 @@ struct tcpip_msg {
enum tcpip_msg_type type;
sys_sem_t *sem;
union {
#if LWIP_NETCONN
#if LWIP_NETCONN || LWIP_SOCKET
struct api_msg *apimsg;
#endif /* LWIP_NETCONN */
#endif /* LWIP_NETCONN || LWIP_SOCKET */
#if LWIP_NETIF_API
struct netifapi_msg *netifapimsg;
#endif /* LWIP_NETIF_API */