#include <mono/io-layer/wapi.h>
#include <mono/io-layer/wapi-private.h>
#include <mono/io-layer/socket-private.h>
-#include <mono/io-layer/handles-private.h>
#include <mono/io-layer/socket-wrappers.h>
#include <mono/io-layer/io-trace.h>
#include <mono/utils/mono-poll.h>
#include <mono/utils/mono-once.h>
#include <mono/utils/mono-logger-internals.h>
+#include <mono/utils/w32handle.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
static const gchar* socket_typename (void);
static gsize socket_typesize (void);
-static WapiHandleOps _wapi_socket_ops = {
+static MonoW32HandleOps _wapi_socket_ops = {
socket_close, /* close */
NULL, /* signal */
NULL, /* own */
void
_wapi_socket_init (void)
{
- _wapi_handle_register_ops (WAPI_HANDLE_SOCKET, &_wapi_socket_ops);
+ mono_w32handle_register_ops (MONO_W32HANDLE_SOCKET, &_wapi_socket_ops);
}
static void socket_close (gpointer handle, gpointer data)
{
int ret;
struct _WapiHandle_socket *socket_handle = (struct _WapiHandle_socket *)data;
+ MonoThreadInfo *info = mono_thread_info_current ();
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: closing socket handle %p", __func__, handle);
do {
ret = close (GPOINTER_TO_UINT(handle));
} while (ret == -1 && errno == EINTR &&
- !_wapi_thread_cur_apc_pending ());
+ !mono_thread_info_is_interrupt_state (info));
if (ret == -1) {
gint errnum = errno;
static gboolean
cleanup_close (gpointer handle, gpointer data, gpointer user_data)
{
- if (_wapi_handle_type (handle) == WAPI_HANDLE_SOCKET)
- _wapi_handle_ops_close (handle, data);
+ if (mono_w32handle_get_type (handle) == MONO_W32HANDLE_SOCKET)
+ mono_w32handle_ops_close (handle, data);
return FALSE;
}
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: cleaning up", __func__);
in_cleanup = 1;
- _wapi_handle_foreach (cleanup_close, NULL);
+ mono_w32handle_foreach (cleanup_close, NULL);
in_cleanup = 0;
}
{
gpointer handle = GUINT_TO_POINTER (fd);
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(0);
}
- _wapi_handle_unref (handle);
+ mono_w32handle_unref (handle);
return(0);
}
struct _WapiHandle_socket new_socket_handle = {0};
gboolean ok;
int new_fd;
+ MonoThreadInfo *info = mono_thread_info_current ();
if (addr != NULL && *addrlen < sizeof(struct sockaddr)) {
WSASetLastError (WSAEFAULT);
return(INVALID_SOCKET);
}
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(INVALID_SOCKET);
}
- ok = _wapi_lookup_handle (handle, WAPI_HANDLE_SOCKET,
+ ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_SOCKET,
(gpointer *)&socket_handle);
if (ok == FALSE) {
g_warning ("%s: error looking up socket handle %p",
do {
new_fd = accept (fd, addr, addrlen);
} while (new_fd == -1 && errno == EINTR &&
- !_wapi_thread_cur_apc_pending());
+ !mono_thread_info_is_interrupt_state (info));
if (new_fd == -1) {
gint errnum = errno;
return(INVALID_SOCKET);
}
- if (new_fd >= _wapi_fd_reserve) {
+ if (new_fd >= mono_w32handle_fd_reserve) {
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big", __func__);
WSASetLastError (WSASYSCALLFAILURE);
new_socket_handle.protocol = socket_handle->protocol;
new_socket_handle.still_readable = 1;
- new_handle = _wapi_handle_new_fd (WAPI_HANDLE_SOCKET, new_fd,
+ new_handle = mono_w32handle_new_fd (MONO_W32HANDLE_SOCKET, new_fd,
&new_socket_handle);
if(new_handle == INVALID_HANDLE_VALUE) {
g_warning ("%s: error creating socket handle", __func__);
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
struct _WapiHandle_socket *socket_handle;
gboolean ok;
gint errnum;
-
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ MonoThreadInfo *info = mono_thread_info_current ();
+
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
* But don't do this for EWOULDBLOCK (bug 317315)
*/
if (errnum != WSAEWOULDBLOCK) {
- ok = _wapi_lookup_handle (handle,
- WAPI_HANDLE_SOCKET,
+ ok = mono_w32handle_lookup (handle,
+ MONO_W32HANDLE_SOCKET,
(gpointer *)&socket_handle);
if (ok == FALSE) {
/* ECONNRESET means the socket was closed by another thread */
fds.fd = fd;
fds.events = MONO_POLLOUT;
while (mono_poll (&fds, 1, -1) == -1 &&
- !_wapi_thread_cur_apc_pending ()) {
+ !mono_thread_info_is_interrupt_state (info)) {
if (errno != EINTR) {
errnum = errno_to_WSA (errno, __func__);
errnum = errno_to_WSA (so_error, __func__);
/* Need to save this socket error */
- ok = _wapi_lookup_handle (handle, WAPI_HANDLE_SOCKET,
+ ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_SOCKET,
(gpointer *)&socket_handle);
if (ok == FALSE) {
g_warning ("%s: error looking up socket handle %p", __func__, handle);
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
struct _WapiHandle_socket *socket_handle;
gboolean ok;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
}
if (optname == SO_ERROR) {
- ok = _wapi_lookup_handle (handle, WAPI_HANDLE_SOCKET,
+ ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_SOCKET,
(gpointer *)&socket_handle);
if (ok == FALSE) {
g_warning ("%s: error looking up socket handle %p",
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
struct _WapiHandle_socket *socket_handle;
gboolean ok;
int ret;
+ MonoThreadInfo *info = mono_thread_info_current ();
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
do {
ret = recvfrom (fd, buf, len, recv_flags, from, fromlen);
} while (ret == -1 && errno == EINTR &&
- !_wapi_thread_cur_apc_pending ());
+ !mono_thread_info_is_interrupt_state (info));
if (ret == 0 && len > 0) {
/* According to the Linux man page, recvfrom only
* still_readable != 1 then shutdown
* (SHUT_RD|SHUT_RDWR) has been called locally.
*/
- ok = _wapi_lookup_handle (handle, WAPI_HANDLE_SOCKET,
+ ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_SOCKET,
(gpointer *)&socket_handle);
if (ok == FALSE || socket_handle->still_readable != 1) {
ret = -1;
struct _WapiHandle_socket *socket_handle;
gboolean ok;
int ret;
+ MonoThreadInfo *info = mono_thread_info_current ();
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
do {
ret = recvmsg (fd, msg, recv_flags);
} while (ret == -1 && errno == EINTR &&
- !_wapi_thread_cur_apc_pending ());
+ !mono_thread_info_is_interrupt_state (info));
if (ret == 0) {
/* see _wapi_recvfrom */
- ok = _wapi_lookup_handle (handle, WAPI_HANDLE_SOCKET,
+ ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_SOCKET,
(gpointer *)&socket_handle);
if (ok == FALSE || socket_handle->still_readable != 1) {
ret = -1;
{
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
+ MonoThreadInfo *info = mono_thread_info_current ();
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
do {
ret = send (fd, msg, len, send_flags);
} while (ret == -1 && errno == EINTR &&
- !_wapi_thread_cur_apc_pending ());
+ !mono_thread_info_is_interrupt_state (info));
if (ret == -1) {
gint errnum = errno;
{
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
+ MonoThreadInfo *info = mono_thread_info_current ();
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
do {
ret = sendto (fd, msg, len, send_flags, to, tolen);
} while (ret == -1 && errno == EINTR &&
- !_wapi_thread_cur_apc_pending ());
+ !mono_thread_info_is_interrupt_state (info));
if (ret == -1) {
gint errnum = errno;
{
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
+ MonoThreadInfo *info = mono_thread_info_current ();
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
do {
ret = sendmsg (fd, msg, send_flags);
} while (ret == -1 && errno == EINTR &&
- !_wapi_thread_cur_apc_pending ());
+ !mono_thread_info_is_interrupt_state (info));
if (ret == -1) {
gint errnum = errno;
#endif
struct timeval tv;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
if (how == SHUT_RD ||
how == SHUT_RDWR) {
- ok = _wapi_lookup_handle (handle, WAPI_HANDLE_SOCKET,
+ ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_SOCKET,
(gpointer *)&socket_handle);
if (ok == FALSE) {
g_warning ("%s: error looking up socket handle %p",
return(INVALID_SOCKET);
}
- if (fd >= _wapi_fd_reserve) {
+ if (fd >= mono_w32handle_fd_reserve) {
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big (%d >= %d)",
- __func__, fd, _wapi_fd_reserve);
+ __func__, fd, mono_w32handle_fd_reserve);
WSASetLastError (WSASYSCALLFAILURE);
close (fd);
}
- handle = _wapi_handle_new_fd (WAPI_HANDLE_SOCKET, fd, &socket_handle);
+ handle = mono_w32handle_new_fd (MONO_W32HANDLE_SOCKET, fd, &socket_handle);
if (handle == INVALID_HANDLE_VALUE) {
g_warning ("%s: error creating socket handle", __func__);
WSASetLastError (WSASYSCALLFAILURE);
gpointer handle = GUINT_TO_POINTER (fd);
int newsock, ret;
- ok = _wapi_lookup_handle (handle, WAPI_HANDLE_SOCKET,
+ ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_SOCKET,
(gpointer *)&socket_handle);
if (ok == FALSE) {
g_warning ("%s: error looking up socket handle %p", __func__,
static gint
wapi_sendfile (guint32 socket, gpointer fd, guint32 bytes_to_write, guint32 bytes_per_send, guint32 flags)
{
+ MonoThreadInfo *info = mono_thread_info_current ();
#if defined(HAVE_SENDFILE) && (defined(__linux__) || defined(DARWIN))
gint file = GPOINTER_TO_INT (fd);
gint n;
/* TODO: Might not send the entire file for non-blocking sockets */
res = sendfile (file, socket, 0, &statbuf.st_size, NULL, 0);
#endif
- } while (res != -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
+ } while (res != -1 && errno == EINTR && !mono_thread_info_is_interrupt_state (info));
if (res == -1) {
errnum = errno;
errnum = errno_to_WSA (errnum, __func__);
do {
do {
n = read (file, buffer, SF_BUFFER_SIZE);
- } while (n == -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
+ } while (n == -1 && errno == EINTR && !mono_thread_info_is_interrupt_state (info));
if (n == -1)
break;
if (n == 0) {
}
do {
n = send (socket, buffer, n, 0); /* short sends? enclose this in a loop? */
- } while (n == -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
- } while (n != -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
+ } while (n == -1 && errno == EINTR && !mono_thread_info_is_interrupt_state (info));
+ } while (n != -1 && errno == EINTR && !mono_thread_info_is_interrupt_state (info));
if (n == -1) {
gint errnum = errno;
gpointer sock = GUINT_TO_POINTER (socket);
gint ret;
- if (_wapi_handle_type (sock) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (sock) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return FALSE;
}
int ret;
gchar *buffer = NULL;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return SOCKET_ERROR;
}
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
fd_set *exceptfds, struct timeval *timeout)
{
int ret, maxfd;
+ MonoThreadInfo *info = mono_thread_info_current ();
for (maxfd = FD_SETSIZE-1; maxfd >= 0; maxfd--) {
if ((readfds && FD_ISSET (maxfd, readfds)) ||
ret = select(maxfd + 1, readfds, writefds, exceptfds,
timeout);
} while (ret == -1 && errno == EINTR &&
- !_wapi_thread_cur_apc_pending ());
+ !mono_thread_info_is_interrupt_state (info));
if (ret == -1) {
gint errnum = errno;
return;
}
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return;
}
return(0);
}
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(0);
}
return;
}
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return;
}