Skip to content

Commit dd12ccc

Browse files
author
Antigravity Agent
committed
Fix Mono debugger 200ms pause (Issue #122344)
- Move TCP_NODELAY to start of transport_handshake to ensure immediate handshake transmission. - Enable TCP_QUICKACK in socket_transport_send to prevent delayed ACKs during event transmission.
1 parent 421445e commit dd12ccc

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

src/mono/mono/component/debugger-agent.c

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,21 @@ socket_transport_send (void *data, int len)
10001000
MONO_REQ_GC_SAFE_MODE;
10011001

10021002
do {
1003-
res = send (conn_fd, (const char*)data, len, 0);
1004-
} while (res == SOCKET_ERROR && get_last_sock_error () == MONO_EINTR);
1003+
res = send (conn_fd, (char*)data, len, 0);
1004+
} while (res == -1 && get_last_sock_error () == MONO_EINTR);
1005+
1006+
#if defined(linux) || defined(__linux__)
1007+
if (res != -1) {
1008+
#ifdef TCP_QUICKACK
1009+
{
1010+
int flag = 1;
1011+
if (setsockopt (conn_fd, IPPROTO_TCP, TCP_QUICKACK, (char *) &flag, sizeof (int)) == -1) {
1012+
/* Fail silently */
1013+
}
1014+
}
1015+
#endif
1016+
}
1017+
#endif
10051018

10061019
if (res != len)
10071020
return FALSE;
@@ -1411,6 +1424,29 @@ transport_handshake (void)
14111424

14121425
MONO_REQ_GC_UNSAFE_MODE;
14131426

1427+
#ifndef DISABLE_SOCKET_TRANSPORT
1428+
#ifndef HOST_WASI
1429+
// FIXME: Move this somewhere else
1430+
/*
1431+
* Set TCP_NODELAY on the socket so the client receives events/command
1432+
* results immediately.
1433+
*/
1434+
MONO_ENTER_GC_SAFE;
1435+
if (conn_fd) {
1436+
int flag = 1;
1437+
int result = setsockopt (conn_fd,
1438+
IPPROTO_TCP,
1439+
TCP_NODELAY,
1440+
(char *) &flag,
1441+
sizeof(int));
1442+
if (result < 0) {
1443+
PRINT_ERROR_MSG ("debugger-agent: Unable to set TCP_NODELAY: %s\n", strerror (errno));
1444+
}
1445+
}
1446+
MONO_EXIT_GC_SAFE;
1447+
#endif // !HOST_WASI
1448+
#endif // DISABLE_SOCKET_TRANSPORT
1449+
14141450
disconnected = TRUE;
14151451

14161452
/* Write handshake message */
@@ -1438,24 +1474,6 @@ transport_handshake (void)
14381474
using_icordbg = FALSE;
14391475
protocol_version_set = FALSE;
14401476

1441-
#ifndef DISABLE_SOCKET_TRANSPORT
1442-
#ifndef HOST_WASI
1443-
// FIXME: Move this somewhere else
1444-
/*
1445-
* Set TCP_NODELAY on the socket so the client receives events/command
1446-
* results immediately.
1447-
*/
1448-
MONO_ENTER_GC_SAFE;
1449-
if (conn_fd) {
1450-
int flag = 1;
1451-
int result = setsockopt (conn_fd,
1452-
IPPROTO_TCP,
1453-
TCP_NODELAY,
1454-
(char *) &flag,
1455-
sizeof(int));
1456-
g_assert (result >= 0);
1457-
}
1458-
14591477
set_keepalive ();
14601478
MONO_EXIT_GC_SAFE;
14611479
#endif // !HOST_WASI

0 commit comments

Comments
 (0)