Pchp.Library.Streams.SocketStream.GetValid C# (CSharp) Method

GetValid() public static method

public static GetValid ( PhpResource handle ) : SocketStream
handle Pchp.Core.PhpResource
return SocketStream
        new public static SocketStream GetValid(PhpResource handle)
        {
            SocketStream result = handle as SocketStream;
            if (result == null)
                PhpException.Throw(PhpError.Warning, ErrResources.invalid_socket_stream_resource);
            return result;
        }
    }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Turns encryption on/off on an already connected socket
        /// </summary>
        /// <param name="stream">The stream resource.</param>
        /// <param name="enable">Enable/disable cryptography on the stream.</param>
        /// <returns>Returns TRUE on success, FALSE if negotiation has failed or 0 if there isn't enough data and you should try again (only for non-blocking sockets).</returns>
        public static PhpValue /*int|bool*/ stream_socket_enable_crypto(PhpResource stream, bool enable)
        {
            var s = SocketStream.GetValid(stream);

            if (s != null)
            {
                // obtain crypto_method option
                var crypto_method = default(CryptoMethod);

                if (enable)
                {
                    var ssl_options = s.Context.GetOptions("ssl");
                    if (ssl_options != null && ssl_options.TryGetValue("crypto_method", out var crypto_method_value))
                    {
                        crypto_method = (CryptoMethod)crypto_method_value.ToLong();
                    }
                    else
                    {
                        PhpException.InvalidArgument(nameof(crypto_method)); // 'crypto_method' must be specified when enabling encryption
                        return(false);
                    }
                }

                return(stream_socket_enable_crypto(s, enable, crypto_method, null));
            }

            //
            return(false);
        }
All Usage Examples Of Pchp.Library.Streams.SocketStream::GetValid