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

GetValid() public static method

Checks the context for validity, throws a warning it is not.
In case the context is invalid.
public static GetValid ( PhpResource resource ) : StreamContext
resource Pchp.Core.PhpResource Resource which should contain a StreamContext.
return StreamContext
		public static StreamContext GetValid(PhpResource resource) => GetValid(resource, false);

Same methods

StreamContext::GetValid ( PhpResource resource, bool allowNull ) : StreamContext

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Open client socket.
        /// </summary>
        public static PhpResource stream_socket_server(Context ctx, string localSocket, out int errno, out string errstr, SocketOptions flags, PhpResource context)
        {
            // defaults:
            errno  = 0;
            errstr = string.Empty;

            var sc = StreamContext.GetValid(context);

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

            //
            int port = 0;

            if (TryParseSocketAddr(localSocket, out _, out var protocol, ref port, out var address))
            {
                try
                {
                    var socket = new Socket(address.AddressFamily, SocketType.Stream, protocol);
                    socket.Bind(new IPEndPoint(address, port));
                    //socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.MaxConnections) // Not Supported
                    socket.Listen(512); // NOTE: a default backlog should be used

                    return(new SocketStream(ctx, socket, localSocket, sc));
                }
                catch (SocketException e)
                {
                    errno  = e.ErrorCode;
                    errstr = e.Message;
                    return(null);
                }
            }
All Usage Examples Of Pchp.Library.Streams.StreamContext::GetValid