GetValid() публичный статический Метод

public static GetValid ( PhpResource handle ) : SocketStream
handle Pchp.Core.PhpResource
Результат SocketStream
Пример #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);
        }
Пример #2
0
        public static int stream_socket_sendto(PhpResource socket, string data, SendReceiveOptions flags = SendReceiveOptions.None, string address = null)
        {
            SocketStream stream = SocketStream.GetValid(socket);

            if (stream == null)
            {
                return(-1);
            }

            PhpException.FunctionNotSupported("stream_socket_sendto");
            return(-1);
        }
Пример #3
0
        /// <summary>
        /// Accepts a connection on a server socket.
        /// </summary>
        public static bool stream_socket_accept(PhpResource serverSocket, int timeout, out string peerName)
        {
            peerName = "";

            SocketStream stream = SocketStream.GetValid(serverSocket);

            if (stream == null)
            {
                return(false);
            }

            PhpException.FunctionNotSupported("stream_socket_accept");
            return(false);
        }
Пример #4
0
        public static string stream_socket_recvfrom(PhpResource socket, int length, SendReceiveOptions flags,
                                                    out string address)
        {
            address = null;

            SocketStream stream = SocketStream.GetValid(socket);

            if (stream == null)
            {
                return(null);
            }

            PhpException.FunctionNotSupported("stream_socket_recvfrom");
            return(null);
        }
Пример #5
0
        public const int STREAM_SHUT_RDWR = (int)SocketShutdown.Both;    // 2;

        /// <summary>
        /// Shutdown a full-duplex connection.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="how">One of the following constants:
        /// - STREAM_SHUT_RD (disable further receptions)<br />
        /// - STREAM_SHUT_WR (disable further transmissions)<br />
        /// - STREAM_SHUT_RDWR (disable further receptions and transmissions).<br/>
        /// </param>
        /// <returns></returns>
        public static bool stream_socket_shutdown(PhpResource stream, SocketShutdown how)
        {
            var s = SocketStream.GetValid(stream);

            if (s != null)
            {
                try
                {
                    s.Socket.Shutdown(how);
                }
                catch (SocketException ex)
                {
                    PhpException.Throw(PhpError.Warning, ex.Message);
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Пример #6
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>
        /// <param name="crypto_method">Encryption on the stream. If omitted, the <c>crypto_method</c> context option on the stream's SSL context will be used instead.</param>
        /// <param name="session_stream">Seed the stream with settings from session_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, CryptoMethod crypto_method = default, PhpResource session_stream = null)
        {
            var s = SocketStream.GetValid(stream);

            if (s == null)
            {
                return(false);
            }

            if (enable && s.SslStream == null)
            {
                s.SslStream = OpenSslStream(s.Socket, s.OpenedPath /*=RemoteHost*/, crypto_method);
                return(s.SslStream != null);
            }
            else if (!enable && s.SslStream != null)
            {
                s.CloseSslStream();
                return(true);
            }

            //
            return(false);
        }