Browse Source

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
bernard.xiong 15 years ago
parent
commit
48c747e0c8
3 changed files with 82 additions and 70 deletions
  1. 31 19
      net/apps/ftpd.c
  2. 39 40
      net/lwip/src/api/sockets.c
  3. 12 11
      net/lwip/src/arch/sys_arch.c

+ 31 - 19
net/apps/ftpd.c

@@ -1,8 +1,7 @@
-#include <rtthread.h>
-
 #include <string.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
+#include <rtthread.h>
 #include <dfs_posix.h>
 #include <dfs_posix.h>
 #include <lwip/sockets.h>
 #include <lwip/sockets.h>
 
 
@@ -107,7 +106,7 @@ int build_full_path(struct ftp_session* session, char* path, char* new_path, siz
 		strcpy(new_path, path);
 		strcpy(new_path, path);
 	else
 	else
 	{
 	{
-		rt_sprintf(new_path, "%s\\%s", session->currentdir, path);
+		rt_sprintf(new_path, "%s/%s", session->currentdir, path);
 	}
 	}
 
 
 	return 0;
 	return 0;
@@ -115,8 +114,8 @@ int build_full_path(struct ftp_session* session, char* path, char* new_path, siz
 
 
 void ftpd_thread_entry(void* parameter)
 void ftpd_thread_entry(void* parameter)
 {
 {
-	int sockfd;
 	int numbytes;
 	int numbytes;
+	int sockfd, maxfdp1;
 	struct sockaddr_in local;
 	struct sockaddr_in local;
 	fd_set readfds, tmpfds;
 	fd_set readfds, tmpfds;
 	struct ftp_session* session;
 	struct ftp_session* session;
@@ -143,8 +142,21 @@ void ftpd_thread_entry(void* parameter)
 	FD_SET(sockfd, &readfds);
 	FD_SET(sockfd, &readfds);
 	for(;;)
 	for(;;)
 	{
 	{
+	    /* get maximum fd */
+	    maxfdp1 = sockfd + 1;
+        session = session_list;
+	    while (session != RT_NULL)
+	    {
+	        if (maxfdp1 < session->sockfd + 1)
+                maxfdp1 = session->sockfd + 1;
+
+            FD_SET(session->sockfd, &readfds);
+            session = session->next;
+	    }
+
 		tmpfds=readfds;
 		tmpfds=readfds;
-		select(0, &tmpfds, 0, 0, 0);
+		if (select(maxfdp1, &tmpfds, 0, 0, 0) == 0) continue;
+
 		if(FD_ISSET(sockfd, &tmpfds))
 		if(FD_ISSET(sockfd, &tmpfds))
 		{
 		{
 			int com_socket;
 			int com_socket;
@@ -199,7 +211,7 @@ void ftpd_thread_entry(void* parameter)
 							closesocket(session->sockfd);
 							closesocket(session->sockfd);
 							ftp_close_session(session);
 							ftp_close_session(session);
 						}
 						}
-					}					
+					}
 				}
 				}
 
 
 				session = next;
 				session = next;
@@ -222,7 +234,7 @@ int do_list(char* directory, int sockfd)
 #endif
 #endif
 
 
 	dirp = opendir(directory);
 	dirp = opendir(directory);
-	if (dirp == NULL) 
+	if (dirp == NULL)
 	{
 	{
 		line_length = rt_sprintf(line_buffer, "500 Internal Error\r\n");
 		line_length = rt_sprintf(line_buffer, "500 Internal Error\r\n");
 		send(sockfd, line_buffer, line_length, 0);
 		send(sockfd, line_buffer, line_length, 0);
@@ -234,7 +246,7 @@ int do_list(char* directory, int sockfd)
 		entry = readdir(dirp);
 		entry = readdir(dirp);
 		if (entry == NULL) break;
 		if (entry == NULL) break;
 
 
-		rt_sprintf(line_buffer, "%s/%s", directory, entry->d_name);
+		rt_sprintf(line_buffer, "%s/%s", directory, entry->d_name);
 #ifdef _WIN32
 #ifdef _WIN32
 		if (_stat(line_buffer, &s) ==0)
 		if (_stat(line_buffer, &s) ==0)
 #else
 #else
@@ -258,24 +270,24 @@ int do_simple_list(char* directory, int sockfd)
 	DIR* dirp;
 	DIR* dirp;
 	struct dirent* entry;
 	struct dirent* entry;
 	char line_buffer[256], line_length;
 	char line_buffer[256], line_length;
-	
+
 	dirp = opendir(directory);
 	dirp = opendir(directory);
-	if (dirp == NULL) 
+	if (dirp == NULL)
 	{
 	{
 		line_length = rt_sprintf(line_buffer, "500 Internal Error\r\n");
 		line_length = rt_sprintf(line_buffer, "500 Internal Error\r\n");
 		send(sockfd, line_buffer, line_length, 0);
 		send(sockfd, line_buffer, line_length, 0);
 		return -1;
 		return -1;
 	}
 	}
-	
+
 	while (1)
 	while (1)
 	{
 	{
 		entry = readdir(dirp);
 		entry = readdir(dirp);
 		if (entry == NULL) break;
 		if (entry == NULL) break;
-		
+
 		line_length = rt_sprintf(line_buffer, "%s\r\n", entry->d_name);
 		line_length = rt_sprintf(line_buffer, "%s\r\n", entry->d_name);
 		send(sockfd, line_buffer, line_length, 0);
 		send(sockfd, line_buffer, line_length, 0);
 	}
 	}
-	
+
 	return 0;
 	return 0;
 }
 }
 
 
@@ -354,7 +366,7 @@ int ftp_process_request(struct ftp_session* session, char *buf)
 	else if(str_begin_with(buf, "PASS")==0)
 	else if(str_begin_with(buf, "PASS")==0)
 	{
 	{
 		rt_kprintf("%s sent password \"%s\"\n", inet_ntoa(session->remote.sin_addr), parameter_ptr);
 		rt_kprintf("%s sent password \"%s\"\n", inet_ntoa(session->remote.sin_addr), parameter_ptr);
-		if (strcmp(parameter_ptr, FTP_PASSWORD)==0 || 
+		if (strcmp(parameter_ptr, FTP_PASSWORD)==0 ||
 			session->is_anonymous == RT_TRUE)
 			session->is_anonymous == RT_TRUE)
 		{
 		{
 			// password correct
 			// password correct
@@ -566,7 +578,7 @@ err1:
 		int file_size;
 		int file_size;
 
 
 		build_full_path(session, parameter_ptr, filename, 256);
 		build_full_path(session, parameter_ptr, filename, 256);
-		
+
 		file_size = ftp_get_filesize(filename);
 		file_size = ftp_get_filesize(filename);
 		if( file_size == -1)
 		if( file_size == -1)
 		{
 		{
@@ -600,7 +612,7 @@ err1:
 	}
 	}
 	else if(str_begin_with(buf, "CDUP")==0)
 	else if(str_begin_with(buf, "CDUP")==0)
 	{
 	{
-		rt_sprintf(filename, "%s\\%s", session->currentdir, "..");
+		rt_sprintf(filename, "%s/%s", session->currentdir, "..");
 
 
 		rt_sprintf(sbuf, "250 Changed to directory \"%s\"\r\n", filename);
 		rt_sprintf(sbuf, "250 Changed to directory \"%s\"\r\n", filename);
 		send(session->sockfd, sbuf, strlen(sbuf), 0);
 		send(session->sockfd, sbuf, strlen(sbuf), 0);
@@ -738,13 +750,13 @@ void ftpd_start()
 {
 {
 	rt_thread_t tid;
 	rt_thread_t tid;
 
 
-	tid = rt_thread_create("ftp", 
+	tid = rt_thread_create("ftpd",
 		ftpd_thread_entry, RT_NULL,
 		ftpd_thread_entry, RT_NULL,
-		1024, 30, 5);
+		4096, 30, 5);
 	if (tid != RT_NULL) rt_thread_startup(tid);
 	if (tid != RT_NULL) rt_thread_startup(tid);
 }
 }
 
 
 #ifdef RT_USING_FINSH
 #ifdef RT_USING_FINSH
 #include <finsh.h>
 #include <finsh.h>
-FINSH_FUNCTION_EXPORT(ftpd_start, start ftp server);
+FINSH_FUNCTION_EXPORT(ftpd_start, start ftp server)
 #endif
 #endif

+ 39 - 40
net/lwip/src/api/sockets.c

@@ -494,7 +494,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
       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)) && 
+      if (((flags & MSG_DONTWAIT) || (sock->flags & O_NONBLOCK)) &&
           (sock->rcvevent <= 0)) {
           (sock->rcvevent <= 0)) {
         if (off > 0) {
         if (off > 0) {
           /* already received data, return that */
           /* 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) {
     if (netconn_type(sock->conn) == NETCONN_TCP) {
       LWIP_ASSERT("invalid copylen, len would underflow", len >= copylen);
       LWIP_ASSERT("invalid copylen, len would underflow", len >= copylen);
       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)) {
            ((flags & MSG_PEEK)!=0)) {
         done = 1;
         done = 1;
       }
       }
@@ -702,16 +702,16 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
 #if LWIP_TCPIP_CORE_LOCKING
 #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...) */
   /* Should only be consider like a sample or a simple way to experiment this option (no check of "to" field...) */
   { struct pbuf* p;
   { struct pbuf* p;
-  
+
     p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
     p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
     if (p == NULL) {
     if (p == NULL) {
       err = ERR_MEM;
       err = ERR_MEM;
     } else {
     } else {
       p->payload = (void*)data;
       p->payload = (void*)data;
       p->len = p->tot_len = short_size;
       p->len = p->tot_len = short_size;
-      
+
       remote_addr.addr = ((const struct sockaddr_in *)to)->sin_addr.s_addr;
       remote_addr.addr = ((const struct sockaddr_in *)to)->sin_addr.s_addr;
-      
+
       LOCK_TCPIP_CORE();
       LOCK_TCPIP_CORE();
       if (sock->conn->type==NETCONN_RAW) {
       if (sock->conn->type==NETCONN_RAW) {
         err = sock->conn->err = raw_sendto(sock->conn->pcb.raw, p, &remote_addr);
         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));
         err = sock->conn->err = udp_sendto(sock->conn->pcb.udp, p, &remote_addr, ntohs(((const struct sockaddr_in *)to)->sin_port));
       }
       }
       UNLOCK_TCPIP_CORE();
       UNLOCK_TCPIP_CORE();
-      
+
       pbuf_free(p);
       pbuf_free(p);
     }
     }
   }
   }
@@ -845,11 +845,11 @@ lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset)
   int i, nready = 0;
   int i, nready = 0;
   fd_set lreadset, lwriteset, lexceptset;
   fd_set lreadset, lwriteset, lexceptset;
   struct lwip_socket *p_sock;
   struct lwip_socket *p_sock;
-  
+
   FD_ZERO(&lreadset);
   FD_ZERO(&lreadset);
   FD_ZERO(&lwriteset);
   FD_ZERO(&lwriteset);
   FD_ZERO(&lexceptset);
   FD_ZERO(&lexceptset);
-  
+
   /* Go through each socket in each list to count number of sockets which
   /* Go through each socket in each list to count number of sockets which
   currently match */
   currently match */
   for(i = 0; i < maxfdp1; i++) {
   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;
   *readset = lreadset;
   *writeset = lwriteset;
   *writeset = lwriteset;
   FD_ZERO(exceptset);
   FD_ZERO(exceptset);
-  
+
   return nready;
   return nready;
 }
 }
 
 
@@ -935,27 +935,27 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
         FD_ZERO(writeset);
         FD_ZERO(writeset);
       if (exceptset)
       if (exceptset)
         FD_ZERO(exceptset);
         FD_ZERO(exceptset);
-  
+
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: no timeout, returning 0\n"));
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: no timeout, returning 0\n"));
       set_errno(0);
       set_errno(0);
-  
+
       return 0;
       return 0;
     }
     }
-    
+
     /* add our semaphore to list */
     /* add our semaphore to list */
     /* We don't actually need any dynamic memory. Our entry on the
     /* 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
      * list is only valid while we are in this function, so it's ok
      * to use local variables */
      * to use local variables */
-    
+
     select_cb.sem = sys_sem_new(0);
     select_cb.sem = sys_sem_new(0);
     /* Note that we are still protected */
     /* Note that we are still protected */
     /* Put this select_cb on top of list */
     /* Put this select_cb on top of list */
     select_cb.next = select_cb_list;
     select_cb.next = select_cb_list;
     select_cb_list = &select_cb;
     select_cb_list = &select_cb;
-    
+
     /* Now we can safely unprotect */
     /* Now we can safely unprotect */
     sys_sem_signal(selectsem);
     sys_sem_signal(selectsem);
-    
+
     /* Now just wait to be woken */
     /* Now just wait to be woken */
     if (timeout == 0)
     if (timeout == 0)
       /* Wait forever */
       /* Wait forever */
@@ -965,9 +965,8 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
       if(msectimeout == 0)
       if(msectimeout == 0)
         msectimeout = 1;
         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 */
 	  /* it's not a lwip thread, use os semaphore with timeout to handle it */
 	  i = sys_arch_sem_wait(select_cb.sem, msectimeout);
 	  i = sys_arch_sem_wait(select_cb.sem, msectimeout);
 	  if (i == SYS_ARCH_TIMEOUT) i = 0;
 	  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 */
 	  /* it's a lwip thread, use os semaphore with timeout to handle it */
       i = sys_sem_wait_timeout(select_cb.sem, msectimeout);
       i = sys_sem_wait_timeout(select_cb.sem, msectimeout);
     }
     }
-    
+
     /* Take us off the list */
     /* Take us off the list */
     sys_sem_wait(selectsem);
     sys_sem_wait(selectsem);
     if (select_cb_list == &select_cb)
     if (select_cb_list == &select_cb)
@@ -989,9 +988,9 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
           break;
           break;
         }
         }
       }
       }
