Пример #1
0
        private bool RemoveSocket(int handle, EpollEvents e)
        {
            int res;
            bool
                isWrite = _onWriteSockets.ContainsKey(handle),
                isRead  = _onReadSockets.ContainsKey(handle);

            Contract.Assert(!((e & ReadEvent) == ReadEvent && !isRead),
                            "removing read from list, although already not added");
            Contract.Assert(!((e & WriteEvent) == WriteEvent && !isWrite),
                            "removing write from list, although already not added");

            if (isWrite && (e & ReadEvent) == ReadEvent ||
                isRead && (e & WriteEvent) == WriteEvent)
            {
                EpollEvents inv = ((e & ReadEvent) == ReadEvent)
                                      ? WriteEvent
                                      : ReadEvent;

                res = _epoll.Edit(handle, inv);
            }
            else
            {
                res = _epoll.Delete(handle);
            }

            if (res == (int)Errno.EINTR)
            {
                return(RemoveSocket(handle, e));
            }

            return(true);
        }
 public static UInt32 FromEpollEvents(EpollEvents value)
 {
     UInt32 rval;
     if (FromEpollEvents (value, out rval) == -1)
         ThrowArgumentException (value);
     return rval;
 }
        public static UInt32 FromEpollEvents(EpollEvents value)
        {
            UInt32 rval;

            if (FromEpollEvents(value, out rval) == -1)
            {
                ThrowArgumentException(value);
            }
            return(rval);
        }
Пример #4
0
        internal int Add(int handle, EpollEvents events)
        {
            if (_epoll == 0)
            {
                throw new InvalidOperationException("Epoll has already been closed");
            }

            int res = Syscall.epoll_ctl(_epoll, EpollOp.EPOLL_CTL_ADD, handle, events);
            return res;
        }
Пример #5
0
        internal int Add(int handle, EpollEvents events)
        {
            if (_epoll == 0)
            {
                throw new InvalidOperationException("Epoll has already been closed");
            }

            int res = Syscall.epoll_ctl(_epoll, EpollOp.EPOLL_CTL_ADD, handle, events);

            return(res);
        }
Пример #6
0
        public IOStream(Socket socket, IOLoop ioloop)
        {
            this.socket = socket;
            this.ioloop = ioloop;

            ReadChunkSize = DefaultReadChunkSize;

            socket.Blocking = false;

            state = IOLoop.EPOLL_ERROR_EVENTS;
            ioloop.AddHandler (socket.Handle, HandleEvents, state);
        }
Пример #7
0
        private void HandleEvents(IntPtr fd, EpollEvents events)
        {
            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);
                HttpTransaction.BeginTransaction (this, iostream, s, callback);
            }
        }
Пример #8
0
        public bool Update(int fd, EpollEvents flags)
        {
            var ev = new EpollEvent()
            {
                events = flags,
                u32    = (uint)fd
            };

            Log.Epoll("[{0}] EPOLL_CTL_MOD({1})", fd, flags);
            var r = Syscall.epoll_ctl(epfd, EpollOp.EPOLL_CTL_MOD, fd, ref ev);

            if (r != 0)
            {
                Log.Error($"Call to epoll_ctl(MOD) failed with code {r}: {Stdlib.GetLastError()}");
                return(false);
            }
            return(true);
        }
Пример #9
0
        private bool AddSocket(int handle, EpollEvents e)
        {
            bool
                isWrite = _onWriteSockets.ContainsKey(handle),
                isRead  = _onReadSockets.ContainsKey(handle);

            Contract.Assert(!((e & ReadEvent) == ReadEvent && isRead),
                            "adding to read list, although already added");
            Contract.Assert(!((e & WriteEvent) == WriteEvent && isWrite),
                            "adding to write list, although already added");

            if (isWrite && (e & ReadEvent) == ReadEvent ||
                isRead && (e & WriteEvent) == WriteEvent)
            {
                _epoll.Edit(handle, ReadEvent | WriteEvent);
            }
            else
            {
                _epoll.Add(handle, e);
            }

            return(true);
        }
Пример #10
0
 private static extern int ToEpollEvents(UInt32 value, out EpollEvents rval);
Пример #11
0
        private void HandleEvents(IntPtr fd, EpollEvents events)
        {
            if (IsClosed) {
                Console.Error.WriteLine ("events on closed socket.");
                return;
            }

            if (fd != socket.Handle)
                throw new Exception ("Incorrectly routed event.");

            if ((events & IOLoop.EPOLL_READ_EVENTS) != 0)
                HandleRead ();

            if (IsClosed)
                return;

            if ((events & IOLoop.EPOLL_WRITE_EVENTS) != 0) {
                if (send_file == null)
                    HandleWrite ();
                else
                    HandleSendFile ();
            }

            if (IsClosed)
                return;

            EpollEvents state = IOLoop.EPOLL_ERROR_EVENTS;
            if (read_delimiter != null || read_bytes != -1)
                state |= IOLoop.EPOLL_READ_EVENTS;
            if (write_data != null)
                state |= IOLoop.EPOLL_WRITE_EVENTS;

            if (state != this.state)
                ioloop.UpdateHandler (socket.Handle, state);
        }
