Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Ceen.Httpd.Cli.UnixSpawn.SpawnedServer"/> class.
        /// </summary>
        /// <param name="usessl">If set to <c>true</c> usessl.</param>
        /// <param name="configfile">Configfile.</param>
        /// <param name="storage">Storage.</param>
        public SpawnedServer(bool usessl, string configfile, IStorageCreator storage)
        {
            var config = ConfigParser.ValidateConfig(ConfigParser.ParseTextFile(configfile));

            config.Storage = storage ?? new MemoryStorageCreator();

            try
            {
                m_pollhandler = new SockRock.KqueueHandler();
            }
            catch (Exception e1)
            {
                try
                {
                    m_pollhandler = new SockRock.EpollHandler();
                }
                catch (Exception e2)
                {
                    throw new PlatformNotSupportedException("Unable to create kqueue or epoll instance", new AggregateException(e1, e2));
                }
            }

            m_pollhandler.WaitForShutdownAsync.ContinueWith(x => {
                Program.ConsoleOutput("The poll handler crashed, stopping this instance");
                this.Stop(TimeSpan.FromSeconds(-5));
            }, TaskContinuationOptions.NotOnRanToCompletion);

            base.Setup(usessl, config);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Ceen.Httpd.Cli.UnixSpawn.SpawnedServer"/> class.
        /// </summary>
        /// <param name="usessl">If set to <c>true</c> usessl.</param>
        /// <param name="configfile">Configfile.</param>
        /// <param name="storage">Storage.</param>
        public SpawnedServer(bool usessl, string configfile, IStorageCreator storage)
        {
            //// Mono version
            //var safeSocketHandleType = Type.GetType("System.Net.Sockets.SafeSocketHandle");
            //var safeSocketHandleConstructor = safeSocketHandleType?.GetConstructor(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic, null, new Type[] { typeof(IntPtr), typeof(bool) }, null);
            //var socketConstructorSafeSocketHandle = safeSocketHandleType == null ? null : typeof(System.Net.Sockets.Socket).GetConstructor(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic, null, new Type[] { typeof(AddressFamily), typeof(SocketType), typeof(ProtocolType), safeSocketHandleType }, null);

            //// .Net Core version
            //var safeCloseSocketType = Type.GetType("System.Net.Sockets.SafeCloseSocket");
            //var safeCloseSocketConstructor = safeCloseSocketType?.GetMethod("CreateSocket", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, null, new Type[] { typeof(IntPtr) }, null);
            //var socketConstructorSafeCloseSocket = safeCloseSocketType == null ? null : typeof(System.Net.Sockets.Socket).GetConstructor(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic, null, new Type[] { safeCloseSocketType }, null);

            //if (safeSocketHandleConstructor != null && socketConstructorSafeSocketHandle != null)
            //    m_createSocket = (handle) => (Socket)Activator.CreateInstance(typeof(Socket), AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, Activator.CreateInstance(safeSocketHandleType, new IntPtr(handle), false));
            //else if (safeCloseSocketConstructor != null && socketConstructorSafeCloseSocket != null)
            //    m_createSocket = (handle) => (Socket)Activator.CreateInstance(typeof(Socket), safeCloseSocketConstructor.Invoke(null, new object[] { new IntPtr(handle) }));
            //else
            //throw new Exception("Unable to find a method to create sockets from handles ....");

            var config = ConfigParser.ValidateConfig(ConfigParser.ParseTextFile(configfile));

            config.Storage = storage ?? new MemoryStorageCreator();

            try
            {
                m_pollhandler = new SockRock.KqueueHandler();
            }
            catch (Exception e1)
            {
                try
                {
                    m_pollhandler = new SockRock.EpollHandler();
                }
                catch (Exception e2)
                {
                    throw new PlatformNotSupportedException("Unable to create kqueue or epoll instance", new AggregateException(e1, e2));
                }
            }

            base.Setup(usessl, config);
        }