[examples] update:
1. cleanup for posix dfs_net.
2. fixed recv buf overwrite.
3. format code.
#include <rtthread.h>
#include <sys/socket.h>
-#include <sys/select.h>
+
+#ifdef RT_USING_DFS_NET
+#include <sys/select.h> // only dfs_net
#include <dfs_posix.h>
+#else
+#define read lwip_read
+#define write lwip_write
+#endif /* RT_USING_DFS_NET */
+
#include "netdb.h"
#define MAX_SERV 32 /* Maximum number of chargen services. Don't need too many */
@@ -113,6 +120,7 @@ static void chargen_thread(void *arg)
closesocket(sock);
}
}
+
/* Go through list of connected clients and process data */
for (p_charcb = charcb_list; p_charcb; p_charcb = p_charcb->next)
{
@@ -124,6 +132,7 @@ static void chargen_thread(void *arg)
if (do_read(p_charcb) < 0)
break;
}
+
if (FD_ISSET(p_charcb->socket, &writeset))
{
char line[80];
@@ -135,6 +144,7 @@ static void chargen_thread(void *arg)
if (++setchar == 0x7f)
setchar = 0x21;
}
+
line[i] = 0;
strcat(line, "\n\r");
if (write(p_charcb->socket, line, strlen(line)) < 0)
@@ -142,6 +152,7 @@ static void chargen_thread(void *arg)
close_chargen(p_charcb);
break;
}
+
if (++p_charcb->nextchar == 0x7f)
p_charcb->nextchar = 0x21;
}
