Пример #1
0
        public void Process()
        {
            if (ListeningSocket == null)
            {
                return;
            }

            // New connection established successfully? Add it to OpenConnections
            if (AcceptTask != null && AcceptTask.IsCompleted)
            {
                if (AcceptTask.IsCompletedSuccessfully)
                {
                    var networkSocket     = AcceptTask.Result;
                    var newHttpConnection = new HttpConnectionStream(new NetworkStream(networkSocket), networkSocket);
                    newHttpConnection.MessageParsed += OnMessageParsed;
                    newHttpConnection.ReadAllMessagesAsync();
                    OpenConnections.Add(newHttpConnection);
                }

                AcceptTask.Dispose();
                AcceptTask = null;
            }
            if (AcceptTask == null)
            {
                AcceptTask = ListeningSocket.AcceptAsync();
            }

            var currentConnections = OpenConnections.ToArray();

            foreach (var connection in currentConnections)
            {
                if (!connection.CanRead)
                {
                    OpenConnections.Remove(connection);
                }
            }
        }
Пример #2
0
 public HttpClient(Stream customStream)
 {
     // If the given stream is a HttpConnectionStream set it as the connection, otherwise leave connection null;
     Connection = customStream as HttpConnectionStream;
     RawStream  = customStream;
 }
Пример #3
0
        public static async Task <HttpMessage> ParseMessage(HttpConnectionStream connection)
        {
            var parser = new HttpParser(connection);

            return(await parser.ParseMessageAsync());
        }
Пример #4
0
 public HttpClient(string hostName, int port = -1, HttpProtocol protocol = HttpProtocol.Auto)
 {
     Connection = HttpConnectionStream.ConnectToServer(hostName, port, protocol);
     RawStream  = Connection;
 }