-    
+
     sys_sem_signal(selectsem);
     sys_sem_signal(selectsem);
-    
+
     sys_sem_free(select_cb.sem);
     sys_sem_free(select_cb.sem);
     if (i == 0)  {
     if (i == 0)  {
       /* Timeout */
       /* Timeout */
@@ -1001,13 +1000,13 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
         FD_ZERO(writeset);
         FD_ZERO(writeset);
       if (exceptset)
       if (exceptset)
         FD_ZERO(exceptset);
         FD_ZERO(exceptset);
-  
+
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: timeout expired\n"));
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: timeout expired\n"));
       set_errno(0);
       set_errno(0);
-  
+
       return 0;
       return 0;
     }
     }
-    
+
     if (readset)
     if (readset)
       lreadset = *readset;
       lreadset = *readset;
     else
     else
@@ -1020,22 +1019,22 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
       lexceptset = *exceptset;
       lexceptset = *exceptset;
     else
     else
       FD_ZERO(&lexceptset);
       FD_ZERO(&lexceptset);
-    
+
     /* See what's set */
     /* See what's set */
     nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
     nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
   } else
   } else
     sys_sem_signal(selectsem);
     sys_sem_signal(selectsem);
-  
+
   if (readset)
   if (readset)
     *readset = lreadset;
     *readset = lreadset;
   if (writeset)
   if (writeset)
     *writeset = lwriteset;
     *writeset = lwriteset;
   if (exceptset)
   if (exceptset)
     *exceptset = lexceptset;
     *exceptset = lexceptset;
