Skip to content

Commit 112fac5

Browse files
authored
Fixes and improvements in native socket (#3289)
***NO_CI***
1 parent be1bb6f commit 112fac5

25 files changed

Lines changed: 43 additions & 6 deletions

src/DeviceInterfaces/System.Net/sys_net_native.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
254254
NULL,
255255
NULL,
256256
NULL,
257+
NULL,
257258
Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate::ParseCertificate___STATIC__VOID__SZARRAY_U1__BYREF_STRING__BYREF_STRING__BYREF_SystemDateTime__BYREF_SystemDateTime,
258259
NULL,
259260
NULL,
@@ -345,9 +346,9 @@ static const CLR_RT_MethodHandler method_lookup[] =
345346
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Net =
346347
{
347348
"System.Net",
348-
0xD82C1452,
349+
0x6DFA71D6,
349350
method_lookup,
350-
{ 100, 2, 0, 11 }
351+
{ 100, 2, 0, 12 }
351352
};
352353

353354
// clang-format on

src/DeviceInterfaces/System.Net/sys_net_native.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,7 @@ struct Library_sys_net_native_System_Net_Sockets_Socket
333333
static const int FIELD__m_recvTimeout = 4;
334334
static const int FIELD__m_sendTimeout = 5;
335335
static const int FIELD___socketType = 6;
336-
static const int FIELD___nonBlockingConnectInProgress = 7;
337-
static const int FIELD___nonBlockingConnectRightEndPoint = 8;
338-
static const int FIELD___rightEndPoint = 9;
336+
static const int FIELD___rightEndPoint = 7;
339337

340338
//--//
341339
};

src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Sockets_NativeSocket.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,11 @@ HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::SendRecvHelper(
864864
break;
865865
}
866866

867+
// yield to the CLR scheduler to prevent a tight loop when select reports ready
868+
// but the actual send/recv returns EWOULDBLOCK (race with lwIP stack)
869+
NANOCLR_CHECK_HRESULT(
870+
g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Socket, fRes));
871+
867872
continue;
868873
}
869874
// zero recv bytes indicates the handle has been closed.

src/PAL/Lwip/lwIP_Sockets.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ int LWIP_SOCKETS_Driver::GetNativeError(int error)
18201820
break;
18211821

18221822
case ENOTCONN:
1823-
ret = SOCK_EISCONN;
1823+
ret = SOCK_ENOTCONN;
18241824
break;
18251825

18261826
#if !defined(__GNUC__) // same as ENOTSOCK for GCC

targets/ChibiOS/_include/lwipopts.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@
485485
#define TCP_MSS 1480
486486
#endif
487487

488+
/**
489+
* TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments.
490+
*/
491+
#ifndef TCP_SYNMAXRTX
492+
#define TCP_SYNMAXRTX 4
493+
#endif
494+
488495
/**
489496
* TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb.
490497
*/

targets/ESP32/_IDF/sdkconfig.default

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ CONFIG_LWIP_DHCPS=n
5555
CONFIG_LWIP_IPV6=n
5656
CONFIG_LWIP_MAX_LISTENING_TCP=8
5757
CONFIG_LWIP_SNTP_MAX_SERVERS=2
58+
CONFIG_LWIP_TCP_SYNMAXRTX=4
5859

5960
CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
6061
CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH=y

targets/ESP32/_IDF/sdkconfig.default.esp32c3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ CONFIG_LWIP_DHCPS=n
4242
CONFIG_LWIP_IPV6=n
4343
CONFIG_LWIP_MAX_LISTENING_TCP=4
4444
CONFIG_LWIP_SNTP_MAX_SERVERS=2
45+
CONFIG_LWIP_TCP_SYNMAXRTX=4
4546

4647
CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
4748
CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH=y

targets/ESP32/_IDF/sdkconfig.default.esp32c5

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ CONFIG_LWIP_DHCP_OPTIONS_LEN=80
5555
CONFIG_LWIP_DHCPS=n
5656
CONFIG_LWIP_MAX_LISTENING_TCP=8
5757
CONFIG_LWIP_SNTP_MAX_SERVERS=2
58+
CONFIG_LWIP_TCP_SYNMAXRTX=4
5859

5960
CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
6061
CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH=y

targets/ESP32/_IDF/sdkconfig.default.esp32c6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ CONFIG_LWIP_DHCP_OPTIONS_LEN=80
5050
CONFIG_LWIP_DHCPS=n
5151
CONFIG_LWIP_MAX_LISTENING_TCP=8
5252
CONFIG_LWIP_SNTP_MAX_SERVERS=2
53+
CONFIG_LWIP_TCP_SYNMAXRTX=4
5354

5455
CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
5556
CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH=y

targets/ESP32/_IDF/sdkconfig.default.esp32h2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ CONFIG_LWIP_MAX_SOCKETS=16
115115
CONFIG_LWIP_SO_LINGER=y
116116
CONFIG_LWIP_SO_RCVBUF=y
117117
CONFIG_LWIP_DHCP_OPTIONS_LEN=80
118+
CONFIG_LWIP_TCP_SYNMAXRTX=4
118119

119120
CONFIG_LITTLEFS_MAX_PARTITIONS=1
120121
CONFIG_LITTLEFS_OBJ_NAME_LEN=256

0 commit comments

Comments
 (0)