Пример #12
0
 private static int ToEpollEvents(UInt32 value, out EpollEvents rval)
 {
     throw new System.NotImplementedException();
 }
Пример #13
0
		private static extern int ToEpollEvents (UInt32 value, out EpollEvents rval);
Пример #14
0
		private static extern int FromEpollEvents (EpollEvents value, out UInt32 rval);
		private static int FromEpollEvents (EpollEvents value, out UInt32 rval)
		{
			throw new System.NotImplementedException();
		}
Пример #16
0
 public void AddHandler(IntPtr fd, IOHandler handler, EpollEvents events)
 {
     handlers [fd] = handler;
     Register (fd, events | EPOLL_ERROR_EVENTS);
 }
Пример #17
0
 private void RunHandler(IntPtr fd, EpollEvents events)
 {
     handlers [fd] (fd, events);
 }
Пример #18
0
 private void Register(IntPtr fd, EpollEvents events)
 {
     Syscall.epoll_ctl (epfd, EpollOp.EPOLL_CTL_ADD, fd, events);
 }
Пример #19
0
 private void Modify(IntPtr fd, EpollEvents events)
 {
     Syscall.epoll_ctl (epfd, EpollOp.EPOLL_CTL_MOD, fd, events);
 }
Пример #20
0
 public void UpdateHandler(IntPtr fd, EpollEvents events)
 {
     Modify (fd, events | EPOLL_ERROR_EVENTS);
 }
Пример #21
0
 public static bool TryToEpollEvents(UInt32 value, out EpollEvents rval)
 {
     return(ToEpollEvents(value, out rval) == 0);
 }
Пример #22
0
        private bool RemoveSocket(int handle, EpollEvents e)
        {
            int res;
            bool
                isWrite = _onWriteSockets.ContainsKey(handle),
                isRead = _onReadSockets.ContainsKey(handle);

            Contract.Assert(!((e & ReadEvent) == ReadEvent && !isRead),
                            "removing read from list, although already not added");
            Contract.Assert(!((e & WriteEvent) == WriteEvent && !isWrite),
                            "removing write from list, although already not added");

            if (isWrite && (e & ReadEvent) == ReadEvent ||
                isRead && (e & WriteEvent) == WriteEvent)
            {
                EpollEvents inv = ((e & ReadEvent) == ReadEvent)
                                      ? WriteEvent
                                      : ReadEvent;

                res = _epoll.Edit(handle, inv);
            }
            else
            {
                res = _epoll.Delete(handle);
            }

            if (res == (int) Errno.EINTR)
            {
                return RemoveSocket(handle, e);
            }

            return true;
        }
		private static int ToEpollEvents (UInt32 value, out EpollEvents rval)
		{
			throw new System.NotImplementedException();
		}
Пример #24
0
		public static bool TryFromEpollEvents (EpollEvents value, out UInt32 rval)
		{
			return FromEpollEvents (value, out rval) == 0;
		}
Пример #25
0
        private bool AddSocket(int handle, EpollEvents e)
        {
            bool
                isWrite = _onWriteSockets.ContainsKey(handle),
                isRead = _onReadSockets.ContainsKey(handle);

            Contract.Assert(!((e & ReadEvent) == ReadEvent && isRead),
                            "adding to read list, although already added");
            Contract.Assert(!((e & WriteEvent) == WriteEvent && isWrite),
                            "adding to write list, although already added");

            if (isWrite && (e & ReadEvent) == ReadEvent ||
                isRead && (e & WriteEvent) == WriteEvent)
            {
                _epoll.Edit(handle, ReadEvent | WriteEvent);
            }
            else
            {
                _epoll.Add(handle, e);
            }

            return true;
        }
Пример #26
0
		public static bool TryToEpollEvents (UInt32 value, out EpollEvents rval)
		{
			return ToEpollEvents (value, out rval) == 0;
		}
Пример #27
0
 private void HandleEvents(IntPtr fd, EpollEvents events)
 {
 }
Пример #28
0
 private static int FromEpollEvents(EpollEvents value, out UInt32 rval)
 {
     throw new System.NotImplementedException();
 }
Пример #29
0
 private static extern int FromEpollEvents(EpollEvents value, out UInt32 rval);
Пример #30
0
 public static bool TryFromEpollEvents(EpollEvents value, out UInt32 rval)
 {
     return(FromEpollEvents(value, out rval) == 0);
 }
Пример #31
0
 private void AddIOState(EpollEvents events)
 {
     if ((state & events) != 0)
         return;
     ioloop.UpdateHandler (socket.Handle, events);
 }