-  
+
   LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: nready=%d\n", nready));
   LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: nready=%d\n", nready));
   set_errno(0);
   set_errno(0);
-  
+
   return nready;
   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. */
   /* Do length and type checks for the various options first, to keep it readable. */
   switch (level) {
   switch (level) {
-   
+
 /* Level: SOL_SOCKET */
 /* Level: SOL_SOCKET */
   case SOL_SOCKET:
   case SOL_SOCKET:
     switch (optname) {
     switch (optname) {
-       
+
     case SO_ACCEPTCONN:
     case SO_ACCEPTCONN:
     case SO_BROADCAST:
     case SO_BROADCAST:
     /* UNIMPL case SO_DEBUG: */
     /* UNIMPL case SO_DEBUG: */
@@ -1259,7 +1258,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
       err = ENOPROTOOPT;
       err = ENOPROTOOPT;
     }  /* switch (optname) */
     }  /* switch (optname) */
     break;
     break;
-                     
+
 /* Level: IPPROTO_IP */
 /* Level: IPPROTO_IP */
   case IPPROTO_IP:
   case IPPROTO_IP:
     switch (optname) {
     switch (optname) {
@@ -1291,7 +1290,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
       err = ENOPROTOOPT;
       err = ENOPROTOOPT;
     }  /* switch (optname) */
     }  /* switch (optname) */
     break;
     break;
-         
+
 #if LWIP_TCP
 #if LWIP_TCP
 /* Level: IPPROTO_TCP */
 /* Level: IPPROTO_TCP */
   case IPPROTO_TCP:
   case IPPROTO_TCP:
@@ -1299,7 +1298,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
       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)
     if (sock->conn->type != NETCONN_TCP)
       return 0;
       return 0;
@@ -1313,7 +1312,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
     case TCP_KEEPCNT:
     case TCP_KEEPCNT:
 #endif /* LWIP_TCP_KEEPALIVE */
 #endif /* LWIP_TCP_KEEPALIVE */
       break;
       break;
-       
+
     default:
     default:
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n",
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n",
                                   s, optname));
                                   s, optname));
