#include <errno.h>
#include <sys/types.h>
-#ifndef PLATFORM_WIN32
+#ifndef HOST_WIN32
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/appdomain.h>
+#include <mono/metadata/file-io.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/threads-types.h>
#include <mono/utils/mono-poll.h>
#include "mono/io-layer/socket-wrappers.h"
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
/* This is a kludge to make this file build under cygwin:
* w32api/ws2tcpip.h has definitions for some AF_INET6 values and
* prototypes for some but not all required functions (notably
#undef AF_INET6
#endif
-#undef DEBUG
+#define LOGDEBUG(...)
+/* define LOGDEBUG(...) g_message(__VA_ARGS__) */
+
+/*
+ * Some older versions of libc provide IPV6 support without defining the AI_ADDRCONFIG
+ * flag for getaddrinfo.
+ */
+#ifndef AI_ADDRCONFIG
+#define AI_ADDRCONFIG 0
+#endif
static gint32 convert_family(MonoAddressFamily mono_family)
{
break;
case AddressFamily_Sna:
+#ifdef AF_SNA
family=AF_SNA;
+#endif
break;
case AddressFamily_DecNet:
+#ifdef AF_DECnet
family=AF_DECnet;
+#endif
break;
case AddressFamily_AppleTalk:
break;
#endif
+#ifdef AF_SNA
case AF_SNA:
family=AddressFamily_Sna;
break;
+#endif
+#ifdef AF_DECnet
case AF_DECnet:
family=AddressFamily_DecNet;
break;
+#endif
case AF_APPLETALK:
family=AddressFamily_AppleTalk;
break;
case SocketType_Rdm:
+#ifdef SOCK_RDM
type=SOCK_RDM;
+#endif
break;
case SocketType_Seqpacket:
{
MONO_ARCH_SAVE_REGS;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": closing 0x%x", sock);
-#endif
+ LOGDEBUG (g_message ("%s: closing 0x%x", __func__, sock));
*error = 0;
{
MONO_ARCH_SAVE_REGS;
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": returning %d", WSAGetLastError());
-#endif
+ LOGDEBUG (g_message("%s: returning %d", __func__, WSAGetLastError()));
return(WSAGetLastError());
}
MONO_ARCH_SAVE_REGS;
*error = 0;
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
{
- MonoThread* curthread = mono_thread_current ();
+ MonoInternalThread* curthread = mono_thread_internal_current ();
curthread->interrupt_on_stop = (gpointer)TRUE;
newsock = _wapi_accept (sock, NULL, 0);
curthread->interrupt_on_stop = (gpointer)FALSE;
return(NULL);
}
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": bound to %s port %d", inet_ntoa(((struct sockaddr_in *)&sa)->sin_addr), ntohs(((struct sockaddr_in *)&sa)->sin_port));
-#endif
+ LOGDEBUG (g_message("%s: bound to %s port %d", __func__, inet_ntoa(((struct sockaddr_in *)&sa)->sin_addr), ntohs(((struct sockaddr_in *)&sa)->sin_port)));
return(create_object_from_sockaddr((struct sockaddr *)sa, salen,
error));
return(NULL);
}
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": connected to %s port %d", inet_ntoa(((struct sockaddr_in *)&sa)->sin_addr), ntohs(((struct sockaddr_in *)&sa)->sin_port));
-#endif
+ LOGDEBUG (g_message("%s: connected to %s port %d", __func__, inet_ntoa(((struct sockaddr_in *)&sa)->sin_addr), ntohs(((struct sockaddr_in *)&sa)->sin_port)));
return(create_object_from_sockaddr((struct sockaddr *)sa, salen,
error));
return;
}
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": binding to %s port %d", inet_ntoa(((struct sockaddr_in *)sa)->sin_addr), ntohs (((struct sockaddr_in *)sa)->sin_port));
-#endif
+ LOGDEBUG (g_message("%s: binding to %s port %d", __func__, inet_ntoa(((struct sockaddr_in *)sa)->sin_addr), ntohs (((struct sockaddr_in *)sa)->sin_port)));
ret = _wapi_bind (sock, sa, sa_size);
if(ret==SOCKET_ERROR) {
ves_icall_System_Net_Sockets_Socket_Poll_internal (SOCKET sock, gint mode,
gint timeout, gint32 *error)
{
- MonoThread *thread = NULL;
+ MonoInternalThread *thread = NULL;
mono_pollfd *pfds;
int ret;
time_t start;
int leave = 0;
if (thread == NULL) {
- thread = mono_thread_current ();
+ thread = mono_thread_internal_current ();
}
leave = mono_thread_test_state (thread, ThreadState_AbortRequested | ThreadState_StopRequested);
} while (ret == -1 && errno == EINTR);
if (ret == -1) {
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
*error = WSAGetLastError ();
#else
*error = errno_to_WSA (errno, __func__);
return;
}
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": connecting to %s port %d", inet_ntoa(((struct sockaddr_in *)sa)->sin_addr), ntohs (((struct sockaddr_in *)sa)->sin_port));
-#endif
+ LOGDEBUG (g_message("%s: connecting to %s port %d", __func__, inet_ntoa(((struct sockaddr_in *)sa)->sin_addr), ntohs (((struct sockaddr_in *)sa)->sin_port)));
ret = _wapi_connect (sock, sa, sa_size);
if(ret==SOCKET_ERROR) {
*error = 0;
-#ifdef DEBUG
- g_message("%s: disconnecting from socket %p (reuse %d)", __func__,
- sock, reuse);
-#endif
+ LOGDEBUG (g_message("%s: disconnecting from socket %p (reuse %d)", __func__, sock, reuse));
/* I _think_ the extension function pointers need to be looked
* up for each socket. FIXME: check the best way to store
return (0);
}
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
{
- MonoThread* curthread = mono_thread_current ();
+ MonoInternalThread* curthread = mono_thread_internal_current ();
curthread->interrupt_on_stop = (gpointer)TRUE;
ret = _wapi_recv (sock, buf, count, recvflags);
curthread->interrupt_on_stop = (gpointer)FALSE;
return(0);
}
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": alen: %d", alen);
-#endif
+ LOGDEBUG (g_message("%s: alen: %d", __func__, alen));
buf=mono_array_addr(buffer, guchar, offset);
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": Sending %d bytes", count);
-#endif
+ LOGDEBUG (g_message("%s: Sending %d bytes", __func__, count));
sendflags = convert_socketflags (flags);
if (sendflags == -1) {
return(0);
}
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": alen: %d", alen);
-#endif
+ LOGDEBUG (g_message("%s: alen: %d", __func__, alen));
buf=mono_array_addr(buffer, guchar, offset);
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": Sending %d bytes", count);
-#endif
+ LOGDEBUG (g_message("%s: Sending %d bytes", __func__, count));
sendflags = convert_socketflags (flags);
if (sendflags == -1) {
#define POLL_ERRORS (MONO_POLLERR | MONO_POLLHUP | MONO_POLLNVAL)
void ves_icall_System_Net_Sockets_Socket_Select_internal(MonoArray **sockets, gint32 timeout, gint32 *error)
{
- MonoThread *thread = NULL;
+ MonoInternalThread *thread = NULL;
MonoObject *obj;
mono_pollfd *pfds;
int nfds, idx;
MonoClass *sock_arr_class;
MonoArray *socks;
time_t start;
- mono_array_size_t socks_size;
+ uintptr_t socks_size;
MONO_ARCH_SAVE_REGS;
if (ret == -1 && errno == EINTR) {
int leave = 0;
if (thread == NULL)
- thread = mono_thread_current ();
+ thread = mono_thread_internal_current ();
leave = mono_thread_test_state (thread, ThreadState_AbortRequested | ThreadState_StopRequested);
} while (ret == -1 && errno == EINTR);
if (ret == -1) {
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
*error = WSAGetLastError ();
#else
*error = errno_to_WSA (errno, __func__);
}
sock_arr_class= ((MonoObject *)*sockets)->vtable->klass;
- socks_size = ((mono_array_size_t)ret) + 3; /* space for the NULL delimiters */
+ socks_size = ((uintptr_t)ret) + 3; /* space for the NULL delimiters */
socks = mono_array_new_full (mono_domain_get (), sock_arr_class, &socks_size, NULL);
mode = idx = 0;
extern MonoBoolean ves_icall_System_Net_Dns_GetHostByAddr_internal(MonoString *addr, MonoString **h_name, MonoArray **h_aliases, MonoArray **h_addr_list)
{
char *address;
- gboolean v1;
#ifdef AF_INET6
struct sockaddr_in saddr;
gboolean ret;
#endif
- v1 = mono_framework_version () == 1;
-
address = mono_string_to_utf8 (addr);
#ifdef AF_INET6
}
g_free(address);
- if (v1) {
- flags = NI_NAMEREQD;
- }
-
if(family == AF_INET) {
#if HAVE_SOCKADDR_IN_SIN_LEN
saddr.sin_len = sizeof (saddr);
}
if ((he = gethostbyaddr ((char *) &inaddr, sizeof (inaddr), AF_INET)) == NULL) {
- if (v1) {
- ret = FALSE;
- } else {
- ret = ipaddr_to_IPHostEntry (address, h_name,
- h_aliases, h_addr_list);
- }
+ ret = ipaddr_to_IPHostEntry (address, h_name, h_aliases, h_addr_list);
} else {
ret = hostent_to_IPHostEntry (he, h_name, h_aliases,
h_addr_list, FALSE);
return(TRUE);
}
+gboolean
+ves_icall_System_Net_Sockets_Socket_SendFile (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags)
+{
+ HANDLE file;
+ gint32 error;
+ TRANSMIT_FILE_BUFFERS buffers;
+
+ MONO_ARCH_SAVE_REGS;
+
+ if (filename == NULL)
+ return FALSE;
+
+ file = ves_icall_System_IO_MonoIO_Open (filename, FileMode_Open, FileAccess_Read, FileShare_Read, 0, &error);
+ if (file == INVALID_HANDLE_VALUE) {
+ SetLastError (error);
+ return FALSE;
+ }
+
+ memset (&buffers, 0, sizeof (buffers));
+ if (pre_buffer != NULL) {
+ buffers.Head = mono_array_addr (pre_buffer, guchar, 0);
+ buffers.HeadLength = mono_array_length (pre_buffer);
+ }
+ if (post_buffer != NULL) {
+ buffers.Tail = mono_array_addr (post_buffer, guchar, 0);
+ buffers.TailLength = mono_array_length (post_buffer);
+ }
+
+ if (!TransmitFile (sock, file, 0, 0, NULL, &buffers, flags)) {
+ CloseHandle (file);
+ return FALSE;
+ }
+
+ CloseHandle (file);
+ return TRUE;
+}
+
void mono_network_init(void)
{
WSADATA wsadata;
err=WSAStartup(MAKEWORD(2,0), &wsadata);
if(err!=0) {
- g_error(G_GNUC_PRETTY_FUNCTION ": Couldn't initialise networking");
+ g_error("%s: Couldn't initialise networking", __func__);
exit(-1);
}
-#ifdef DEBUG
- g_message(G_GNUC_PRETTY_FUNCTION ": Using socket library: %s", wsadata.szDescription);
- g_message(G_GNUC_PRETTY_FUNCTION ": Socket system status: %s", wsadata.szSystemStatus);
-#endif
+ LOGDEBUG (g_message("%s: Using socket library: %s", __func__, wsadata.szDescription));
+ LOGDEBUG (g_message("%s: Socket system status: %s", __func__, wsadata.szSystemStatus));
}
void mono_network_cleanup(void)