mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-10 17:43:39 +08:00
Implement LWIP_SO_RCVTIMEO configuration option to enable/disable SO_RCVTIMEO on UDP sockets/netconn.
This commit is contained in:
@@ -226,7 +226,9 @@ netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto,
|
||||
}
|
||||
conn->state = NETCONN_NONE;
|
||||
conn->socket = 0;
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
conn->recv_timeout = 0;
|
||||
#endif /* LWIP_SO_RCVTIMEO */
|
||||
conn->callback = callback;
|
||||
conn->recv_avail = 0;
|
||||
|
||||
@@ -234,7 +236,7 @@ netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto,
|
||||
msg.msg.msg.bc.port = proto; /* misusing the port field */
|
||||
msg.msg.conn = conn;
|
||||
api_msg_post(&msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
|
||||
if ( conn->err != ERR_OK ) {
|
||||
memp_free(MEMP_NETCONN, conn);
|
||||
@@ -272,7 +274,7 @@ netconn_delete(struct netconn *conn)
|
||||
msg.type = API_MSG_DELCONN;
|
||||
msg.msg.conn = conn;
|
||||
api_msg_post(&msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
|
||||
/* Drain the recvmbox. */
|
||||
if (conn->recvmbox != SYS_MBOX_NULL) {
|
||||
@@ -387,7 +389,7 @@ netconn_bind(struct netconn *conn, struct ip_addr *addr,
|
||||
msg.msg.msg.bc.ipaddr = addr;
|
||||
msg.msg.msg.bc.port = port;
|
||||
api_msg_post(&msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
return conn->err;
|
||||
}
|
||||
|
||||
@@ -414,7 +416,7 @@ netconn_connect(struct netconn *conn, struct ip_addr *addr,
|
||||
msg.msg.msg.bc.ipaddr = addr;
|
||||
msg.msg.msg.bc.port = port;
|
||||
api_msg_post(&msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
return conn->err;
|
||||
}
|
||||
|
||||
@@ -430,7 +432,7 @@ netconn_disconnect(struct netconn *conn)
|
||||
msg.type = API_MSG_DISCONNECT;
|
||||
msg.msg.conn = conn;
|
||||
api_msg_post(&msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
return conn->err;
|
||||
|
||||
}
|
||||
@@ -454,7 +456,7 @@ netconn_listen(struct netconn *conn)
|
||||
msg.type = API_MSG_LISTEN;
|
||||
msg.msg.conn = conn;
|
||||
api_msg_post(&msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
return conn->err;
|
||||
}
|
||||
|
||||
@@ -467,7 +469,7 @@ netconn_accept(struct netconn *conn)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sys_mbox_fetch(conn->acceptmbox, (void *)&newconn, 0);
|
||||
sys_mbox_fetch(conn->acceptmbox, (void *)&newconn);
|
||||
/* Register event with callback */
|
||||
if (conn->callback)
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVMINUS, 0);
|
||||
@@ -510,7 +512,7 @@ netconn_recv(struct netconn *conn)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sys_mbox_fetch(conn->recvmbox, (void *)&p, 0);
|
||||
sys_mbox_fetch(conn->recvmbox, (void *)&p);
|
||||
|
||||
if (p != NULL)
|
||||
{
|
||||
@@ -548,9 +550,13 @@ netconn_recv(struct netconn *conn)
|
||||
}
|
||||
api_msg_post(&msg);
|
||||
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
} else {
|
||||
sys_mbox_fetch(conn->recvmbox, (void *)&buf, conn->recv_timeout);
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
sys_mbox_fetch_timeout(conn->recvmbox, (void *)&buf, conn->recv_timeout);
|
||||
#else
|
||||
sys_mbox_fetch(conn->recvmbox, (void *)&buf);
|
||||
#endif /* LWIP_SO_RCVTIMEO*/
|
||||
if (buf!=NULL)
|
||||
{ conn->recv_avail -= buf->p->tot_len;
|
||||
/* Register event with callback */
|
||||
@@ -587,7 +593,7 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
|
||||
msg.msg.msg.p = buf->p;
|
||||
api_msg_post(&msg);
|
||||
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
return conn->err;
|
||||
}
|
||||
|
||||
@@ -635,7 +641,7 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy)
|
||||
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_write: writing %d bytes (%d)\n", len, copy));
|
||||
msg.msg.msg.w.len = len;
|
||||
api_msg_post(&msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
if (conn->err == ERR_OK) {
|
||||
dataptr = (void *)((u8_t *)dataptr + len);
|
||||
size -= len;
|
||||
@@ -666,7 +672,7 @@ netconn_close(struct netconn *conn)
|
||||
msg.type = API_MSG_CLOSE;
|
||||
msg.msg.conn = conn;
|
||||
api_msg_post(&msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
if (conn->err == ERR_MEM &&
|
||||
conn->sem != SYS_SEM_NULL) {
|
||||
sys_sem_wait(conn->sem);
|
||||
|
||||
@@ -34,17 +34,21 @@
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
|
||||
static const char *err_strerr[] = {"Ok.",
|
||||
"Out of memory error.",
|
||||
"Buffer error.",
|
||||
"Connection aborted.",
|
||||
"Connection reset.",
|
||||
"Connection closed.",
|
||||
"Not connected.",
|
||||
"Illegal value.",
|
||||
"Illegal argument.",
|
||||
"Routing problem.",
|
||||
"Address in use."
|
||||
static const char *err_strerr[] = {
|
||||
"Ok.", /* ERR_OK 0 */
|
||||
"Out of memory error.", /* ERR_MEM -1 */
|
||||
"Buffer error.", /* ERR_BUF -2 */
|
||||
"Connection aborted.", /* ERR_ABRT -3 */
|
||||
"Connection reset.", /* ERR_RST -4 */
|
||||
"Connection closed.", /* ERR_CLSD -5 */
|
||||
"Not connected.", /* ERR_CONN -6 */
|
||||
"Illegal value.", /* ERR_VAL -7 */
|
||||
"Illegal argument.", /* ERR_ARG -8 */
|
||||
"Routing problem.", /* ERR_RTE -9 */
|
||||
"Address in use.", /* ERR_USE -10 */
|
||||
"Low-level netif error.", /* ERR_IF -11 */
|
||||
"Already connected.", /* ERR_ISCONN -12 */
|
||||
"Timeout." /* ERR_TIMEOUT -13 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -996,8 +996,11 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
/* UNIMPL case SO_DONTROUTE: */
|
||||
case SO_ERROR:
|
||||
case SO_KEEPALIVE:
|
||||
/* UNIMPL case SO_CONTIMEO: */
|
||||
/* UNIMPL case SO_SNDTIMEO: */
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
case SO_RCVTIMEO:
|
||||
#endif /* LWIP_SO_RCVTIMEO */
|
||||
/* UNIMPL case SO_OOBINLINE: */
|
||||
/* UNIMPL case SO_RCVBUF: */
|
||||
/* UNIMPL case SO_SNDBUF: */
|
||||
@@ -1124,9 +1127,11 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n", s, *(int *)optval));
|
||||
break;
|
||||
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
case SO_RCVTIMEO:
|
||||
*(int *)optval = sock->conn->recv_timeout;
|
||||
break;
|
||||
#endif /* LWIP_SO_RCVTIMEO */
|
||||
} /* switch */
|
||||
break;
|
||||
|
||||
@@ -1191,8 +1196,11 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
||||
/* UNIMPL case SO_DEBUG: */
|
||||
/* UNIMPL case SO_DONTROUTE: */
|
||||
case SO_KEEPALIVE:
|
||||
/* UNIMPL case case SO_CONTIMEO: */
|
||||
/* UNIMPL case case SO_SNDTIMEO: */
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
case SO_RCVTIMEO:
|
||||
#endif /* LWIP_SO_RCVTIMEO */
|
||||
/* UNIMPL case SO_OOBINLINE: */
|
||||
/* UNIMPL case SO_RCVBUF: */
|
||||
/* UNIMPL case SO_SNDBUF: */
|
||||
@@ -1292,9 +1300,11 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
||||
}
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, optname=0x%x, ..) -> %s\n", s, optname, (*(int*)optval?"on":"off")));
|
||||
break;
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
case SO_RCVTIMEO:
|
||||
sock->conn->recv_timeout = ( *(int*)optval );
|
||||
break;
|
||||
#endif /* LWIP_SO_RCVTIMEO */
|
||||
} /* switch */
|
||||
break;
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ tcpip_thread(void *arg)
|
||||
}
|
||||
|
||||
while (1) { /* MAIN Loop */
|
||||
sys_mbox_fetch(mbox, (void *)&msg, 0);
|
||||
sys_mbox_fetch(mbox, (void *)&msg);
|
||||
switch (msg->type) {
|
||||
case TCPIP_MSG_API:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
|
||||
|
||||
Reference in New Issue
Block a user