@@ -1328,7 +1327,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
       err = EINVAL;
       err = EINVAL;
       break;
       break;
     }
     }
-    
+
     /* If this is no UDP lite socket, ignore any options. */
     /* If this is no UDP lite socket, ignore any options. */
     if (sock->conn->type != NETCONN_UDPLITE)
     if (sock->conn->type != NETCONN_UDPLITE)
       return 0;
       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_SEND_CSCOV:
     case UDPLITE_RECV_CSCOV:
     case UDPLITE_RECV_CSCOV:
       break;
       break;
-       
+
     default:
     default:
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UNIMPL: optname=0x%x, ..)\n",
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UNIMPL: optname=0x%x, ..)\n",
                                   s, optname));
                                   s, optname));
@@ -1352,7 +1351,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
       err = ENOPROTOOPT;
       err = ENOPROTOOPT;
   }  /* switch */
   }  /* switch */
 
 
-   
+
   if (err != ERR_OK) {
   if (err != ERR_OK) {
     sock_set_errno(sock, err);
     sock_set_errno(sock, err);
     return -1;
     return -1;
@@ -1397,7 +1396,7 @@ lwip_getsockopt_internal(void *arg)
   optval = data->optval;
   optval = data->optval;
 
 
   switch (level) {
   switch (level) {
-   
+
 /* Level: SOL_SOCKET */
 /* Level: SOL_SOCKET */
   case SOL_SOCKET:
   case SOL_SOCKET:
     switch (optname) {
     switch (optname) {
@@ -1443,7 +1442,7 @@ lwip_getsockopt_internal(void *arg)
     case SO_ERROR:
     case SO_ERROR:
       if (sock->err == 0) {
       if (sock->err == 0) {
         sock_set_errno(sock, err_to_errno(sock->conn->err));
         sock_set_errno(sock, err_to_errno(sock->conn->err));
-      } 
+      }
       *(int *)optval = sock->err;
       *(int *)optval = sock->err;
       sock->err = 0;
       sock->err = 0;
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n",
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n",

+ 12 - 11
net/lwip/src/arch/sys_arch.c

@@ -34,7 +34,7 @@ sys_sem_t sys_sem_new(u8_t count)
 #if SYS_DEBUG
 #if SYS_DEBUG
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
-	
+
 		thread = rt_thread_self();
 		thread = rt_thread_self();
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Create sem: %s \n",thread->name, tname));
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Create sem: %s \n",thread->name, tname));
 	}
 	}
@@ -51,7 +51,7 @@ void sys_sem_free(sys_sem_t sem)
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
 		thread = rt_thread_self();
 		thread = rt_thread_self();
-	
+
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete sem: %s \n",thread->name,
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete sem: %s \n",thread->name,
 			sem->parent.parent.name));
 			sem->parent.parent.name));
 	}
 	}
