Implement SO_RCVTIMEO on UDP sockets/netconn.
This commit is contained in:
@@ -224,16 +224,17 @@ netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto,
|
||||
memp_free(MEMP_NETCONN, conn);
|
||||
return NULL;
|
||||
}
|
||||
conn->state = NETCONN_NONE;
|
||||
conn->socket = 0;
|
||||
conn->callback = callback;
|
||||
conn->recv_avail = 0;
|
||||
conn->state = NETCONN_NONE;
|
||||
conn->socket = 0;
|
||||
conn->recv_timeout = 0;
|
||||
conn->callback = callback;
|
||||
conn->recv_avail = 0;
|
||||
|
||||
msg.type = API_MSG_NEWCONN;
|
||||
msg.msg.msg.bc.port = proto; /* misusing the port field */
|
||||
msg.msg.conn = conn;
|
||||
api_msg_post(&msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
|
||||
if ( conn->err != ERR_OK ) {
|
||||
memp_free(MEMP_NETCONN, conn);
|
||||
@@ -271,7 +272,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);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
|
||||
/* Drain the recvmbox. */
|
||||
if (conn->recvmbox != SYS_MBOX_NULL) {
|
||||
@@ -386,7 +387,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);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
return conn->err;
|
||||
}
|
||||
|
||||
@@ -413,7 +414,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);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
return conn->err;
|
||||
}
|
||||
|
||||
@@ -429,7 +430,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);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
return conn->err;
|
||||
|
||||
}
|
||||
@@ -453,7 +454,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);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
return conn->err;
|
||||
}
|
||||
|
||||
@@ -466,7 +467,7 @@ netconn_accept(struct netconn *conn)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sys_mbox_fetch(conn->acceptmbox, (void *)&newconn);
|
||||
sys_mbox_fetch(conn->acceptmbox, (void *)&newconn, 0);
|
||||
/* Register event with callback */
|
||||
if (conn->callback)
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVMINUS, 0);
|
||||
@@ -481,7 +482,7 @@ netconn_recv(struct netconn *conn)
|
||||
struct netbuf *buf = NULL;
|
||||
struct pbuf *p;
|
||||
u16_t len;
|
||||
|
||||
|
||||
if (conn == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -509,7 +510,7 @@ netconn_recv(struct netconn *conn)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sys_mbox_fetch(conn->recvmbox, (void *)&p);
|
||||
sys_mbox_fetch(conn->recvmbox, (void *)&p, 0);
|
||||
|
||||
if (p != NULL)
|
||||
{
|
||||
@@ -547,13 +548,15 @@ netconn_recv(struct netconn *conn)
|
||||
}
|
||||
api_msg_post(&msg);
|
||||
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
} else {
|
||||
sys_mbox_fetch(conn->recvmbox, (void *)&buf);
|
||||
conn->recv_avail -= buf->p->tot_len;
|
||||
/* Register event with callback */
|
||||
if (conn->callback)
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVMINUS, buf->p->tot_len);
|
||||
sys_mbox_fetch(conn->recvmbox, (void *)&buf, conn->recv_timeout);
|
||||
if (buf!=NULL)
|
||||
{ conn->recv_avail -= buf->p->tot_len;
|
||||
/* Register event with callback */
|
||||
if (conn->callback)
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVMINUS, buf->p->tot_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -584,7 +587,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);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
return conn->err;
|
||||
}
|
||||
|
||||
@@ -632,7 +635,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);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
if (conn->err == ERR_OK) {
|
||||
dataptr = (void *)((u8_t *)dataptr + len);
|
||||
size -= len;
|
||||
@@ -663,7 +666,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);
|
||||
sys_mbox_fetch(conn->mbox, NULL, 0);
|
||||
if (conn->err == ERR_MEM &&
|
||||
conn->sem != SYS_SEM_NULL) {
|
||||
sys_sem_wait(conn->sem);
|
||||
|
||||
Reference in New Issue
Block a user