/// <summary> /// Helper method to set up the socket when calling bind /// </summary> /// <param name="family">The address family to use</param> private void SetupSocket(UnixAddressFamily family) { if (m_socket != -1) { throw new InvalidOperationException("The socket is already initialized"); } // Create new socket m_socket = Syscall.socket(family, UnixSocketType.SOCK_STREAM, 0); // Allow address reuse Syscall.setsockopt(m_socket, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, 1); var opts = Syscall.fcntl(m_socket, FcntlCommand.F_GETFL); if (opts < 0) { throw new IOException($"Failed to get openflags from handle: {Stdlib.GetLastError()}"); } opts |= (int)OpenFlags.O_NONBLOCK; if (Syscall.fcntl(m_socket, FcntlCommand.F_SETFL, opts) < 0) { throw new IOException($"Failed to set socket O_NOBLOCK: {Stdlib.GetLastError()}"); } m_handle = m_handler.MonitoredHandle(m_socket); }
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(); } } }
public static Int32 FromUnixAddressFamily(UnixAddressFamily value) { Int32 rval; if (FromUnixAddressFamily(value, out rval) == -1) { ThrowArgumentException(value); } return(rval); }
/// <summary> /// Helper method to set up the socket when calling bind /// </summary> /// <param name="family">The address family to use</param> private void SetupSocket(UnixAddressFamily family) { if (m_socket != -1) { throw new InvalidOperationException("The socket is already initialized"); } // Create the socket m_socket = Syscall.socket(family, UnixSocketType.SOCK_STREAM, 0); // Allow address reuse Syscall.setsockopt(m_socket, UnixSocketProtocol.SOL_SOCKET, UnixSocketOptionName.SO_REUSEADDR, 1); }
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 (); } }
public static bool TryToUnixAddressFamily (Int32 value, out UnixAddressFamily rval) { return ToUnixAddressFamily (value, out rval) == 0; }
private static extern int ToUnixAddressFamily (Int32 value, out UnixAddressFamily rval);
public static Int32 FromUnixAddressFamily (UnixAddressFamily value) { Int32 rval; if (FromUnixAddressFamily (value, out rval) == -1) ThrowArgumentException (value); return rval; }
public static bool TryFromUnixAddressFamily (UnixAddressFamily value, out Int32 rval) { return FromUnixAddressFamily (value, out rval) == 0; }
private static extern int FromUnixAddressFamily (UnixAddressFamily value, out Int32 rval);
public static bool TryToUnixAddressFamily(Int32 value, out UnixAddressFamily rval) { return(ToUnixAddressFamily(value, out rval) == 0); }
private static extern int ToUnixAddressFamily(Int32 value, out UnixAddressFamily rval);
public static bool TryFromUnixAddressFamily(UnixAddressFamily value, out Int32 rval) { return(FromUnixAddressFamily(value, out rval) == 0); }
private static extern int FromUnixAddressFamily(UnixAddressFamily value, out Int32 rval);