diff options
| author | bernard.xiong <[email protected]> | 2009-11-03 23:59:30 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2009-11-03 23:59:30 +0000 |
| commit | 48c747e0c8f1a09ddadaca06f4c95c7c652b08ea (patch) | |
| tree | 75b716b7aa7dd86df4b17e4ced2fb29113de98fa /net/lwip/src/api | |
| parent | fee61e2c2a01a72ccf58fb9c04365c5920a5aa58 (diff) | |
fix select issue in ftpd and lwip_select. cleanup assert information output in lwip.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@148 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'net/lwip/src/api')
| -rw-r--r-- | net/lwip/src/api/sockets.c | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/net/lwip/src/api/sockets.c b/net/lwip/src/api/sockets.c index efa54f494b..c02e56ef16 100644 --- a/net/lwip/src/api/sockets.c +++ b/net/lwip/src/api/sockets.c @@ -494,7 +494,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags, buf = sock->lastdata; } else { /* If this is non-blocking call, then check first */ - if (((flags & MSG_DONTWAIT) || (sock->flags & O_NONBLOCK)) && + if (((flags & MSG_DONTWAIT) || (sock->flags & O_NONBLOCK)) && (sock->rcvevent <= 0)) { if (off > 0) { /* already received data, return that */ @@ -546,9 +546,9 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags, if (netconn_type(sock->conn) == NETCONN_TCP) { LWIP_ASSERT("invalid copylen, len would underflow", len >= copylen); len -= copylen; - if ( (len <= 0) || - (buf->p->flags & PBUF_FLAG_PUSH) || - (sock->rcvevent <= 0) || + if ( (len <= 0) || + (buf->p->flags & PBUF_FLAG_PUSH) || + (sock->rcvevent <= 0) || ((flags & MSG_PEEK)!=0)) { done = 1; } @@ -702,16 +702,16 @@ lwip_sendto(int s, const void *data, size_t size, int flags, #if LWIP_TCPIP_CORE_LOCKING /* Should only be consider like a sample or a simple way to experiment this option (no check of "to" field...) */ { struct pbuf* p; - + p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF); if (p == NULL) { err = ERR_MEM; } else { p->payload = (void*)data; p->len = p->tot_len = short_size; - + remote_addr.addr = ((const struct sockaddr_in *)to)->sin_addr.s_addr; - + LOCK_TCPIP_CORE(); if (sock->conn->type==NETCONN_RAW) { err = sock->conn->err = raw_sendto(sock->conn->pcb.raw, p, &remote_addr); @@ -719,7 +719,7 @@ lwip_sendto(int s, const void *data, size_t size, int flags, err = sock->conn->err = udp_sendto(sock->conn->pcb.udp, p, &remote_addr, ntohs(((const struct sockaddr_in *)to)->sin_port)); } UNLOCK_TCPIP_CORE(); - + pbuf_free(p); } } @@ -845,11 +845,11 @@ lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset) int i, nready = 0; fd_set lreadset, lwriteset, lexceptset; struct lwip_socket *p_sock; - + FD_ZERO(&lreadset); FD_ZERO(&lwriteset); FD_ZERO(&lexceptset); - + /* Go through each socket in each list to count number of sockets which currently match */ for(i = 0; i < maxfdp1; i++) { @@ -875,7 +875,7 @@ lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset) *readset = lreadset; *writeset = lwriteset; FD_ZERO(exceptset); - + return nready; } @@ -935,27 +935,27 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, FD_ZERO(writeset); if (exceptset) FD_ZERO(exceptset); - + LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: no timeout, returning 0\n")); set_errno(0); - + return 0; } - + /* add our semaphore to list */ /* We don't actually need any dynamic memory. Our entry on the * list is only valid while we are in this function, so it's ok * to use local variables */ - + select_cb.sem = sys_sem_new(0); /* Note that we are still protected */ /* Put this select_cb on top of list */ select_cb.next = select_cb_list; select_cb_list = &select_cb; - + /* Now we can safely unprotect */ sys_sem_signal(selectsem); - + /* Now just wait to be woken */ if (timeout == 0) /* Wait forever */ @@ -965,9 +965,8 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, if(msectimeout == 0) msectimeout = 1; } - - if (msectimeout > 0 && sys_arch_timeouts() == NULL){ + if (sys_arch_timeouts() == NULL){ /* it's not a lwip thread, use os semaphore with timeout to handle it */ i = sys_arch_sem_wait(select_cb.sem, msectimeout); if (i == SYS_ARCH_TIMEOUT) i = 0; @@ -977,7 +976,7 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, /* it's a lwip thread, use os semaphore with timeout to handle it */ i = sys_sem_wait_timeout(select_cb.sem, msectimeout); } - + /* Take us off the list */ sys_sem_wait(selectsem); if (select_cb_list == &select_cb) @@ -989,9 +988,9 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, break; } } - + sys_sem_signal(selectsem); - + sys_sem_free(select_cb.sem); if (i == 0) { /* Timeout */ @@ -1001,13 +1000,13 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, FD_ZERO(writeset); if (exceptset) FD_ZERO(exceptset); - + LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: timeout expired\n")); set_errno(0); - + return 0; } - + if (readset) lreadset = *readset; else @@ -1020,22 +1019,22 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, lexceptset = *exceptset; else FD_ZERO(&lexceptset); - + /* See what's set */ nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset); } else sys_sem_signal(selectsem); - + if (readset) *readset = lreadset; if (writeset) *writeset = lwriteset; if (exceptset) *exceptset = lexceptset; - + LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: nready=%d\n", nready)); set_errno(0); - + return nready; } @@ -1206,11 +1205,11 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) /* Do length and type checks for the various options first, to keep it readable. */ switch (level) { - + /* Level: SOL_SOCKET */ case SOL_SOCKET: switch (optname) { - + case SO_ACCEPTCONN: case SO_BROADCAST: /* UNIMPL case SO_DEBUG: */ @@ -1259,7 +1258,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) err = ENOPROTOOPT; } /* switch (optname) */ break; - + /* Level: IPPROTO_IP */ case IPPROTO_IP: switch (optname) { @@ -1291,7 +1290,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) err = ENOPROTOOPT; } /* switch (optname) */ break; - + #if LWIP_TCP /* Level: IPPROTO_TCP */ case IPPROTO_TCP: @@ -1299,7 +1298,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) err = EINVAL; break; } - + /* If this is no TCP socket, ignore any options. */ if (sock->conn->type != NETCONN_TCP) return 0; @@ -1313,7 +1312,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) case TCP_KEEPCNT: #endif /* LWIP_TCP_KEEPALIVE */ break; - + default: LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n", s, optname)); @@ -1328,7 +1327,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) err = EINVAL; break; } - + /* If this is no UDP lite socket, ignore any options. */ if (sock->conn->type != NETCONN_UDPLITE) return 0; @@ -1337,7 +1336,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) case UDPLITE_SEND_CSCOV: case UDPLITE_RECV_CSCOV: break; - + default: LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UNIMPL: optname=0x%x, ..)\n", s, optname)); @@ -1352,7 +1351,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) err = ENOPROTOOPT; } /* switch */ - + if (err != ERR_OK) { sock_set_errno(sock, err); return -1; @@ -1397,7 +1396,7 @@ lwip_getsockopt_internal(void *arg) optval = data->optval; switch (level) { - + /* Level: SOL_SOCKET */ case SOL_SOCKET: switch (optname) { @@ -1443,7 +1442,7 @@ lwip_getsockopt_internal(void *arg) case SO_ERROR: if (sock->err == 0) { sock_set_errno(sock, err_to_errno(sock->conn->err)); - } + } *(int *)optval = sock->err; sock->err = 0; LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n", |
