glib/win32: introduce private g_win32_handle_is_socket()

Used in following commits, including in some GIO experiments.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau
2022-04-08 14:49:49 +04:00
parent c43472060b
commit 277657eacc
5 changed files with 79 additions and 1 deletions

View File

@@ -1450,6 +1450,25 @@ g_win32_find_helper_executable_path (const gchar *executable_name, void *dll_han
return executable_path;
}
/*
* g_win32_handle_is_socket:
* @h: a win32 HANDLE
*
* Returns: %TRUE if the handle is a `SOCKET`.
*/
gboolean
g_win32_handle_is_socket (HANDLE h)
{
int option = 0;
int optlen = sizeof (option);
/* according to: https://stackoverflow.com/a/50981652/1277510, this is reasonable */
if (getsockopt ((SOCKET) h, SOL_SOCKET, SO_DEBUG, (char *) &option, &optlen) == SOCKET_ERROR)
return FALSE;
return TRUE;
}
/*
* g_win32_reopen_noninherited:
* @fd: (transfer full): A file descriptor