#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 guint32 in_cleanup = 0;
static void socket_close (gpointer handle, gpointer data);
+static void socket_details (gpointer data);
+static const gchar* socket_typename (void);
+static gsize socket_typesize (void);
-struct _WapiHandleOps _wapi_socket_ops = {
+static MonoW32HandleOps _wapi_socket_ops = {
socket_close, /* close */
NULL, /* signal */
NULL, /* own */
NULL, /* is_owned */
NULL, /* special_wait */
- NULL /* prewait */
+ NULL, /* prewait */
+ socket_details, /* details */
+ socket_typename, /* typename */
+ socket_typesize, /* typesize */
};
-static mono_once_t socket_ops_once=MONO_ONCE_INIT;
-
-static void socket_ops_init (void)
+void
+_wapi_socket_init (void)
{
- /* No capabilities to register */
+ mono_w32handle_register_ops (MONO_W32HANDLE_SOCKET, &_wapi_socket_ops);
}
static void socket_close (gpointer handle, gpointer data)
socket_handle->saved_error = 0;
}
+static void socket_details (gpointer data)
+{
+ /* FIXME: do something */
+}
+
+static const gchar* socket_typename (void)
+{
+ return "Socket";
+}
+
+static gsize socket_typesize (void)
+{
+ return sizeof (struct _WapiHandle_socket);
+}
+
static gboolean
-cleanup_close (gpointer handle, gpointer data)
+cleanup_close (gpointer handle, gpointer data, gpointer user_data)
{
- _wapi_handle_ops_close (handle, NULL);
- return TRUE;
+ if (mono_w32handle_get_type (handle) == MONO_W32HANDLE_SOCKET)
+ mono_w32handle_ops_close (handle, data);
+
+ return FALSE;
}
void _wapi_cleanup_networking(void)
MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: cleaning up", __func__);
in_cleanup = 1;
- _wapi_handle_foreach (WAPI_HANDLE_SOCKET, 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);
}
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",
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 == _WAPI_HANDLE_INVALID) {
+ if(new_handle == INVALID_HANDLE_VALUE) {
g_warning ("%s: error creating socket handle", __func__);
WSASetLastError (ERROR_GEN_FAILURE);
return(INVALID_SOCKET);
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);
}
gboolean ok;
gint errnum;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ 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 */
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);
}
gboolean ok;
int ret;
- if (_wapi_handle_type (handle) != WAPI_HANDLE_SOCKET) {
+ if (mono_w32handle_get_type (handle) != MONO_W32HANDLE_SOCKET) {
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
* 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;
gboolean ok;
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 (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;
- 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);
}
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);
}
#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);
}
- mono_once (&socket_ops_once, socket_ops_init);
-
- handle = _wapi_handle_new_fd (WAPI_HANDLE_SOCKET, fd, &socket_handle);
- if (handle == _WAPI_HANDLE_INVALID) {
+ 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);
close (fd);
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__,
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);
}
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;
}