You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@@ -8,4 +8,5 @@ Mono.Unix/UnixSignalTest.cs
|
||||
Mono.Unix/UnixUserTest.cs
|
||||
Mono.Unix.Android/TestHelper.cs
|
||||
Mono.Unix.Native/RealTimeSignumTests.cs
|
||||
Mono.Unix.Native/SocketTest.cs
|
||||
Mono.Unix.Native/StdlibTest.cs
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* This file was automatically generated by create-native-map from ../../class/lib/net_2_0/Mono.Posix.dll.
|
||||
* This file was automatically generated by create-native-map from ./../../class/lib/net_4_x/Mono.Posix.dll.
|
||||
*
|
||||
* DO NOT MODIFY.
|
||||
*/
|
||||
@@ -342,6 +342,22 @@ namespace Mono.Unix.Native {
|
||||
return ToIovec (source, out destination) == 0;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromLinger")]
|
||||
private static extern int FromLinger (ref Linger source, IntPtr destination);
|
||||
|
||||
public static bool TryCopy (ref Linger source, IntPtr destination)
|
||||
{
|
||||
return FromLinger (ref source, destination) == 0;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_ToLinger")]
|
||||
private static extern int ToLinger (IntPtr source, out Linger destination);
|
||||
|
||||
public static bool TryCopy (IntPtr source, out Linger destination)
|
||||
{
|
||||
return ToLinger (source, out destination) == 0;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromLockType")]
|
||||
private static extern int FromLockType (LockType value, out Int16 rval);
|
||||
|
||||
@@ -406,6 +422,38 @@ namespace Mono.Unix.Native {
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromMessageFlags")]
|
||||
private static extern int FromMessageFlags (MessageFlags value, out Int32 rval);
|
||||
|
||||
public static bool TryFromMessageFlags (MessageFlags value, out Int32 rval)
|
||||
{
|
||||
return FromMessageFlags (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static Int32 FromMessageFlags (MessageFlags value)
|
||||
{
|
||||
Int32 rval;
|
||||
if (FromMessageFlags (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_ToMessageFlags")]
|
||||
private static extern int ToMessageFlags (Int32 value, out MessageFlags rval);
|
||||
|
||||
public static bool TryToMessageFlags (Int32 value, out MessageFlags rval)
|
||||
{
|
||||
return ToMessageFlags (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static MessageFlags ToMessageFlags (Int32 value)
|
||||
{
|
||||
MessageFlags rval;
|
||||
if (ToMessageFlags (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromMlockallFlags")]
|
||||
private static extern int FromMlockallFlags (MlockallFlags value, out Int32 rval);
|
||||
|
||||
@@ -806,6 +854,38 @@ namespace Mono.Unix.Native {
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromShutdownOption")]
|
||||
private static extern int FromShutdownOption (ShutdownOption value, out Int32 rval);
|
||||
|
||||
public static bool TryFromShutdownOption (ShutdownOption value, out Int32 rval)
|
||||
{
|
||||
return FromShutdownOption (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static Int32 FromShutdownOption (ShutdownOption value)
|
||||
{
|
||||
Int32 rval;
|
||||
if (FromShutdownOption (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_ToShutdownOption")]
|
||||
private static extern int ToShutdownOption (Int32 value, out ShutdownOption rval);
|
||||
|
||||
public static bool TryToShutdownOption (Int32 value, out ShutdownOption rval)
|
||||
{
|
||||
return ToShutdownOption (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static ShutdownOption ToShutdownOption (Int32 value)
|
||||
{
|
||||
ShutdownOption rval;
|
||||
if (ToShutdownOption (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromSignum")]
|
||||
private static extern int FromSignum (Signum value, out Int32 rval);
|
||||
|
||||
@@ -1014,6 +1094,166 @@ namespace Mono.Unix.Native {
|
||||
return ToTimezone (source, out destination) == 0;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromUnixAddressFamily")]
|
||||
private static extern int FromUnixAddressFamily (UnixAddressFamily value, out Int32 rval);
|
||||
|
||||
public static bool TryFromUnixAddressFamily (UnixAddressFamily value, out Int32 rval)
|
||||
{
|
||||
return FromUnixAddressFamily (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static Int32 FromUnixAddressFamily (UnixAddressFamily value)
|
||||
{
|
||||
Int32 rval;
|
||||
if (FromUnixAddressFamily (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_ToUnixAddressFamily")]
|
||||
private static extern int ToUnixAddressFamily (Int32 value, out UnixAddressFamily rval);
|
||||
|
||||
public static bool TryToUnixAddressFamily (Int32 value, out UnixAddressFamily rval)
|
||||
{
|
||||
return ToUnixAddressFamily (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static UnixAddressFamily ToUnixAddressFamily (Int32 value)
|
||||
{
|
||||
UnixAddressFamily rval;
|
||||
if (ToUnixAddressFamily (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromUnixSocketFlags")]
|
||||
private static extern int FromUnixSocketFlags (UnixSocketFlags value, out Int32 rval);
|
||||
|
||||
public static bool TryFromUnixSocketFlags (UnixSocketFlags value, out Int32 rval)
|
||||
{
|
||||
return FromUnixSocketFlags (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static Int32 FromUnixSocketFlags (UnixSocketFlags value)
|
||||
{
|
||||
Int32 rval;
|
||||
if (FromUnixSocketFlags (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_ToUnixSocketFlags")]
|
||||
private static extern int ToUnixSocketFlags (Int32 value, out UnixSocketFlags rval);
|
||||
|
||||
public static bool TryToUnixSocketFlags (Int32 value, out UnixSocketFlags rval)
|
||||
{
|
||||
return ToUnixSocketFlags (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static UnixSocketFlags ToUnixSocketFlags (Int32 value)
|
||||
{
|
||||
UnixSocketFlags rval;
|
||||
if (ToUnixSocketFlags (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromUnixSocketOptionName")]
|
||||
private static extern int FromUnixSocketOptionName (UnixSocketOptionName value, out Int32 rval);
|
||||
|
||||
public static bool TryFromUnixSocketOptionName (UnixSocketOptionName value, out Int32 rval)
|
||||
{
|
||||
return FromUnixSocketOptionName (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static Int32 FromUnixSocketOptionName (UnixSocketOptionName value)
|
||||
{
|
||||
Int32 rval;
|
||||
if (FromUnixSocketOptionName (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_ToUnixSocketOptionName")]
|
||||
private static extern int ToUnixSocketOptionName (Int32 value, out UnixSocketOptionName rval);
|
||||
|
||||
public static bool TryToUnixSocketOptionName (Int32 value, out UnixSocketOptionName rval)
|
||||
{
|
||||
return ToUnixSocketOptionName (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static UnixSocketOptionName ToUnixSocketOptionName (Int32 value)
|
||||
{
|
||||
UnixSocketOptionName rval;
|
||||
if (ToUnixSocketOptionName (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromUnixSocketProtocol")]
|
||||
private static extern int FromUnixSocketProtocol (UnixSocketProtocol value, out Int32 rval);
|
||||
|
||||
public static bool TryFromUnixSocketProtocol (UnixSocketProtocol value, out Int32 rval)
|
||||
{
|
||||
return FromUnixSocketProtocol (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static Int32 FromUnixSocketProtocol (UnixSocketProtocol value)
|
||||
{
|
||||
Int32 rval;
|
||||
if (FromUnixSocketProtocol (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_ToUnixSocketProtocol")]
|
||||
private static extern int ToUnixSocketProtocol (Int32 value, out UnixSocketProtocol rval);
|
||||
|
||||
public static bool TryToUnixSocketProtocol (Int32 value, out UnixSocketProtocol rval)
|
||||
{
|
||||
return ToUnixSocketProtocol (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static UnixSocketProtocol ToUnixSocketProtocol (Int32 value)
|
||||
{
|
||||
UnixSocketProtocol rval;
|
||||
if (ToUnixSocketProtocol (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromUnixSocketType")]
|
||||
private static extern int FromUnixSocketType (UnixSocketType value, out Int32 rval);
|
||||
|
||||
public static bool TryFromUnixSocketType (UnixSocketType value, out Int32 rval)
|
||||
{
|
||||
return FromUnixSocketType (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static Int32 FromUnixSocketType (UnixSocketType value)
|
||||
{
|
||||
Int32 rval;
|
||||
if (FromUnixSocketType (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_ToUnixSocketType")]
|
||||
private static extern int ToUnixSocketType (Int32 value, out UnixSocketType rval);
|
||||
|
||||
public static bool TryToUnixSocketType (Int32 value, out UnixSocketType rval)
|
||||
{
|
||||
return ToUnixSocketType (value, out rval) == 0;
|
||||
}
|
||||
|
||||
public static UnixSocketType ToUnixSocketType (Int32 value)
|
||||
{
|
||||
UnixSocketType rval;
|
||||
if (ToUnixSocketType (value, out rval) == -1)
|
||||
ThrowArgumentException (value);
|
||||
return rval;
|
||||
}
|
||||
|
||||
[DllImport (LIB, EntryPoint="Mono_Posix_FromUtimbuf")]
|
||||
private static extern int FromUtimbuf (ref Utimbuf source, IntPtr destination);
|
||||
|
||||
|
@@ -381,6 +381,42 @@ namespace Mono.Unix.Native {
|
||||
internal const string LIBC = "msvcrt";
|
||||
internal const string MPH = "MonoPosixHelper";
|
||||
|
||||
// It is possible for Mono.Posix and MonoPosixHelper to get out of sync,
|
||||
// for example if NuGet does something weird. To mitigate this, anyone
|
||||
// editing Mono.Posix needs to observe two rules:
|
||||
// 1. When introducing C-interface changes to MonoPosixHelper, update
|
||||
// the version strings in VersionCheck below and also
|
||||
// Mono_Unix_VersionString in the C sources.
|
||||
// 2. Any class which performs a DllImport on Stdlib.MPH needs to call
|
||||
// Stdlib.VersionCheck in its static constructor.
|
||||
|
||||
[DllImport (Stdlib.MPH, CallingConvention=CallingConvention.Cdecl,
|
||||
EntryPoint="Mono_Unix_VersionString")]
|
||||
private static extern IntPtr VersionStringPtr ();
|
||||
private static bool versionCheckPerformed = false;
|
||||
internal static void VersionCheck ()
|
||||
{
|
||||
if (versionCheckPerformed)
|
||||
return;
|
||||
|
||||
// This string is arbitrary; it matters only that it is unique.
|
||||
string assemblyVersion = "MonoProject-2015-12-1";
|
||||
string nativeVersion = Marshal.PtrToStringAnsi (VersionStringPtr ());
|
||||
if (assemblyVersion != nativeVersion)
|
||||
{
|
||||
throw new Exception ("Mono.Posix assembly loaded with a different version (\""
|
||||
+ assemblyVersion + "\") than MonoPosixHelper (\"" + nativeVersion
|
||||
+ "\"). You may need to reinstall Mono.Posix.");
|
||||
}
|
||||
|
||||
versionCheckPerformed = true;
|
||||
}
|
||||
|
||||
static Stdlib ()
|
||||
{
|
||||
VersionCheck ();
|
||||
}
|
||||
|
||||
internal Stdlib () {}
|
||||
|
||||
#region <errno.h> Declarations
|
||||
|
@@ -1 +1 @@
|
||||
c4ff89c0573826bf5b1b77b8f98053f071e0b0d8
|
||||
4125978df0c8371b3c21d2a86e7e00364e2f7e54
|
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// UnixListener.cs
|
||||
// UnixClient.cs
|
||||
//
|
||||
// Authors:
|
||||
// Joe Shaw (joeshaw@novell.com)
|
||||
|
@@ -39,6 +39,11 @@ namespace Mono.Unix {
|
||||
private int signum;
|
||||
private IntPtr signal_info;
|
||||
|
||||
static UnixSignal ()
|
||||
{
|
||||
Stdlib.VersionCheck ();
|
||||
}
|
||||
|
||||
public UnixSignal (Signum signum)
|
||||
{
|
||||
this.signum = NativeConvert.FromSignum (signum);
|
||||
@@ -145,10 +150,12 @@ namespace Mono.Unix {
|
||||
set {Interlocked.Exchange (ref Info->count, value);}
|
||||
}
|
||||
|
||||
// signum, count, write_fd, pipecnt, and pipelock are read from a signal handler thread
|
||||
// count and pipelock are both read and written from the signal handler thread
|
||||
[Map]
|
||||
struct SignalInfo {
|
||||
public int signum, count, read_fd, write_fd, have_handler, pipecnt;
|
||||
public IntPtr handler;
|
||||
public int signum, count, read_fd, write_fd, pipecnt, pipelock, have_handler;
|
||||
public IntPtr handler; // Backed-up handler to restore when signal unregistered
|
||||
}
|
||||
|
||||
#region WaitHandle overrides
|
||||
|
223
mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs
Normal file
223
mcs/class/Mono.Posix/Test/Mono.Unix.Native/SocketTest.cs
Normal file
@@ -0,0 +1,223 @@
|
||||
//
|
||||
// socket-related test cases
|
||||
//
|
||||
// Authors:
|
||||
// Steffen Kiess (s-kiess@web.de)
|
||||
//
|
||||
// Copyright (C) 2015 Steffen Kiess
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using Mono.Unix;
|
||||
using Mono.Unix.Native;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MonoTests.Mono.Unix.Native
|
||||
{
|
||||
[TestFixture, Category ("NotDotNet")]
|
||||
public class SocketTest {
|
||||
|
||||
string TempFolder;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp ()
|
||||
{
|
||||
TempFolder = Path.Combine (Path.GetTempPath (), this.GetType ().FullName);
|
||||
|
||||
if (Directory.Exists (TempFolder))
|
||||
Directory.Delete (TempFolder, true);
|
||||
|
||||
Directory.CreateDirectory (TempFolder);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
if (Directory.Exists (TempFolder))
|
||||
Directory.Delete (TempFolder, true);
|
||||
}
|
||||
|
||||
// Set a timeout on all sockets to make sure that if a test fails it
|
||||
// won't cause the program to hang
|
||||
void SetTimeout (int socket)
|
||||
{
|
||||
var timeout = new Timeval {
|
||||
tv_sec = 0,
|
||||
tv_usec = 500000,
|
||||
};
|
||||
if (Syscall.setsockopt (socket, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_RCVTIMEO, timeout) < 0 ||
|
||||
Syscall.setsockopt (socket, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_SNDTIMEO, timeout) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
}
|
||||
|
||||
void WithSocketPair (Action<int, int> f)
|
||||
{
|
||||
int socket1, socket2;
|
||||
if (Syscall.socketpair (UnixAddressFamily.AF_UNIX, UnixSocketType.SOCK_STREAM, 0, out socket1, out socket2) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
try {
|
||||
SetTimeout (socket1);
|
||||
SetTimeout (socket2);
|
||||
|
||||
f (socket1, socket2);
|
||||
} finally {
|
||||
int r0 = Syscall.close (socket1);
|
||||
int r1 = Syscall.close (socket2);
|
||||
if (r0 < 0 || r1 < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
}
|
||||
}
|
||||
|
||||
void WithSockets (UnixAddressFamily af, UnixSocketType type, UnixSocketProtocol protocol, Action<int, int> f)
|
||||
{
|
||||
int so1, so2;
|
||||
if ((so1 = Syscall.socket (af, type, protocol)) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
try {
|
||||
if ((so2 = Syscall.socket (af, type, protocol)) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
try {
|
||||
SetTimeout (so1);
|
||||
SetTimeout (so2);
|
||||
|
||||
f (so1, so2);
|
||||
} finally {
|
||||
if (Syscall.close (so2) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
}
|
||||
} finally {
|
||||
if (Syscall.close (so1) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Socket ()
|
||||
{
|
||||
int socket;
|
||||
if ((socket = Syscall.socket (UnixAddressFamily.AF_UNIX, UnixSocketType.SOCK_STREAM, 0)) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
|
||||
if (Syscall.close (socket) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SocketPair ()
|
||||
{
|
||||
int socket1, socket2;
|
||||
if (Syscall.socketpair (UnixAddressFamily.AF_UNIX, UnixSocketType.SOCK_STREAM, 0, out socket1, out socket2) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
|
||||
int r0 = Syscall.close (socket1);
|
||||
int r1 = Syscall.close (socket2);
|
||||
if (r0 < 0 || r1 < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendRecv ()
|
||||
{
|
||||
WithSocketPair ((so1, so2) => {
|
||||
long ret;
|
||||
var buffer1 = new byte[] { 42, 43, 44 };
|
||||
ret = Syscall.send (so1, buffer1, (ulong) buffer1.Length, 0);
|
||||
if (ret < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
|
||||
var buffer2 = new byte[1024];
|
||||
ret = Syscall.recv (so2, buffer2, (ulong) buffer2.Length, 0);
|
||||
if (ret < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
|
||||
Assert.AreEqual (buffer1.Length, ret);
|
||||
for (int i = 0; i < buffer1.Length; i++)
|
||||
Assert.AreEqual (buffer1[i], buffer2[i]);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SockOpt ()
|
||||
{
|
||||
WithSockets (UnixAddressFamily.AF_UNIX, UnixSocketType.SOCK_STREAM, 0, (so1, so2) => {
|
||||
int value;
|
||||
if (Syscall.getsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, out value) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
Assert.AreEqual (0, value);
|
||||
|
||||
// Set SO_REUSEADDR to 1
|
||||
if (Syscall.setsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, 1) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
|
||||
// Get and check SO_REUSEADDR
|
||||
if (Syscall.getsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, out value) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
Assert.AreNotEqual (0, value);
|
||||
|
||||
// Set SO_REUSEADDR to 0
|
||||
if (Syscall.setsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, new byte[10], 4) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
|
||||
// Get and check SO_REUSEADDR
|
||||
var buffer = new byte[15];
|
||||
long size = 12;
|
||||
if (Syscall.getsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, buffer, ref size) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
Assert.AreEqual (size, 4);
|
||||
for (int i = 0; i < size; i++)
|
||||
Assert.AreEqual (buffer[i], 0);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SockOptLinger ()
|
||||
{
|
||||
WithSockets (UnixAddressFamily.AF_INET, UnixSocketType.SOCK_STREAM, UnixSocketProtocol.IPPROTO_TCP, (so1, so2) => {
|
||||
Linger linger = new Linger {
|
||||
l_onoff = 1,
|
||||
l_linger = 42,
|
||||
};
|
||||
// Set SO_LINGER
|
||||
if (Syscall.setsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_LINGER, linger) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
|
||||
// Get and check SO_LINGER
|
||||
Linger value;
|
||||
if (Syscall.getsockopt (so1, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_LINGER, out value) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
if (value.l_onoff == 0)
|
||||
Assert.Fail ("Linger not enabled");
|
||||
Assert.AreEqual (linger.l_linger, value.l_linger);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Shutdown ()
|
||||
{
|
||||
WithSocketPair ((so1, so2) => {
|
||||
if (Syscall.shutdown (so1, ShutdownOption.SHUT_WR) < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
|
||||
var buffer2 = new byte[1024];
|
||||
long ret = Syscall.recv (so2, buffer2, (ulong) buffer2.Length, 0);
|
||||
if (ret < 0)
|
||||
UnixMarshal.ThrowExceptionForLastError ();
|
||||
|
||||
Assert.AreEqual (ret, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vim: noexpandtab
|
||||
// Local Variables:
|
||||
// tab-width: 4
|
||||
// c-basic-offset: 4
|
||||
// indent-tabs-mode: t
|
||||
// End:
|
@@ -456,6 +456,7 @@ namespace MonoTests.Mono.Unix {
|
||||
s.Close ();
|
||||
}
|
||||
|
||||
// Create thread that issues many signals from a set of harmless signals
|
||||
static Thread CreateRaiseStormThread (int max)
|
||||
{
|
||||
return new Thread (delegate () {
|
||||
@@ -486,6 +487,7 @@ namespace MonoTests.Mono.Unix {
|
||||
CloseSignals (usignals);
|
||||
}
|
||||
|
||||
// Create thread that repeatedly registers then unregisters signal handlers
|
||||
static Thread CreateSignalCreatorThread ()
|
||||
{
|
||||
return new Thread (delegate () {
|
||||
@@ -523,6 +525,7 @@ namespace MonoTests.Mono.Unix {
|
||||
CloseSignals (usignals);
|
||||
}
|
||||
|
||||
// Create thread that blocks until at least one of the given signals is received
|
||||
static Thread CreateWaitAnyThread (params UnixSignal[] usignals)
|
||||
{
|
||||
return new Thread (delegate () {
|
||||
|
Reference in New Issue
Block a user