@@ -68,7 +68,7 @@ void sys_sem_signal(sys_sem_t sem)
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
 		thread = rt_thread_self();
 		thread = rt_thread_self();
-	
+
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Release signal: %s , %d\n",thread->name,
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Release signal: %s , %d\n",thread->name,
 			sem->parent.parent.name, sem->value));
 			sem->parent.parent.name, sem->value));
 	}
 	}
@@ -91,7 +91,7 @@ u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout)
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
 		thread = rt_thread_self();
 		thread = rt_thread_self();
-	
+
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Wait sem: %s , %d\n",thread->name,
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Wait sem: %s , %d\n",thread->name,
 			sem->parent.parent.name, sem->value));
 			sem->parent.parent.name, sem->value));
 	}
 	}
@@ -132,7 +132,7 @@ sys_mbox_t sys_mbox_new(int size)
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
 		thread = rt_thread_self();
 		thread = rt_thread_self();
-	
+
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Create mbox: %s \n",thread->name, tname));
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Create mbox: %s \n",thread->name, tname));
 	}
 	}
 #endif
 #endif
@@ -148,7 +148,7 @@ void sys_mbox_free(sys_mbox_t mbox)
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
 		thread = rt_thread_self();
 		thread = rt_thread_self();
-	
+
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete mbox: %s\n",thread->name,
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Delete mbox: %s\n",thread->name,
 			mbox->parent.parent.name));
 			mbox->parent.parent.name));
 	}
 	}
