Skip to content

Commit

Permalink
Merge pull request mono/mono#1698 from ludovic-henry/socket-reorg-2
Browse files Browse the repository at this point in the history
Reorganize Socket code

Commit migrated from mono/mono@a95ec1f
  • Loading branch information
kumpera committed Apr 9, 2015
2 parents c6ca052 + 129117d commit 7305a23
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 74 deletions.
1 change: 0 additions & 1 deletion src/mono/mono/metadata/class-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,6 @@ mono_inflate_generic_signature (MonoMethodSignature *sig, MonoGenericContext *co

typedef struct {
MonoImage *corlib;
MonoImage *system;
MonoClass *object_class;
MonoClass *byte_class;
MonoClass *void_class;
Expand Down
3 changes: 0 additions & 3 deletions src/mono/mono/metadata/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,6 @@ mono_init_internal (const char *filename, const char *exe_filename, const char *
}
mono_defaults.corlib = mono_assembly_get_image (ass);

/* might be NULL if System.dll is not yet loaded */
mono_defaults.system = mono_image_loaded ("System");

mono_defaults.object_class = mono_class_from_name (
mono_defaults.corlib, "System", "Object");
g_assert (mono_defaults.object_class != 0);
Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/metadata/icall-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,22 +426,22 @@ ICALL(SOCK_6, "Connect_internal(intptr,System.Net.SocketAddress,int&)", ves_ical
ICALL (SOCK_6a, "Disconnect_internal(intptr,bool,int&)", ves_icall_System_Net_Sockets_Socket_Disconnect_internal)
ICALL(SOCK_7, "GetSocketOption_arr_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,byte[]&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal)
ICALL(SOCK_8, "GetSocketOption_obj_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object&,int&)", ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal)
ICALL(SOCK_21, "IOControl_internal(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_IOControl_internal)
ICALL(SOCK_9, "Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal)
ICALL(SOCK_10, "LocalEndPoint_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal)
ICALL(SOCK_11, "Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal)
ICALL(SOCK_13, "ReceiveFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal)
ICALL(SOCK_11a, "Receive_internal(intptr,System.Net.Sockets.Socket/WSABUF[],System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_array_internal)
ICALL(SOCK_12, "Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal)
ICALL(SOCK_13, "RecvFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&)", ves_icall_System_Net_Sockets_Socket_RecvFrom_internal)
ICALL(SOCK_14, "RemoteEndPoint_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal)
ICALL(SOCK_15, "Select_internal(System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal)
ICALL(SOCK_15a, "SendFile(intptr,string,byte[],byte[],System.Net.Sockets.TransmitFileOptions)", ves_icall_System_Net_Sockets_Socket_SendFile)
ICALL(SOCK_15a, "SendFile_internal(intptr,string,byte[],byte[],System.Net.Sockets.TransmitFileOptions)", ves_icall_System_Net_Sockets_Socket_SendFile_internal)
ICALL(SOCK_16, "SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal)
ICALL(SOCK_16a, "Send_internal(intptr,System.Net.Sockets.Socket/WSABUF[],System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_array_internal)
ICALL(SOCK_17, "Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal)
ICALL(SOCK_18, "SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal)
ICALL(SOCK_19, "Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal)
ICALL(SOCK_20, "Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal)
ICALL(SOCK_21, "WSAIoctl(intptr,int,byte[],byte[],int&)", ves_icall_System_Net_Sockets_Socket_WSAIoctl)
ICALL(SOCK_21a, "cancel_blocking_socket_operation", icall_cancel_blocking_socket_operation)
ICALL(SOCK_22, "socket_pool_queue", icall_append_io_job)

Expand Down
12 changes: 6 additions & 6 deletions src/mono/mono/metadata/socket-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ static gint32 get_family_hint(void)
MonoVTable *vtable;

socket_class = mono_class_from_name (get_socket_assembly (), "System.Net.Sockets", "Socket");
ipv4_field = mono_class_get_field_from_name (socket_class, "ipv4Supported");
ipv6_field = mono_class_get_field_from_name (socket_class, "ipv6Supported");
ipv4_field = mono_class_get_field_from_name (socket_class, "ipv4_supported");
ipv6_field = mono_class_get_field_from_name (socket_class, "ipv6_supported");
vtable = mono_class_vtable (mono_domain_get (), socket_class);
g_assert (vtable);
mono_runtime_class_init (vtable);
Expand Down Expand Up @@ -1406,7 +1406,7 @@ gint32 ves_icall_System_Net_Sockets_Socket_Receive_array_internal(SOCKET sock, M
return(recv);
}

gint32 ves_icall_System_Net_Sockets_Socket_RecvFrom_internal(SOCKET sock, MonoArray *buffer, gint32 offset, gint32 count, gint32 flags, MonoObject **sockaddr, gint32 *error)
gint32 ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal(SOCKET sock, MonoArray *buffer, gint32 offset, gint32 count, gint32 flags, MonoObject **sockaddr, gint32 *error)
{
int ret;
guchar *buf;
Expand Down Expand Up @@ -1573,7 +1573,7 @@ static SOCKET Socket_to_SOCKET(MonoObject *sockobj)
MonoSafeHandle *safe_handle;
MonoClassField *field;

field = mono_class_get_field_from_name (sockobj->vtable->klass, "socket");
field = mono_class_get_field_from_name (sockobj->vtable->klass, "safe_handle");
safe_handle = ((MonoSafeHandle*) (*(gpointer *)(((char *)sockobj)+field->offset)));

if (safe_handle == NULL)
Expand Down Expand Up @@ -2198,7 +2198,7 @@ void ves_icall_System_Net_Sockets_Socket_Shutdown_internal(SOCKET sock,
}

gint
ves_icall_System_Net_Sockets_Socket_WSAIoctl (SOCKET sock, gint32 code,
ves_icall_System_Net_Sockets_Socket_IOControl_internal (SOCKET sock, gint32 code,
MonoArray *input,
MonoArray *output, gint32 *error)
{
Expand Down Expand Up @@ -2467,7 +2467,7 @@ extern MonoBoolean ves_icall_System_Net_Dns_GetHostName_internal(MonoString **h_
}

gboolean
ves_icall_System_Net_Sockets_Socket_SendFile (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags)
ves_icall_System_Net_Sockets_Socket_SendFile_internal (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags)
{
HANDLE file;
gint32 error;
Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/metadata/socket-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ extern void ves_icall_System_Net_Sockets_Socket_Bind_internal(SOCKET sock, MonoO
extern void ves_icall_System_Net_Sockets_Socket_Connect_internal(SOCKET sock, MonoObject *sockaddr, gint32 *error);
extern gint32 ves_icall_System_Net_Sockets_Socket_Receive_internal(SOCKET sock, MonoArray *buffer, gint32 offset, gint32 count, gint32 flags, gint32 *error);
extern gint32 ves_icall_System_Net_Sockets_Socket_Receive_array_internal(SOCKET sock, MonoArray *buffers, gint32 flags, gint32 *error);
extern gint32 ves_icall_System_Net_Sockets_Socket_RecvFrom_internal(SOCKET sock, MonoArray *buffer, gint32 offset, gint32 count, gint32 flags, MonoObject **sockaddr, gint32 *error);
extern gint32 ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal(SOCKET sock, MonoArray *buffer, gint32 offset, gint32 count, gint32 flags, MonoObject **sockaddr, gint32 *error);
extern gint32 ves_icall_System_Net_Sockets_Socket_Send_internal(SOCKET sock, MonoArray *buffer, gint32 offset, gint32 count, gint32 flags, gint32 *error);
extern gint32 ves_icall_System_Net_Sockets_Socket_Send_array_internal(SOCKET sock, MonoArray *buffers, gint32 flags, gint32 *error);
extern gint32 ves_icall_System_Net_Sockets_Socket_SendTo_internal(SOCKET sock, MonoArray *buffer, gint32 offset, gint32 count, gint32 flags, MonoObject *sockaddr, gint32 *error);
Expand All @@ -213,13 +213,13 @@ extern void ves_icall_System_Net_Sockets_Socket_Shutdown_internal(SOCKET sock, g
extern void ves_icall_System_Net_Sockets_Socket_GetSocketOption_obj_internal(SOCKET sock, gint32 level, gint32 name, MonoObject **obj_val, gint32 *error);
extern void ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_internal(SOCKET sock, gint32 level, gint32 name, MonoArray **byte_val, gint32 *error);
extern void ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal(SOCKET sock, gint32 level, gint32 name, MonoObject *obj_val, MonoArray *byte_val, gint32 int_val, gint32 *error);
extern int ves_icall_System_Net_Sockets_Socket_WSAIoctl (SOCKET sock, gint32 code, MonoArray *input, MonoArray *output, gint32 *error);
extern int ves_icall_System_Net_Sockets_Socket_IOControl_internal (SOCKET sock, gint32 code, MonoArray *input, MonoArray *output, gint32 *error);
extern MonoBoolean ves_icall_System_Net_Dns_GetHostByName_internal(MonoString *host, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list);
extern MonoBoolean ves_icall_System_Net_Dns_GetHostByAddr_internal(MonoString *addr, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list);
extern MonoBoolean ves_icall_System_Net_Dns_GetHostName_internal(MonoString **h_name);
extern MonoBoolean ves_icall_System_Net_Sockets_Socket_Poll_internal (SOCKET sock, gint mode, gint timeout, gint32 *error);
extern void ves_icall_System_Net_Sockets_Socket_Disconnect_internal(SOCKET sock, MonoBoolean reuse, gint32 *error);
extern gboolean ves_icall_System_Net_Sockets_Socket_SendFile (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags);
extern gboolean ves_icall_System_Net_Sockets_Socket_SendFile_internal (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags);
void icall_cancel_blocking_socket_operation (MonoThread *thread);

extern void mono_network_init(void);
Expand Down
63 changes: 29 additions & 34 deletions src/mono/mono/metadata/threadpool-ms-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,43 +1062,39 @@ ensure_cleanedup (void)
io_status = STATUS_CLEANED_UP;
}

gboolean
mono_threadpool_ms_is_io (MonoObject *target, MonoObject *state)
static gboolean
is_socket_async_callback (MonoImage *system_image, MonoClass *class)
{
static MonoClass *socket_class = NULL;
static MonoClass *socket_async_class = NULL;
static MonoClass *process_class = NULL;
static MonoClass *async_read_handler_class = NULL;
MonoClass *class;
MonoSocketAsyncResult *sockares;
MonoClass *socket_async_callback_class = NULL;

if (!mono_defaults.system)
mono_defaults.system = mono_image_loaded ("System");
if (!mono_defaults.system)
return FALSE;
g_assert (mono_defaults.system);
socket_async_callback_class = mono_class_from_name (system_image, "System.Net.Sockets", "SocketAsyncCallback");
g_assert (socket_async_callback_class);

if (!socket_class)
socket_class = mono_class_from_name (mono_defaults.system, "System.Net.Sockets", "Socket");
g_assert (socket_class);
return class == socket_async_callback_class;
}

static gboolean
is_async_read_handler (MonoImage *system_image, MonoClass *class)
{
MonoClass *process_class = NULL;

if (!process_class)
process_class = mono_class_from_name (mono_defaults.system, "System.Diagnostics", "Process");
process_class = mono_class_from_name (system_image, "System.Diagnostics", "Process");
g_assert (process_class);

class = target->vtable->klass;
return class->nested_in && class->nested_in == process_class && strcmp (class->name, "AsyncReadHandler") == 0;
}

if (!socket_async_class) {
if (class->nested_in && class->nested_in == socket_class && strcmp (class->name, "SocketAsyncCall") == 0)
socket_async_class = class;
}
gboolean
mono_threadpool_ms_is_io (MonoObject *target, MonoObject *state)
{
MonoImage *system_image;
MonoSocketAsyncResult *sockares;

if (!async_read_handler_class) {
if (class->nested_in && class->nested_in == process_class && strcmp (class->name, "AsyncReadHandler") == 0)
async_read_handler_class = class;
}
system_image = mono_image_loaded ("System");
if (!system_image)
return FALSE;

if (class != socket_async_class && class != async_read_handler_class)
if (!is_socket_async_callback (system_image, target->vtable->klass) && !is_async_read_handler (system_image, target->vtable->klass))
return FALSE;

sockares = (MonoSocketAsyncResult*) state;
Expand Down Expand Up @@ -1237,17 +1233,16 @@ mono_threadpool_ms_io_remove_domain_jobs (MonoDomain *domain)
void
mono_threadpool_io_enqueue_socket_async_result (MonoDomain *domain, MonoSocketAsyncResult *sockares)
{
static MonoClass *socket_runtime_work_item_class = NULL;
MonoImage *system_image;
MonoClass *socket_runtime_work_item_class;
MonoSocketRuntimeWorkItem *srwi;

g_assert (sockares);

if (!mono_defaults.system)
mono_defaults.system = mono_image_loaded ("System");
g_assert (mono_defaults.system);
system_image = mono_image_loaded ("System");
g_assert (system_image);

if (!socket_runtime_work_item_class)
socket_runtime_work_item_class = mono_class_from_name (mono_defaults.system, "System.Net.Sockets", "MonoSocketRuntimeWorkItem");
socket_runtime_work_item_class = mono_class_from_name (system_image, "System.Net.Sockets", "MonoSocketRuntimeWorkItem");
g_assert (socket_runtime_work_item_class);

srwi = (MonoSocketRuntimeWorkItem*) mono_object_new (domain, socket_runtime_work_item_class);
Expand Down
28 changes: 4 additions & 24 deletions src/mono/mono/metadata/threadpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,6 @@ is_corlib_type (MonoDomain *domain, MonoClass *klass)
return klass->image == mono_defaults.corlib;
}

/*
* Note that we call it is_socket_type() where 'socket' refers to the image
* that contains the System.Net.Sockets.Socket type.
*/
static gboolean
is_socket_type (MonoDomain *domain, MonoClass *klass)
{
return is_system_type (domain, klass);
}

#define check_type_cached(domain, ASSEMBLY, _class, _namespace, _name, loc) do { \
if (*loc) \
return *loc == _class; \
Expand All @@ -235,8 +225,6 @@ is_socket_type (MonoDomain *domain, MonoClass *klass)

#define check_corlib_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, corlib, _class, _namespace, _name, loc)

#define check_socket_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, socket, _class, _namespace, _name, loc)

#define check_system_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, system, _class, _namespace, _name, loc)

static gboolean
Expand All @@ -245,26 +233,18 @@ is_corlib_asyncresult (MonoDomain *domain, MonoClass *klass)
check_corlib_type_cached (domain, klass, "System.Runtime.Remoting.Messaging", "AsyncResult", &domain->corlib_asyncresult_class);
}

static gboolean
is_socket (MonoDomain *domain, MonoClass *klass)
{
check_socket_type_cached (domain, klass, "System.Net.Sockets", "Socket", &domain->socket_class);
}

static gboolean
is_socketasyncresult (MonoDomain *domain, MonoClass *klass)
{
return (klass->nested_in &&
is_socket (domain, klass->nested_in) &&
!strcmp (klass->name, "SocketAsyncResult"));
static MonoClass *socket_async_result_klass = NULL;
check_system_type_cached (domain, klass, "System.Net.Sockets", "SocketAsyncResult", &socket_async_result_klass);
}

static gboolean
is_socketasynccall (MonoDomain *domain, MonoClass *klass)
{
return (klass->nested_in &&
is_socket (domain, klass->nested_in) &&
!strcmp (klass->name, "SocketAsyncCall"));
static MonoClass *socket_async_callback_klass = NULL;
check_system_type_cached (domain, klass, "System.Net.Sockets", "SocketAsyncCallback", &socket_async_callback_klass);
}

static gboolean
Expand Down

0 comments on commit 7305a23

Please sign in to comment.