mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-11-18 20:10:53 +00:00
Missing recv_timeout initialize in accept_function. Minor style fix (indent, mbox checking...)
This commit is contained in:
parent
913a99dd35
commit
9ec08fa76a
@ -186,7 +186,6 @@ err_tcp(void *arg, err_t err)
|
|||||||
|
|
||||||
conn->pcb.tcp = NULL;
|
conn->pcb.tcp = NULL;
|
||||||
|
|
||||||
|
|
||||||
conn->err = err;
|
conn->err = err;
|
||||||
if (conn->recvmbox != SYS_MBOX_NULL) {
|
if (conn->recvmbox != SYS_MBOX_NULL) {
|
||||||
/* Register event with callback */
|
/* Register event with callback */
|
||||||
@ -224,7 +223,6 @@ setup_tcp(struct netconn *conn)
|
|||||||
static err_t
|
static err_t
|
||||||
accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
|
accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
|
||||||
{
|
{
|
||||||
sys_mbox_t mbox;
|
|
||||||
struct netconn *newconn;
|
struct netconn *newconn;
|
||||||
struct netconn *conn;
|
struct netconn *conn;
|
||||||
|
|
||||||
@ -234,7 +232,6 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
|
|||||||
#endif /* TCP_DEBUG */
|
#endif /* TCP_DEBUG */
|
||||||
#endif /* API_MSG_DEBUG */
|
#endif /* API_MSG_DEBUG */
|
||||||
conn = (struct netconn *)arg;
|
conn = (struct netconn *)arg;
|
||||||
mbox = conn->acceptmbox;
|
|
||||||
newconn = memp_malloc(MEMP_NETCONN);
|
newconn = memp_malloc(MEMP_NETCONN);
|
||||||
if (newconn == NULL) {
|
if (newconn == NULL) {
|
||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
@ -252,8 +249,8 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
|
|||||||
}
|
}
|
||||||
newconn->sem = sys_sem_new(0);
|
newconn->sem = sys_sem_new(0);
|
||||||
if (newconn->sem == SYS_SEM_NULL) {
|
if (newconn->sem == SYS_SEM_NULL) {
|
||||||
sys_mbox_free(newconn->recvmbox);
|
|
||||||
sys_mbox_free(newconn->mbox);
|
sys_mbox_free(newconn->mbox);
|
||||||
|
sys_mbox_free(newconn->recvmbox);
|
||||||
memp_free(MEMP_NETCONN, newconn);
|
memp_free(MEMP_NETCONN, newconn);
|
||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
}
|
}
|
||||||
@ -272,8 +269,11 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
|
|||||||
newconn->callback = conn->callback;
|
newconn->callback = conn->callback;
|
||||||
newconn->socket = -1;
|
newconn->socket = -1;
|
||||||
newconn->recv_avail = 0;
|
newconn->recv_avail = 0;
|
||||||
|
#if LWIP_SO_RCVTIMEO
|
||||||
|
newconn->recv_timeout = 0;
|
||||||
|
#endif /* LWIP_SO_RCVTIMEO */
|
||||||
|
|
||||||
sys_mbox_post(mbox, newconn);
|
sys_mbox_post( conn->acceptmbox, newconn);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
#endif /* LWIP_TCP */
|
#endif /* LWIP_TCP */
|
||||||
@ -338,8 +338,7 @@ do_newconn(struct api_msg_msg *msg)
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sys_mbox_post(msg->conn->mbox, NULL);
|
sys_mbox_post(msg->conn->mbox, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,8 +617,7 @@ do_listen(struct api_msg_msg *msg)
|
|||||||
msg->conn->err = ERR_MEM;
|
msg->conn->err = ERR_MEM;
|
||||||
} else {
|
} else {
|
||||||
if (msg->conn->acceptmbox == SYS_MBOX_NULL) {
|
if (msg->conn->acceptmbox == SYS_MBOX_NULL) {
|
||||||
msg->conn->acceptmbox = sys_mbox_new();
|
if ((msg->conn->acceptmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
|
||||||
if (msg->conn->acceptmbox == SYS_MBOX_NULL) {
|
|
||||||
msg->conn->err = ERR_MEM;
|
msg->conn->err = ERR_MEM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -748,8 +746,7 @@ do_close(struct api_msg_msg *msg)
|
|||||||
case NETCONN_TCP:
|
case NETCONN_TCP:
|
||||||
if (msg->conn->pcb.tcp->state == LISTEN) {
|
if (msg->conn->pcb.tcp->state == LISTEN) {
|
||||||
err = tcp_close(msg->conn->pcb.tcp);
|
err = tcp_close(msg->conn->pcb.tcp);
|
||||||
}
|
} else if (msg->conn->pcb.tcp->state == CLOSE_WAIT) {
|
||||||
else if (msg->conn->pcb.tcp->state == CLOSE_WAIT) {
|
|
||||||
err = tcp_output(msg->conn->pcb.tcp);
|
err = tcp_output(msg->conn->pcb.tcp);
|
||||||
}
|
}
|
||||||
msg->conn->err = err;
|
msg->conn->err = err;
|
||||||
|
@ -53,14 +53,13 @@ struct lwip_socket {
|
|||||||
int err;
|
int err;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lwip_select_cb
|
struct lwip_select_cb {
|
||||||
{
|
struct lwip_select_cb *next;
|
||||||
struct lwip_select_cb *next;
|
fd_set *readset;
|
||||||
fd_set *readset;
|
fd_set *writeset;
|
||||||
fd_set *writeset;
|
fd_set *exceptset;
|
||||||
fd_set *exceptset;
|
int sem_signalled;
|
||||||
int sem_signalled;
|
sys_sem_t sem;
|
||||||
sys_sem_t sem;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct lwip_socket sockets[NUM_SOCKETS];
|
static struct lwip_socket sockets[NUM_SOCKETS];
|
||||||
@ -197,8 +196,8 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
|||||||
newsock = alloc_socket(newconn);
|
newsock = alloc_socket(newconn);
|
||||||
if (newsock == -1) {
|
if (newsock == -1) {
|
||||||
netconn_delete(newconn);
|
netconn_delete(newconn);
|
||||||
sock_set_errno(sock, ENOBUFS);
|
sock_set_errno(sock, ENOBUFS);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
newconn->callback = event_callback;
|
newconn->callback = event_callback;
|
||||||
sock = get_socket(newsock);
|
sock = get_socket(newsock);
|
||||||
@ -305,7 +304,7 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
|
|||||||
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(remote_port)));
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(remote_port)));
|
||||||
|
|
||||||
err = netconn_connect(sock->conn, &remote_addr, ntohs(remote_port));
|
err = netconn_connect(sock->conn, &remote_addr, ntohs(remote_port));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) failed, err=%d\n", s, err));
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) failed, err=%d\n", s, err));
|
||||||
@ -359,37 +358,36 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
|
|||||||
|
|
||||||
/* Check if there is data left from the last recv operation. */
|
/* Check if there is data left from the last recv operation. */
|
||||||
if (sock->lastdata) {
|
if (sock->lastdata) {
|
||||||
buf = sock->lastdata;
|
buf = sock->lastdata;
|
||||||
} else {
|
} else {
|
||||||
/* If this is non-blocking call, then check first */
|
/* If this is non-blocking call, then check first */
|
||||||
if (((flags & MSG_DONTWAIT) || (sock->flags & O_NONBLOCK)) && !sock->rcvevent)
|
if (((flags & MSG_DONTWAIT) || (sock->flags & O_NONBLOCK)) && !sock->rcvevent) {
|
||||||
{
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): returning EWOULDBLOCK\n", s));
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): returning EWOULDBLOCK\n", s));
|
sock_set_errno(sock, EWOULDBLOCK);
|
||||||
sock_set_errno(sock, EWOULDBLOCK);
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* No data was left from the previous operation, so we try to get
|
/* No data was left from the previous operation, so we try to get
|
||||||
some from the network. */
|
some from the network. */
|
||||||
buf = netconn_recv(sock->conn);
|
buf = netconn_recv(sock->conn);
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
/* We should really do some error checking here. */
|
/* We should really do some error checking here. */
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): buf == NULL!\n", s));
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): buf == NULL!\n", s));
|
||||||
sock_set_errno(sock, (sock->conn->type==NETCONN_UDP)?ETIMEDOUT:0);
|
sock_set_errno(sock, (sock->conn->type==NETCONN_UDP)?ETIMEDOUT:0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buflen = netbuf_len(buf);
|
buflen = netbuf_len(buf);
|
||||||
|
|
||||||
buflen -= sock->lastoffset;
|
buflen -= sock->lastoffset;
|
||||||
|
|
||||||
if (len > buflen) {
|
if (len > buflen) {
|
||||||
copylen = buflen;
|
copylen = buflen;
|
||||||
} else {
|
} else {
|
||||||
copylen = len;
|
copylen = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy the contents of the received buffer into
|
/* copy the contents of the received buffer into
|
||||||
the supplied memory pointer mem */
|
the supplied memory pointer mem */
|
||||||
@ -440,7 +438,6 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
|
|||||||
netbuf_delete(buf);
|
netbuf_delete(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sock_set_errno(sock, 0);
|
sock_set_errno(sock, 0);
|
||||||
return copylen;
|
return copylen;
|
||||||
}
|
}
|
||||||
@ -545,7 +542,7 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
|
|||||||
if (connected)
|
if (connected)
|
||||||
netconn_connect(sock->conn, &addr, port);
|
netconn_connect(sock->conn, &addr, port);
|
||||||
else
|
else
|
||||||
netconn_disconnect(sock->conn);
|
netconn_disconnect(sock->conn);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,8 +582,8 @@ lwip_socket(int domain, int type, int protocol)
|
|||||||
|
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
netconn_delete(conn);
|
netconn_delete(conn);
|
||||||
set_errno(ENOBUFS);
|
set_errno(ENOBUFS);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
conn->socket = i;
|
conn->socket = i;
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("%d\n", i));
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("%d\n", i));
|
||||||
@ -998,7 +995,7 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
|||||||
if( *optlen < sizeof(int) ) {
|
if( *optlen < sizeof(int) ) {
|
||||||
err = EINVAL;
|
err = EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
||||||
@ -1030,7 +1027,7 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
|||||||
if( *optlen < sizeof(int) ) {
|
if( *optlen < sizeof(int) ) {
|
||||||
err = EINVAL;
|
err = EINVAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this is no TCP socket, ignore any options. */
|
/* If this is no TCP socket, ignore any options. */
|
||||||
if ( sock->conn->type != NETCONN_TCP ) return 0;
|
if ( sock->conn->type != NETCONN_TCP ) return 0;
|
||||||
@ -1062,7 +1059,6 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
|||||||
sock_set_errno(sock, err);
|
sock_set_errno(sock, err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Now do the actual option processing */
|
/* Now do the actual option processing */
|
||||||
@ -1234,7 +1230,7 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
|||||||
if( optlen < sizeof(int) ) {
|
if( optlen < sizeof(int) ) {
|
||||||
err = EINVAL;
|
err = EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#if LWIP_IGMP
|
#if LWIP_IGMP
|
||||||
case IP_MULTICAST_TTL:
|
case IP_MULTICAST_TTL:
|
||||||
{
|
{
|
||||||
@ -1245,15 +1241,15 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
|||||||
}
|
}
|
||||||
case IP_ADD_MEMBERSHIP:
|
case IP_ADD_MEMBERSHIP:
|
||||||
case IP_DROP_MEMBERSHIP:
|
case IP_DROP_MEMBERSHIP:
|
||||||
{ if( optlen < sizeof(struct ip_mreq) )
|
{ if( optlen < sizeof(struct ip_mreq) ) {
|
||||||
{ err = EINVAL;
|
err = EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* LWIP_IGMP */
|
#endif /* LWIP_IGMP */
|
||||||
default:
|
default:
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
||||||
err = ENOPROTOOPT;
|
err = ENOPROTOOPT;
|
||||||
} /* switch */
|
} /* switch */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1261,7 +1257,7 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
|||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
if( optlen < sizeof(int) ) {
|
if( optlen < sizeof(int) ) {
|
||||||
err = EINVAL;
|
err = EINVAL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this is no TCP socket, ignore any options. */
|
/* If this is no TCP socket, ignore any options. */
|
||||||
@ -1283,7 +1279,7 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
|||||||
} /* switch */
|
} /* switch */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* UNDEFINED LEVEL */
|
/* UNDEFINED LEVEL */
|
||||||
default:
|
default:
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname));
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname));
|
||||||
err = ENOPROTOOPT;
|
err = ENOPROTOOPT;
|
||||||
@ -1296,7 +1292,6 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Now do the actual option processing */
|
/* Now do the actual option processing */
|
||||||
|
|
||||||
switch(level) {
|
switch(level) {
|
||||||
|
Loading…
Reference in New Issue
Block a user