[Mono-dev] [PATCH] Map SocketFlags enum to native flags
Ankit Jain
jankit at novell.com
Wed Feb 1 11:33:49 EST 2006
Hi,
The icalls for System.Net.Sockets.Receive_internal, ..Send_internal etc,
ignore any socket flags (like SocketFlags.Peek). The attached patch fixes
that.
The patch adds an enum MonoSocketFlags in mono/metadata/socket-io.h since
it contains other similar enums.
But this means that a "#include <mono/metadata/socket-io.h>" is required in
mono/io-layer/sockets.c, as the mapping of flags is done in
io-layer/sockets.c (_wapi_recv etc). Am not sure whether this dependency
is acceptable.
-Ankit
--
Blog : http://ankitj.blogspot.com
-------------- next part --------------
Index: mono/metadata/socket-io.h
===================================================================
--- mono/metadata/socket-io.h (revision 56384)
+++ mono/metadata/socket-io.h (working copy)
@@ -138,6 +138,16 @@
SocketOptionName_PeerCred=10001
} MonoSocketOptionName;
+/* This is a copy of System.Net.Sockets.SocketFlags */
+typedef enum {
+ SocketFlags_None = 0,
+ SocketFlags_OutOfBand = 1,
+ SocketFlags_MaxIOVectorLength = 0x10,
+ SocketFlags_Peek = 2,
+ SocketFlags_DontRoute = 4,
+ SocketFlags_Partial = 0x8000
+} MonoSocketFlags;
+
typedef struct _MonoSocketAsyncResult {
MonoObject obj;
MonoObject *socket;
Index: mono/metadata/ChangeLog
===================================================================
--- mono/metadata/ChangeLog (revision 56384)
+++ mono/metadata/ChangeLog (working copy)
@@ -1,3 +1,12 @@
+2006-02-01 Ankit Jain <jankit at novell.com>
+
+ * socket-io.h (MonoSocketFlags): New. Copy of System.Net.Sockets.SocketFlags
+ * socket-io.c (ves_icall_System_Net_Sockets_Socket_Receive_internal): Pass the
+ flags to _wapi_recv.
+ (ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal): Pass the flags to _wapi_recvfrom.
+ (ves_icall_System_Net_Sockets_Socket_Send_internal): Pass the flags to _wapi_send.
+ (ves_icall_System_Net_Sockets_Socket_SendTo_internal): Pass the flags to _wapi_sendto.
+
2006-01-31 Zoltan Varga <vargaz at gmail.com>
* icall.c (ves_icall_Type_GetInterfaceMapData): Make sure
Index: mono/metadata/socket-io.c
===================================================================
--- mono/metadata/socket-io.c (revision 56384)
+++ mono/metadata/socket-io.c (working copy)
@@ -1133,7 +1133,6 @@
int ret;
guchar *buf;
gint32 alen;
- int recvflags=0;
MONO_ARCH_SAVE_REGS;
@@ -1146,7 +1145,7 @@
buf=mono_array_addr(buffer, guchar, offset);
- ret = _wapi_recv (sock, buf, count, recvflags);
+ ret = _wapi_recv (sock, buf, count, flags);
if(ret==SOCKET_ERROR) {
*error = WSAGetLastError ();
return(0);
@@ -1160,7 +1159,6 @@
int ret;
guchar *buf;
gint32 alen;
- int recvflags=0;
struct sockaddr *sa;
int sa_size;
@@ -1180,7 +1178,7 @@
buf=mono_array_addr(buffer, guchar, offset);
- ret = _wapi_recvfrom (sock, buf, count, recvflags, sa, &sa_size);
+ ret = _wapi_recvfrom (sock, buf, count, flags, sa, &sa_size);
if(ret==SOCKET_ERROR) {
g_free(sa);
*error = WSAGetLastError ();
@@ -1206,7 +1204,6 @@
int ret;
guchar *buf;
gint32 alen;
- int sendflags=0;
MONO_ARCH_SAVE_REGS;
@@ -1227,7 +1224,7 @@
g_message(G_GNUC_PRETTY_FUNCTION ": Sending %d bytes", count);
#endif
- ret = _wapi_send (sock, buf, count, sendflags);
+ ret = _wapi_send (sock, buf, count, flags);
if(ret==SOCKET_ERROR) {
*error = WSAGetLastError ();
return(0);
@@ -1241,7 +1238,6 @@
int ret;
guchar *buf;
gint32 alen;
- int sendflags=0;
struct sockaddr *sa;
int sa_size;
@@ -1269,7 +1265,7 @@
g_message(G_GNUC_PRETTY_FUNCTION ": Sending %d bytes", count);
#endif
- ret = _wapi_sendto (sock, buf, count, sendflags, sa, sa_size);
+ ret = _wapi_sendto (sock, buf, count, flags, sa, sa_size);
if(ret==SOCKET_ERROR) {
*error = WSAGetLastError ();
}
Index: mono/io-layer/ChangeLog
===================================================================
--- mono/io-layer/ChangeLog (revision 56384)
+++ mono/io-layer/ChangeLog (working copy)
@@ -1,3 +1,11 @@
+2006-02-01 Ankit Jain <jankit at novell.com>
+
+ * sockets.c (wapi_flags_to_native_flags): New. Convert SocketFlags to
+ platform specific flags.
+ (_wapi_recvfrom): Use wapi_flags_to_native_flags to convert flags before
+ using them.
+ (_wapi_send): Likewise.
+
2006-01-03 Neale Ferguson <neale at sinenomine.net>
* atomic.h: Correct s390x definitions and eliminate compiler warnings.
Index: mono/io-layer/sockets.c
===================================================================
--- mono/io-layer/sockets.c (revision 56384)
+++ mono/io-layer/sockets.c (working copy)
@@ -34,6 +34,8 @@
#include <mono/io-layer/handles-private.h>
#include <mono/io-layer/socket-wrappers.h>
+#include <mono/metadata/socket-io.h>
+
#undef DEBUG
static guint32 startup_count=0;
@@ -41,6 +43,7 @@
static mono_once_t error_key_once=MONO_ONCE_INIT;
static void socket_close (gpointer handle, gpointer data);
+static int wapi_flags_to_native_flags (int flags);
struct _WapiHandleOps _wapi_socket_ops = {
socket_close, /* close */
@@ -481,6 +484,7 @@
{
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
+ int flags;
if (startup_count == 0) {
WSASetLastError (WSANOTINITIALISED);
@@ -491,9 +495,11 @@
WSASetLastError (WSAENOTSOCK);
return(SOCKET_ERROR);
}
-
+
+ flags = wapi_flags_to_native_flags (recv_flags);
+
do {
- ret = recvfrom (fd, buf, len, recv_flags, from, fromlen);
+ ret = recvfrom (fd, buf, len, flags, from, fromlen);
} while (ret == -1 && errno == EINTR &&
!_wapi_thread_cur_apc_pending ());
@@ -515,6 +521,7 @@
{
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
+ int flags;
if (startup_count == 0) {
WSASetLastError (WSANOTINITIALISED);
@@ -526,8 +533,9 @@
return(SOCKET_ERROR);
}
+ flags = wapi_flags_to_native_flags (send_flags);
do {
- ret = send (fd, msg, len, send_flags);
+ ret = send (fd, msg, len, flags);
} while (ret == -1 && errno == EINTR &&
!_wapi_thread_cur_apc_pending ());
@@ -550,6 +558,7 @@
{
gpointer handle = GUINT_TO_POINTER (fd);
int ret;
+ int flags;
if (startup_count == 0) {
WSASetLastError (WSANOTINITIALISED);
@@ -561,8 +570,9 @@
return(SOCKET_ERROR);
}
+ flags = wapi_flags_to_native_flags (send_flags);
do {
- ret = sendto (fd, msg, len, send_flags, to, tolen);
+ ret = sendto (fd, msg, len, flags, to, tolen);
} while (ret == -1 && errno == EINTR &&
!_wapi_thread_cur_apc_pending ());
@@ -859,6 +869,25 @@
return(0);
}
+int wapi_flags_to_native_flags (int flags)
+{
+ int ret = 0;
+ if (flags & SocketFlags_OutOfBand)
+ ret |= MSG_OOB;
+ if (flags & SocketFlags_Peek)
+ ret |= MSG_PEEK;
+ if (flags & SocketFlags_DontRoute)
+ ret |= MSG_DONTROUTE;
+#ifdef MSG_MORE
+ if (flags & SocketFlags_Partial)
+ ret |= MSG_MORE;
+#endif
+ /* FIXME: Don't know what to do for MaxIOVectorLength query
+ on linux. */
+
+ return ret;
+}
+
int _wapi_select(int nfds G_GNUC_UNUSED, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout)
{
More information about the Mono-devel-list
mailing list