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); }
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; }
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); }
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); }
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); } }
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); }
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); }
private static extern int ToEpollEvents(UInt32 value, out EpollEvents rval);
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); }
private static int ToEpollEvents(UInt32 value, out EpollEvents rval) { throw new System.NotImplementedException(); }
private static extern int ToEpollEvents (UInt32 value, out EpollEvents rval);
private static extern int FromEpollEvents (EpollEvents value, out UInt32 rval);
private static int FromEpollEvents (EpollEvents value, out UInt32 rval) { throw new System.NotImplementedException(); }
public void AddHandler(IntPtr fd, IOHandler handler, EpollEvents events) { handlers [fd] = handler; Register (fd, events | EPOLL_ERROR_EVENTS); }
private void RunHandler(IntPtr fd, EpollEvents events) { handlers [fd] (fd, events); }
private void Register(IntPtr fd, EpollEvents events) { Syscall.epoll_ctl (epfd, EpollOp.EPOLL_CTL_ADD, fd, events); }
private void Modify(IntPtr fd, EpollEvents events) { Syscall.epoll_ctl (epfd, EpollOp.EPOLL_CTL_MOD, fd, events); }
public void UpdateHandler(IntPtr fd, EpollEvents events) { Modify (fd, events | EPOLL_ERROR_EVENTS); }
public static bool TryToEpollEvents(UInt32 value, out EpollEvents rval) { return(ToEpollEvents(value, out rval) == 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(); }
public static bool TryFromEpollEvents (EpollEvents value, out UInt32 rval) { return FromEpollEvents (value, out rval) == 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; }
public static bool TryToEpollEvents (UInt32 value, out EpollEvents rval) { return ToEpollEvents (value, out rval) == 0; }
private void HandleEvents(IntPtr fd, EpollEvents events) { }
private static int FromEpollEvents(EpollEvents value, out UInt32 rval) { throw new System.NotImplementedException(); }
private static extern int FromEpollEvents(EpollEvents value, out UInt32 rval);
public static bool TryFromEpollEvents(EpollEvents value, out UInt32 rval) { return(FromEpollEvents(value, out rval) == 0); }
private void AddIOState(EpollEvents events) { if ((state & events) != 0) return; ioloop.UpdateHandler (socket.Handle, events); }