jgauffin / griffin.networking

Networking library for .NET
http://blog.gauffin.org/2012/05/griffin-networking-a-somewhat-performant-networking-library-for-net/
GNU Lesser General Public License v3.0
108 stars 35 forks source link

Pipeline and streams #8

Closed dr4cul4 closed 11 years ago

dr4cul4 commented 11 years ago

There is a problem with streams and pipelines.

They seam to work on small amount of data, but when you try to use images or something larger output get's mess up. (html is mixed with images and css/js). As it turns out it's related to using same connection by browsers and reading output at the same time.

Also when you switch to keep alive false in response you get more errors (Close message not supported, easy fix), after that i got null reference (socket was null ServerClientContext.cs:218), those two fixes solves my problem partially... now the response is cutoff and I get half of an image, part of js and css. If I find a fix I will post it here. I will also try to solve connection sharing problem.

jgauffin commented 11 years ago

hmmm. I must have screwed something up with my later fixes. For this I've tried quite extensivly in the past. HTTP/1.1 (reusing the connection) is the prefered way to do it since it speeds up the handling

dr4cul4 commented 11 years ago

I have a clue... header parser is messed up. First of all header names are weird for example doing second request I post to "http://127.0.0.1:8283/?module=task&option=list&session=a805183b-af0e-41d5-bf0e-d6e45e3e5be5" But http message has "http://127.0.0.1:8283/?resource=js/bundle.js", Which is last js in my html file.

First Header Name: "GET /?module=task&option=list&session=a805183b-af0e-41d5-bf0e-d6e45e3e5be5 HTTP/1.1 Host" First Header Value: "127.0.0.1:8283"

Those values are strange.

Now I also find something curious. If I have many resources on a page I only get the last one to output (not at first request... at first request i get all things but cutoff)

jgauffin commented 11 years ago

The problem is most likely that Reset() doesn't set the _parserMethod to FirstLine

dr4cul4 commented 11 years ago

I'll test this at home. What about stream cutoff? I thinking it has something to do with async handling.

jgauffin commented 11 years ago

It's probably related. The HeaderParser should take care of headers and leave the body bytes intact. But since the header parsing gets out of sync it will probably effect the body handling too.

dr4cul4 commented 11 years ago

If it desn't work I'll post sample project reproducing the problem.

dr4cul4 commented 11 years ago

I modified reset method like this and use it inside HeaderDecoder with parameter set to true:

        public void Reset(bool first = false)
        {
            _headerName.Clear();
            _headerValue.Clear();
            if (first)
                _parserMethod = FirstLine;
            else
                _parserMethod = Name_StripWhiteSpacesBefore;
        }

This solved initial problem.

Now my only concern is keep alive set to false. Connection should be closed after data is send. Currently this happens in the middle of the transfer.

dr4cul4 commented 11 years ago

I've discovered one more thing.

When page redirects itself it tends to hang one socket... random one. (usually second, but that's not a rule). I'm trying to figure that out. Only thing I can tell now it's that socket is open and listening and browser is reading from it. Browser claims that it send request but there is no data in the web server. When I his stop in browser sockets finishes read with zero bytes. I happens on all browsers.

Also browsing using links and ajax requests works well. At least after hour of clicking.

jgauffin commented 11 years ago

should work with the next commit