Skip to content

Commit 4b91533

Browse files
authored
Merge pull request #2 from mysterywolf/winsock
[sal] improve debug code
2 parents 442828a + 381eca5 commit 4b91533

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

components/net/sal/impl/af_inet_winsock.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
*/
1010

1111
/* Do NOT include sys/time.h in this file */
12-
#include <WinSock2.h>
12+
/* Do NOT include WinSock2.h or winsock.h in this file */
1313
#include <rtthread.h>
1414
#include <sal_low_lvl.h>
1515
#include <sal_socket.h>
1616
#include <sal_netdb.h>
1717

18+
#define DBG_TAG "sal.winsock"
19+
#define DBG_LVL DBG_INFO
20+
#include <rtdbg.h>
21+
1822
/* Important, must reserve */
1923
#pragma comment( lib, "ws2_32.lib" )
2024

@@ -43,7 +47,7 @@
4347
iResult = WSAStartup(MAKEWORD(2, 2), &wsa_data); \
4448
if (iResult != 0) \
4549
{ \
46-
rt_kprintf("WSAStartup failed: %d\n", iResult); \
50+
LOG_E("WSAStartup failed: %d\n", iResult); \
4751
return -RT_ERROR; \
4852
} \
4953
}while(0)
@@ -79,7 +83,7 @@ int win_connect(int s, const struct sockaddr *name, socklen_t namelen)
7983
* result = connect(s, name, namelen);
8084
* if (result == -1)
8185
* {
82-
* rt_kprintf("error :%d\n", WSAGetLastError());
86+
* LOG_E("error :%d\n", WSAGetLastError());
8387
* return WSAGetLastError();
8488
* }
8589
* else
@@ -239,7 +243,7 @@ static int win_getaddrinfo(const char* nodename, const char* servname, const str
239243
{
240244
return EAI_MEMORY;
241245
}
242-
memset(ai, 0, total_size);
246+
rt_memset(ai, 0, total_size);
243247
/* cast through void* to get rid of alignment warnings */
244248
sa = (struct sockaddr_storage*)(void*)((uint8_t*)ai + sizeof(struct addrinfo));
245249
struct sockaddr_in* sa4 = (struct sockaddr_in*)sa;
@@ -261,7 +265,7 @@ static int win_getaddrinfo(const char* nodename, const char* servname, const str
261265
{
262266
/* copy nodename to canonname if specified */
263267
ai->ai_canonname = ((char*)ai + sizeof(struct addrinfo) + sizeof(struct sockaddr_storage));
264-
memcpy(ai->ai_canonname, nodename, namelen);
268+
rt_memcpy(ai->ai_canonname, nodename, namelen);
265269
ai->ai_canonname[namelen] = 0;
266270
}
267271
ai->ai_addrlen = sizeof(struct sockaddr_storage);
@@ -358,9 +362,8 @@ static const struct sal_proto_family windows_inet_family =
358362
&windows_netdb_ops,
359363
};
360364

361-
#include <stdint.h>
362-
#include <netdev_ipaddr.h>
363365
#include <netdev.h>
366+
#include <netdev_ipaddr.h>
364367
/* Set lwIP network interface device protocol family information */
365368
int sal_win_netdev_set_pf_info(struct netdev* netdev)
366369
{
@@ -369,4 +372,3 @@ int sal_win_netdev_set_pf_info(struct netdev* netdev)
369372
netdev->sal_user_data = (void*)&windows_inet_family;
370373
return 0;
371374
}
372-

0 commit comments

Comments
 (0)