Example #1
0
        static void TrampolineConfigureHandler(IntPtr block, IntPtr iface)
        {
            var del = BlockLiteral.GetTarget <Action <NWProtocolOptions> > (block);

            if (del != null)
            {
                using (var tempOptions = new NWProtocolOptions(iface, owns: false))
                    using (var definition = tempOptions.ProtocolDefinition) {
                        NWProtocolOptions?castedOptions = null;

                        if (definition.Equals(NWProtocolDefinition.TcpDefinition))
                        {
                            castedOptions = new NWProtocolTcpOptions(iface, owns: false);
                        }
                        else if (definition.Equals(NWProtocolDefinition.UdpDefinition))
                        {
                            castedOptions = new NWProtocolUdpOptions(iface, owns: false);
                        }
                        else if (definition.Equals(NWProtocolDefinition.TlsDefinition))
                        {
                            castedOptions = new NWProtocolTlsOptions(iface, owns: false);
                        }
                        else if (definition.Equals(NWProtocolDefinition.IPDefinition))
                        {
                            castedOptions = new NWProtocolIPOptions(iface, owns: false);
                        }
                        else if (definition.Equals(NWProtocolDefinition.WebSocketDefinition))
                        {
                            castedOptions = new NWWebSocketOptions(iface, owns: false);
                        }

                        try {
                            del(castedOptions ?? tempOptions);
                        } finally {
                            castedOptions?.Dispose();
                        }
                    }
            }
        }
        static void TrampolineIterateHandler(IntPtr block, IntPtr options)
        {
            var del = BlockLiteral.GetTarget <Action <NWProtocolOptions> > (block);

            if (del != null)
            {
                using (var tempOptions = new NWProtocolOptions(options, owns: false))
                    using (var definition = tempOptions.ProtocolDefinition) {
                        NWProtocolOptions?castedOptions = null;

                        if (definition.Equals(NWProtocolDefinition.CreateTcpDefinition()))
                        {
                            castedOptions = new NWProtocolTcpOptions(options, owns: false);
                        }
                        else if (definition.Equals(NWProtocolDefinition.CreateUdpDefinition()))
                        {
                            castedOptions = new NWProtocolUdpOptions(options, owns: false);
                        }
                        else if (definition.Equals(NWProtocolDefinition.CreateTlsDefinition()))
                        {
                            castedOptions = new NWProtocolTlsOptions(options, owns: false);
                        }
                        else if (definition.Equals(NWProtocolDefinition.CreateIPDefinition()))
                        {
                            castedOptions = new NWProtocolIPOptions(options, owns: false);
                        }
                        else if (definition.Equals(NWProtocolDefinition.CreateWebSocketDefinition()))
                        {
                            castedOptions = new NWWebSocketOptions(options, owns: false);
                        }

                        del(castedOptions ?? tempOptions);
                        castedOptions?.Dispose();
                    }
            }
        }