mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-06-13 08:23:56 +08:00
rawapi.txt, api.h, api_lib.c, api_msg.h, api_msg.c, sockets.c, tcp.h, tcp.c, tcp_in.c, init.c, opt.h: rename backlog options with TCP_ prefix, limit the "backlog" parameter in an u8_t, 0 is interpreted as "smallest queue", add documentation in the rawapi.txt file.
This commit is contained in:
@@ -261,7 +261,7 @@ netconn_disconnect(struct netconn *conn)
|
||||
* Set a TCP netconn into listen mode
|
||||
*
|
||||
* @param conn the tcp netconn to set to listen mode
|
||||
* @param backlog the listen backlog (0 = max), only used if LWIP_LISTEN_BACKLOG==1
|
||||
* @param backlog the listen backlog, only used if TCP_LISTEN_BACKLOG==1
|
||||
* @return ERR_OK if the netconn was set to listen (UDP and RAW netconns
|
||||
* don't return any error (yet?))
|
||||
*/
|
||||
@@ -270,16 +270,16 @@ netconn_listen_with_backlog(struct netconn *conn, u8_t backlog)
|
||||
{
|
||||
struct api_msg msg;
|
||||
|
||||
/* This does no harm. If LWIP_LISTEN_BACKLOG is off, backlog is unused. */
|
||||
/* This does no harm. If TCP_LISTEN_BACKLOG is off, backlog is unused. */
|
||||
LWIP_UNUSED_ARG(backlog);
|
||||
|
||||
LWIP_ERROR("netconn_listen: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
#if LWIP_LISTEN_BACKLOG
|
||||
msg.msg.msg.lb.backlog = backlog;
|
||||
#endif /* LWIP_LISTEN_BACKLOG */
|
||||
msg.function = do_listen;
|
||||
msg.msg.conn = conn;
|
||||
#if TCP_LISTEN_BACKLOG
|
||||
msg.msg.msg.lb.backlog = backlog;
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
TCPIP_APIMSG(&msg);
|
||||
return conn->err;
|
||||
}
|
||||
@@ -309,7 +309,7 @@ netconn_accept(struct netconn *conn)
|
||||
/* Register event with callback */
|
||||
API_EVENT(conn, NETCONN_EVT_RCVMINUS, 0);
|
||||
|
||||
#if LWIP_LISTEN_BACKLOG
|
||||
#if TCP_LISTEN_BACKLOG
|
||||
if (newconn != NULL) {
|
||||
/* Let the stack know that we have accepted the connection. */
|
||||
struct api_msg msg;
|
||||
@@ -317,7 +317,7 @@ netconn_accept(struct netconn *conn)
|
||||
msg.msg.conn = conn;
|
||||
TCPIP_APIMSG(&msg);
|
||||
}
|
||||
#endif /* LWIP_LISTEN_BACKLOG */
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
}
|
||||
|
||||
return newconn;
|
||||
|
||||
@@ -717,13 +717,17 @@ do_listen(struct api_msg_msg *msg)
|
||||
if (msg->conn->pcb.tcp != NULL) {
|
||||
if (msg->conn->type == NETCONN_TCP) {
|
||||
if (msg->conn->pcb.tcp->state == CLOSED) {
|
||||
#if TCP_LISTEN_BACKLOG
|
||||
struct tcp_pcb* lpcb = tcp_listen_with_backlog(msg->conn->pcb.tcp, msg->msg.lb.backlog);
|
||||
#else /* TCP_LISTEN_BACKLOG */
|
||||
struct tcp_pcb* lpcb = tcp_listen(msg->conn->pcb.tcp);
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
if (lpcb == NULL) {
|
||||
msg->conn->err = ERR_MEM;
|
||||
} else {
|
||||
/* delete the recvmbox and allocate the acceptmbox */
|
||||
if (msg->conn->recvmbox != SYS_MBOX_NULL) {
|
||||
/* @todo: should we drain the recvmbox here? */
|
||||
/** @todo: should we drain the recvmbox here? */
|
||||
sys_mbox_free(msg->conn->recvmbox);
|
||||
msg->conn->recvmbox = NULL;
|
||||
}
|
||||
@@ -735,9 +739,6 @@ do_listen(struct api_msg_msg *msg)
|
||||
if (msg->conn->err == ERR_OK) {
|
||||
msg->conn->state = NETCONN_LISTEN;
|
||||
msg->conn->pcb.tcp = lpcb;
|
||||
#if LWIP_LISTEN_BACKLOG
|
||||
tcp_backlog(lpcb, msg->msg.lb.backlog);
|
||||
#endif /* LWIP_LISTEN_BACKLOG */
|
||||
tcp_arg(msg->conn->pcb.tcp, msg->conn);
|
||||
tcp_accept(msg->conn->pcb.tcp, accept_function);
|
||||
}
|
||||
@@ -803,11 +804,11 @@ do_recv(struct api_msg_msg *msg)
|
||||
if (!ERR_IS_FATAL(msg->conn->err)) {
|
||||
if (msg->conn->pcb.tcp != NULL) {
|
||||
if (msg->conn->type == NETCONN_TCP) {
|
||||
#if LWIP_LISTEN_BACKLOG
|
||||
#if TCP_LISTEN_BACKLOG
|
||||
if (msg->conn->pcb.tcp->state == LISTEN) {
|
||||
tcp_accepted(msg->conn->pcb.tcp);
|
||||
} else
|
||||
#endif /* LWIP_LISTEN_BACKLOG */
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
{
|
||||
tcp_recved(msg->conn->pcb.tcp, msg->msg.r.len);
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
|
||||
* The socket may not have been used for another connection previously.
|
||||
*
|
||||
* @param s the socket to set to listening mode
|
||||
* @param backlog (ATTENTION: this is not implemented, yet!)
|
||||
* @param backlog (ATTENTION: need TCP_LISTEN_BACKLOG=1)
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
int
|
||||
@@ -431,13 +431,19 @@ lwip_listen(int s, int backlog)
|
||||
err_t err;
|
||||
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d, backlog=%d)\n", s, backlog));
|
||||
LWIP_ASSERT("backlog must be between 0 and 255", backlog > 0);
|
||||
LWIP_ASSERT("backlog must be between 0 and 255", backlog <= 0xff);
|
||||
|
||||
sock = get_socket(s);
|
||||
if (!sock)
|
||||
return -1;
|
||||
|
||||
/* limit the "backlog" parameter to fit in an u8_t */
|
||||
if (backlog < 0) {
|
||||
backlog = 0;
|
||||
}
|
||||
if (backlog > 0xff) {
|
||||
backlog = 0xff;
|
||||
}
|
||||
|
||||
err = netconn_listen_with_backlog(sock->conn, backlog);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
|
||||
Reference in New Issue
Block a user