Skip to content

Commit

Permalink
* socket-io.h (MonoSocketFlags): New. Copy of System.Net.Sockets.Sock…
Browse files Browse the repository at this point in the history
…etFlags

* socket-io.c (convert_socketflags): New. Convert SocketFlags to native ones.
(ves_icall_System_Net_Sockets_Socket_Receive_internal): Convert flags using convert_socketflags.
(ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal): Likewise.
(ves_icall_System_Net_Sockets_Socket_Send_internal): Likewise.
(ves_icall_System_Net_Sockets_Socket_SendTo_internal): Likewise.

svn path=/trunk/mono/; revision=56608


Commit migrated from mono/mono@4699ca6
  • Loading branch information
radical committed Feb 7, 2006
1 parent 9eeab28 commit 5b621d6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/mono/mono/metadata/socket-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,39 @@ static gint32 convert_proto(MonoProtocolType mono_proto)
return(proto);
}

/* Convert MonoSocketFlags */
static gint32 convert_socketflags (gint32 sflags)
{
gint32 flags = 0;

if (!sflags)
/* SocketFlags.None */
return 0;

if (sflags & ~(SocketFlags_OutOfBand | SocketFlags_MaxIOVectorLength | SocketFlags_Peek |
SocketFlags_DontRoute | SocketFlags_Partial))
/* Contains invalid flag values */
return -1;

if (sflags & SocketFlags_OutOfBand)
flags |= MSG_OOB;
if (sflags & SocketFlags_Peek)
flags |= MSG_PEEK;
if (sflags & SocketFlags_DontRoute)
flags |= MSG_DONTROUTE;
if (sflags & SocketFlags_Partial)
#ifdef MSG_MORE
flags |= MSG_MORE;
#else
return -1;
#endif
if (sflags & SocketFlags_MaxIOVectorLength)
/* FIXME: Don't know what to do for MaxIOVectorLength query */
return -1;

return (flags ? flags : -1);
}

static gint32 convert_sockopt_level_and_name(MonoSocketOptionLevel mono_level,
MonoSocketOptionName mono_name,
int *system_level,
Expand Down Expand Up @@ -1146,6 +1179,12 @@ gint32 ves_icall_System_Net_Sockets_Socket_Receive_internal(SOCKET sock, MonoArr

buf=mono_array_addr(buffer, guchar, offset);

recvflags = convert_socketflags (flags);
if (recvflags == -1) {
*error = WSAEOPNOTSUPP;
return (0);
}

ret = _wapi_recv (sock, buf, count, recvflags);
if(ret==SOCKET_ERROR) {
*error = WSAGetLastError ();
Expand Down Expand Up @@ -1180,6 +1219,12 @@ gint32 ves_icall_System_Net_Sockets_Socket_RecvFrom_internal(SOCKET sock, MonoAr

buf=mono_array_addr(buffer, guchar, offset);

recvflags = convert_socketflags (flags);
if (recvflags == -1) {
*error = WSAEOPNOTSUPP;
return (0);
}

ret = _wapi_recvfrom (sock, buf, count, recvflags, sa, &sa_size);
if(ret==SOCKET_ERROR) {
g_free(sa);
Expand Down Expand Up @@ -1227,6 +1272,12 @@ gint32 ves_icall_System_Net_Sockets_Socket_Send_internal(SOCKET sock, MonoArray
g_message(G_GNUC_PRETTY_FUNCTION ": Sending %d bytes", count);
#endif

sendflags = convert_socketflags (flags);
if (sendflags == -1) {
*error = WSAEOPNOTSUPP;
return (0);
}

ret = _wapi_send (sock, buf, count, sendflags);
if(ret==SOCKET_ERROR) {
*error = WSAGetLastError ();
Expand Down Expand Up @@ -1269,6 +1320,12 @@ gint32 ves_icall_System_Net_Sockets_Socket_SendTo_internal(SOCKET sock, MonoArra
g_message(G_GNUC_PRETTY_FUNCTION ": Sending %d bytes", count);
#endif

sendflags = convert_socketflags (flags);
if (sendflags == -1) {
*error = WSAEOPNOTSUPP;
return (0);
}

ret = _wapi_sendto (sock, buf, count, sendflags, sa, sa_size);
if(ret==SOCKET_ERROR) {
*error = WSAGetLastError ();
Expand Down
10 changes: 10 additions & 0 deletions src/mono/mono/metadata/socket-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ typedef enum {
SocketOptionName_PeerCred=10001
} MonoSocketOptionName;

/* This is a copy of System.Net.Sockets.SocketFlags */
typedef enum {
SocketFlags_None = 0x0000,
SocketFlags_OutOfBand = 0x0001,
SocketFlags_MaxIOVectorLength = 0x0010,
SocketFlags_Peek = 0x0002,
SocketFlags_DontRoute = 0x0004,
SocketFlags_Partial = 0x8000
} MonoSocketFlags;

typedef struct _MonoSocketAsyncResult {
MonoObject obj;
MonoObject *socket;
Expand Down

0 comments on commit 5b621d6

Please sign in to comment.