Exemplo n.º 1
0
        public void Start()
        {
            //			ioloop.AddHandler (Socket.Handle, HandleEvents, IOLoop.EPOLL_READ_EVENTS);

            iowatcher = new IOWatcher (Socket.Handle, EventTypes.Read, ioloop.EventLoop, HandleIOEvents);
            iowatcher.Start ();
        }
Exemplo n.º 2
0
        public override void Connect(string host, int port, Action callback)
        {
            if (state != Socket.SocketState.Invalid)
                throw new InvalidOperationException ("Socket already in use");

            int error;
            var fd = manos_socket_connect (host, port, out error);

            if (fd < 0)
                throw new Exception (String.Format ("An error occurred while trying to connect to {0}:{1} errno: {2}", host, port, error));

            stream = new PlainSocketStream (this, new IntPtr (fd));

            var connectWatcher = new IOWatcher (new IntPtr (fd), EventTypes.Write, Context.Loop, (watcher, revents) => {
                watcher.Stop ();
                watcher.Dispose ();

                this.address = host;
                this.port = port;

                this.state = Socket.SocketState.Open;

                callback ();
            });
            connectWatcher.Start ();
        }
Exemplo n.º 3
0
        private static void StaticCallback(IntPtr loop, IntPtr watcher, EventTypes revents)
        {
            UnmanagedIOWatcher iow = (UnmanagedIOWatcher)Marshal.PtrToStructure(watcher, typeof(UnmanagedIOWatcher));

            GCHandle  gchandle = GCHandle.FromIntPtr(iow.data);
            IOWatcher w        = (IOWatcher)gchandle.Target;

            w.callback(w.Loop, w, revents);
        }
Exemplo n.º 4
0
        protected EventedStream(Context context, IntPtr handle)
            : base(context)
        {
            if (handle == IntPtr.Zero)
                throw new ArgumentException ("handle");

            this.Handle = handle;

            this.readWatcher = new IOWatcher (Handle, EventTypes.Read, Context.Loop, HandleReadReady);
            this.writeWatcher = new IOWatcher (Handle, EventTypes.Write, Context.Loop, HandleWriteReady);
        }
Exemplo n.º 5
0
        public IOStream(Socket socket, IOLoop ioloop)
        {
            this.socket = socket;
            this.ioloop = ioloop;

            ReadChunkSize = DefaultReadChunkSize;

            socket.Blocking = false;

            read_watcher = new IOWatcher (socket.Handle, EventTypes.Read, ioloop.EventLoop, HandleIORead);
            write_watcher = new IOWatcher (socket.Handle, EventTypes.Write, ioloop.EventLoop, HandleIOWrite);
        }
Exemplo n.º 6
0
        protected EventedStream(IOLoop loop, IntPtr handle)
        {
            if (loop == null)
                throw new ArgumentNullException ("loop");
            if (handle == IntPtr.Zero)
                throw new ArgumentException ("handle");

            this.Loop = loop;
            this.Handle = handle;

            this.readWatcher = new IOWatcher (Handle, EventTypes.Read, Loop.EVLoop, HandleReadReady);
            this.writeWatcher = new IOWatcher (Handle, EventTypes.Write, Loop.EVLoop, HandleWriteReady);
        }
Exemplo n.º 7
0
        public IOStream(Socket socket, IOLoop ioloop)
        {
            this.socket = socket;
            this.ioloop = ioloop;

            TimeOut = TimeSpan.FromMinutes (2);
            Expires = DateTime.UtcNow + TimeOut;

            socket.Blocking = false;

            handle = IOWatcher.GetHandle (socket);
            read_watcher = new IOWatcher (handle, EventTypes.Read, ioloop.EventLoop, HandleIOReadEvent);
            write_watcher = new IOWatcher (handle, EventTypes.Write, ioloop.EventLoop, HandleIOWriteEvent);
        }
Exemplo n.º 8
0
        public override void Connect(string host, int port)
        {
            int error;
            fd = manos_socket_connect (host, port, out error);

            if (fd < 0)
                throw new Exception (String.Format ("An error occurred while trying to connect to {0}:{1} errno: {2}", host, port, error));

            IOWatcher iowatcher = new IOWatcher (new IntPtr (fd), EventTypes.Write, (LibEvLoop)IOLoop.EventLoop, (l, w, r) => {
                w.Stop ();

                this.host = host;
                this.port = port;
                OnConnected ();
            });
            iowatcher.Start ();
        }
Exemplo n.º 9
0
 public void Start()
 {
     iowatcher = new IOWatcher (Socket.Handle, EventTypes.Read, ioloop.EventLoop, HandleIOEvents);
     iowatcher.Start ();
 }
Exemplo n.º 10
0
        public void Listen( string host, int port )
        {
            int error;
            fd = manos_dgram_socket_listen( host, port, out error );

            if (fd < 0)
                throw new Exception (String.Format ("An error occurred while trying to connect to {0}:{1} errno: {2}", host, port, error));

            watcher = new IOWatcher( new IntPtr( fd ), EventTypes.Read, loop.EventLoop, (l, w, r) => onRead() );
            watcher.Start();
        }
Exemplo n.º 11
0
        public IOStream(Socket socket, IOLoop ioloop)
        {
            this.socket = socket;
            this.ioloop = ioloop;

            TimeOut = TimeSpan.FromMinutes (2);
            Expires = DateTime.UtcNow + TimeOut;

            ReadChunkSize = DefaultReadChunkSize;

            socket.Blocking = false;

            read_watcher = new IOWatcher (socket.Handle, EventTypes.Read, ioloop.EventLoop, HandleIORead);
            write_watcher = new IOWatcher (socket.Handle, EventTypes.Write, ioloop.EventLoop, HandleIOWrite);
        }
