Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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();
                }
            }
        }
Exemplo n.º 3
0
        public static Int32 FromUnixAddressFamily(UnixAddressFamily value)
        {
            Int32 rval;

            if (FromUnixAddressFamily(value, out rval) == -1)
            {
                ThrowArgumentException(value);
            }
            return(rval);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
		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 ();
			}
		}
Exemplo n.º 6
0
		public static bool TryToUnixAddressFamily (Int32 value, out UnixAddressFamily rval)
		{
			return ToUnixAddressFamily (value, out rval) == 0;
		}
Exemplo n.º 7
0
		private static extern int ToUnixAddressFamily (Int32 value, out UnixAddressFamily rval);
Exemplo n.º 8
0
		public static Int32 FromUnixAddressFamily (UnixAddressFamily value)
		{
			Int32 rval;
			if (FromUnixAddressFamily (value, out rval) == -1)
				ThrowArgumentException (value);
			return rval;
		}
Exemplo n.º 9
0
		public static bool TryFromUnixAddressFamily (UnixAddressFamily value, out Int32 rval)
		{
			return FromUnixAddressFamily (value, out rval) == 0;
		}
Exemplo n.º 10
0
		private static extern int FromUnixAddressFamily (UnixAddressFamily value, out Int32 rval);
Exemplo n.º 11
0
 public static bool TryToUnixAddressFamily(Int32 value, out UnixAddressFamily rval)
 {
     return(ToUnixAddressFamily(value, out rval) == 0);
 }
Exemplo n.º 12
0
 private static extern int ToUnixAddressFamily(Int32 value, out UnixAddressFamily rval);
Exemplo n.º 13
0
 public static bool TryFromUnixAddressFamily(UnixAddressFamily value, out Int32 rval)
 {
     return(FromUnixAddressFamily(value, out rval) == 0);
 }
Exemplo n.º 14
0
 private static extern int FromUnixAddressFamily(UnixAddressFamily value, out Int32 rval);