Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Windows debugger socket setup #10212

Merged
merged 4 commits into from
Feb 23, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 21 additions & 34 deletions runtime/debugger.c
Expand Up @@ -66,7 +66,7 @@ CAMLexport void caml_debugger_cleanup_fork(void)
#include <netdb.h>
#else
#define ATOM ATOM_WS
#include <winsock.h>
#include <winsock2.h>
#undef ATOM
#include <process.h>
#endif
Expand Down Expand Up @@ -103,42 +103,29 @@ static struct skiplist event_points_table = SKIPLIST_STATIC_INITIALIZER;
static void open_connection(void)
{
#ifdef _WIN32
/* Set socket to synchronous mode so that file descriptor-oriented
functions (read()/write() etc.) can be used */

int oldvalue, oldvaluelen, newvalue, retcode;
oldvaluelen = sizeof(oldvalue);
retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
(char *) &oldvalue, &oldvaluelen);
if (retcode == 0) {
newvalue = SO_SYNCHRONOUS_NONALERT;
setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
(char *) &newvalue, sizeof(newvalue));
}
#endif
/* Set socket to synchronous mode (= non-overlapped) so that file
descriptor-oriented functions (read()/write() etc.) can be
used */
SOCKET sock = WSASocket(sock_domain, SOCK_STREAM, 0,
NULL, 0,
0 /* not WSA_FLAG_OVERLAPPED */);
if (sock == INVALID_SOCKET
|| connect(sock, &sock_addr.s_gen, sock_addr_len) != 0)
caml_fatal_error("cannot connect to debugger at %s\n"
"WSA error code: %d",
(dbg_addr ? dbg_addr : "(none)"),
WSAGetLastError());
dbg_socket = _open_osfhandle(sock, 0);
if (dbg_socket != -1)
xavierleroy marked this conversation as resolved.
Show resolved Hide resolved
#else
dbg_socket = socket(sock_domain, SOCK_STREAM, 0);
#ifdef _WIN32
if (retcode == 0) {
/* Restore initial mode */
setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
(char *) &oldvalue, oldvaluelen);
}
#endif
if (dbg_socket == -1 ||
connect(dbg_socket, &sock_addr.s_gen, sock_addr_len) == -1){
caml_fatal_error
(
"cannot connect to debugger at %s\n"
"error: %s",
(dbg_addr ? dbg_addr : "(none)"),
strerror (errno)
);
}
#ifdef _WIN32
dbg_socket = _open_osfhandle(dbg_socket, 0);
if (dbg_socket == -1)
caml_fatal_error("_open_osfhandle failed");
connect(dbg_socket, &sock_addr.s_gen, sock_addr_len) == -1)
#endif
caml_fatal_error("cannot connect to debugger at %s\n"
"error: %s",
(dbg_addr ? dbg_addr : "(none)"),
strerror (errno));
dbg_in = caml_open_descriptor_in(dbg_socket);
dbg_out = caml_open_descriptor_out(dbg_socket);
/* The code in this file does not bracket channel I/O operations with
Expand Down