Exemplo n.º 12
0
        private void HandleIOWrite(Loop loop, IOWatcher watcher, int revents)
        {
            // write ready can still be raised after we are done writing.
            if (send_file == null && write_data == null)
               return;

            if (send_file != null) {
               HandleSendFile ();
               return;
            }

                        HandleWrite ();
        }
Exemplo n.º 13
0
 private void HandleIORead(Loop loop, IOWatcher watcher, int revents)
 {
     try {
         HandleRead ();
     } catch (Exception e) {
         Close ();
     }
 }
Exemplo n.º 14
0
        public override void Close()
        {
            base.Close ();
            if (Handle != IntPtr.Zero) {
                PauseReading ();
                PauseWriting ();

                readWatcher.Dispose ();
                writeWatcher.Dispose ();

                if (readTimeoutWatcher != null)
                    readTimeoutWatcher.Dispose ();
                if (writeTimeoutWatcher != null)
                    writeTimeoutWatcher.Dispose ();

                readWatcher = null;
                writeWatcher = null;
                readTimeoutWatcher = null;
                writeTimeoutWatcher = null;

                Handle = IntPtr.Zero;
            }
        }
Exemplo n.º 15
0
        private void HandleIOEvents(Loop loop, IOWatcher watcher, EventTypes revents)
        {
            while (true) {
                  	Socket s = null;
                try {
                    s = Socket.Accept ();
                } catch (SocketException se) {
                    if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain)
                        return;
                    throw se;
                } catch {
                    throw;
                }

                IOStream iostream = new IOStream (s, IOLoop);
                transactions.Add (HttpTransaction.BeginTransaction (this, iostream, s, callback));
            }
        }
Exemplo n.º 16
0
 void HandleReadReady(IOWatcher watcher, EventTypes revents)
 {
     if (readTimeoutContinuation == null) {
         readTimeoutContinuation = DateTime.Now;
     }
     HandleRead ();
 }
Exemplo n.º 17
0
        private void HandleIOReadEvent(Loop loop, IOWatcher watcher, EventTypes revents)
        {
            // Happens after a close
            if (socket == null)
                return;

            Expires = DateTime.UtcNow + TimeOut;
            HandleRead ();
        }
Exemplo n.º 18
0
 private void HandleIOWrite(Loop loop, IOWatcher watcher, int revents)
 {
     HandleWrite ();
 }
Exemplo n.º 19
0
 private void HandleIORead(Loop loop, IOWatcher watcher, int revents)
 {
     HandleRead ();
 }
Exemplo n.º 20
0
        public void Connect(string host, int port)
        {
            socket = CreateSocket ();
            socket.Connect (host, port);

            IntPtr handle = IOWatcher.GetHandle (socket);
            IOWatcher iowatcher = new IOWatcher (handle, EventTypes.Write, IOLoop.EventLoop, (l, w, r) => {
                w.Stop ();
                OnConnected ();
            });
            iowatcher.Start ();
        }
Exemplo n.º 21
0
        private void HandleIOEvents(Loop loop, IOWatcher watcher, EventTypes revents)
        {
            while (true) {
                  	Socket s = null;
                try {
                    s = Socket.Accept ();
                } catch (SocketException se) {
                    if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain)
                        return;
                    Console.WriteLine ("Socket exception in Accept handler");
                    Console.WriteLine (se);
                    return;
                } catch (Exception e) {
                    Console.WriteLine ("Exception in Accept handler");
                    Console.WriteLine (e);
                    return;
                }

                IOStream iostream = new IOStream (s, IOLoop);
                transactions.Add (HttpTransaction.BeginTransaction (this, iostream, s, callback));
            }
        }
Exemplo n.º 22
0
        public void SetHandle(IntPtr handle)
        {
            if (this.handle != IntPtr.Zero && this.handle != handle)
                Close ();

            this.handle = handle;
            read_watcher = new IOWatcher (handle, EventTypes.Read, ioloop.EventLoop, HandleIOReadEvent);
            write_watcher = new IOWatcher (handle, EventTypes.Write, ioloop.EventLoop, HandleIOWriteEvent);
            timeout_watcher = new TimerWatcher (TimeOut, TimeOut, ioloop.EventLoop, HandleTimeoutEvent);

            timeout_watcher.Start ();
        }
Exemplo n.º 23
0
 public void Start()
 {
     handle = IOWatcher.GetHandle (Socket);
     iowatcher = new IOWatcher (handle, EventTypes.Read, ioloop.EventLoop, HandleIOEvents);
     iowatcher.Start ();
 }
Exemplo n.º 24
0
        private void HandleIOWriteEvent(Loop loop, IOWatcher watcher, EventTypes revents)
        {
            // Happens after a close
            if (handle == IntPtr.Zero)
                return;

            Expires = DateTime.UtcNow + TimeOut;
            HandleWrite ();
        }
Exemplo n.º 25
0
        public virtual void Close()
        {
            if (handle == IntPtr.Zero)
                return;

            DisableReading ();
            DisableWriting ();

            read_watcher.Dispose ();
            write_watcher.Dispose ();
            timeout_watcher.Dispose ();

            read_watcher = null;
            write_watcher = null;
            timeout_watcher = null;
            handle = IntPtr.Zero;

            foreach (IWriteOperation op in write_ops) {
                op.Dispose ();
            }
            write_ops.Clear ();

            if (Closed != null)
                Closed (this, EventArgs.Empty);
            Closed = null;
            read_callback = null;
        }
Exemplo n.º 26
0
 void HandleWriteReady(IOWatcher watcher, EventTypes revents)
 {
     if (writeTimeoutContinuation == null) {
         writeTimeoutContinuation = DateTime.Now;
     }
     HandleWrite ();
 }