@@ -165,7 +165,7 @@ void sys_mbox_post(sys_mbox_t mbox, void *msg)
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
 		thread = rt_thread_self();
 		thread = rt_thread_self();
-	
+
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Post mail: %s ,0x%x\n",thread->name,
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Post mail: %s ,0x%x\n",thread->name,
 			mbox->parent.parent.name, (rt_uint32_t)msg));
 			mbox->parent.parent.name, (rt_uint32_t)msg));
 	}
 	}
@@ -182,7 +182,7 @@ err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg)
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
 		thread = rt_thread_self();
 		thread = rt_thread_self();
-	
+
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Post mail: %s ,0x%x\n",thread->name,
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Post mail: %s ,0x%x\n",thread->name,
 			mbox->parent.parent.name, (rt_uint32_t)msg));
 			mbox->parent.parent.name, (rt_uint32_t)msg));
 	}
 	}
@@ -220,7 +220,7 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
 		thread = rt_thread_self();
 		thread = rt_thread_self();
-	
+
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n",thread->name,
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n",thread->name,
 			mbox->parent.parent.name, *(rt_uint32_t **)msg));
 			mbox->parent.parent.name, *(rt_uint32_t **)msg));
 	}
 	}
@@ -249,7 +249,7 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg)
 	{
 	{
 		struct rt_thread *thread;
 		struct rt_thread *thread;
 		thread = rt_thread_self();
 		thread = rt_thread_self();
-	
+
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n",thread->name,
 		LWIP_DEBUGF(SYS_DEBUG, ("%s, Fetch mail: %s , 0x%x\n",thread->name,
 			mbox->parent.parent.name, *(rt_uint32_t **)msg));
 			mbox->parent.parent.name, *(rt_uint32_t **)msg));
 	}
 	}
@@ -314,6 +314,7 @@ void sys_arch_unprotect(sys_prot_t pval)
 
 
 void sys_arch_assert(const char* file, int line)
 void sys_arch_assert(const char* file, int line)
 {
 {
-	rt_kprintf("Assertion: %d in %s\n", line, file);
+	rt_kprintf("\nAssertion: %d in %s, thread %s\n", line, file,
+        rt_thread_self()->name);
 	RT_ASSERT(0);
 	RT_ASSERT(0);
 }
 }