jacksonh / manos

Manos is an easy to use, easy to test, high performance web application framework that stays out of your way and makes your life ridiculously simple.
Other
454 stars 61 forks source link

Socket Disconnect #106

Closed txdv closed 13 years ago

txdv commented 13 years ago

Is there a way to disconnect a Socket manually? I am porting smartirc4net to manos and I see that Close() disposes the socket alltogether.

ghost commented 13 years ago

In what way "disconnect manually"? Closing a socket, but keeping the Socket object in usable state does not make much sense.

txdv commented 13 years ago

Well, so I have to close it and create a new one then, right?

Could you explain, why it doesn't?

ghost commented 13 years ago

I don't think i fully understand your question. If you close a socket, it's closed. Gone. Useless. No matter by what means it was closed. What do you even mean by "disconnect manually"?

txdv commented 13 years ago

something like System.Net.Sockets.Socket::Disconnect(bool reuseSocket)

ghost commented 13 years ago

Ah, now I understand. No, there is currently no way to do that, and I don't think one will be added. The classes in Manos.IO are not intended to be very smart - one socket, one underlying kernel object. You could derive Manos.IO.Socket and emulate the reusable thing, of course.

txdv commented 13 years ago

Another question:

HttpServer takes Context and a Socket into it's constructor. Isn't it kinda redundant? When I think of wrapping an IrcConnection with these manos sockets, I would use only the Context so I could use it to recreate sockets on reconnect and stuff like that.

ghost commented 13 years ago

One could pass a listening port instead, that's correct. Perhaps that'll change in later versions. As for your second question, yes.

txdv commented 13 years ago

I'm writing a Socks4Socket class now, it would be possible to easily use it in HttpServer if the class actually would have a socket in their constructor.

But this leads to another problem, it is not possible to recreate a stream class only with an instance of an stream, which will be useful for socks5, or other prefixed packets.

ghost commented 13 years ago

You mean a wrapper stream? Of course that's possible, there's just no class that does it yet. Or am I misunderstanding?

txdv commented 13 years ago

Not by deriving, but by using an instance of another socket or stream.

ghost commented 13 years ago

I don't understand the problem you are having. If you want a stream that proxies calls to an (interchangeable) base stream, create one.

txdv commented 13 years ago

When I derive from Stream, I have to override WriteByteBuffer, I don't know how I am supposed to do that with just the instance of another Stream

namespace Manos.Awesomeness
{
    public class ProxyStream : Stream
    {
        public Stream Stream { get; set; }
        public ProxyStream(Stream stream)
        {
            Stream = stream;
        }

        public override void Close()
        {
            Stream.Close();
        }

        public override TimeSpan WriteTimeout {
            get {
                return Stream.WriteTimeout;
            }
            set {
                Stream.WriteTimeout = value;
            }
        }

        // Some other methods

        protected int WriteSingleBuffer(ByteBuffer buffer)
        {
        }
}
ghost commented 13 years ago

Throw some exception. Everything public should be forwarded to the underlying stream, everything nonpublic will then never be called.