| ... | @@ -677,94 +677,6 @@ fn setSockFlags(sock: socket_t, flags: u32) !void { | ... | @@ -677,94 +677,6 @@ fn setSockFlags(sock: socket_t, flags: u32) !void { |
| 677 | } | 677 | } |
| 678 | } | 678 | } |
| 679 | | 679 | |
| 680 | pub const EpollCreateError = error{ | | |
| 681 | /// The per-user limit on the number of epoll instances imposed by | | |
| 682 | /// /proc/sys/fs/epoll/max_user_instances was encountered. See epoll(7) for further | | |
| 683 | /// details. | | |
| 684 | /// Or, The per-process limit on the number of open file descriptors has been reached. | | |
| 685 | ProcessFdQuotaExceeded, | | |
| 686 | | | |
| 687 | /// The system-wide limit on the total number of open files has been reached. | | |
| 688 | SystemFdQuotaExceeded, | | |
| 689 | | | |
| 690 | /// There was insufficient memory to create the kernel object. | | |
| 691 | SystemResources, | | |
| 692 | } || UnexpectedError; | | |
| 693 | | | |
| 694 | pub fn epoll_create1(flags: u32) EpollCreateError!i32 { | | |
| 695 | const rc = system.epoll_create1(flags); | | |
| 696 | switch (errno(rc)) { | | |
| 697 | .SUCCESS => return @intCast(rc), | | |
| 698 | else => |err| return unexpectedErrno(err), | | |
| 699 | | | |
| 700 | .INVAL => unreachable, | | |
| 701 | .MFILE => return error.ProcessFdQuotaExceeded, | | |
| 702 | .NFILE => return error.SystemFdQuotaExceeded, | | |
| 703 | .NOMEM => return error.SystemResources, | | |
| 704 | } | | |
| 705 | } | | |
| 706 | | | |
| 707 | pub const EpollCtlError = error{ | | |
| 708 | /// op was EPOLL_CTL_ADD, and the supplied file descriptor fd is already registered | | |
| 709 | /// with this epoll instance. | | |
| 710 | FileDescriptorAlreadyPresentInSet, | | |
| 711 | | | |
| 712 | /// fd refers to an epoll instance and this EPOLL_CTL_ADD operation would result in a | | |
| 713 | /// circular loop of epoll instances monitoring one another. | | |
| 714 | OperationCausesCircularLoop, | | |
| 715 | | | |
| 716 | /// op was EPOLL_CTL_MOD or EPOLL_CTL_DEL, and fd is not registered with this epoll | | |
| 717 | /// instance. | | |
| 718 | FileDescriptorNotRegistered, | | |
| 719 | | | |
| 720 | /// There was insufficient memory to handle the requested op control operation. | | |
| 721 | SystemResources, | | |
| 722 | | | |
| 723 | /// The limit imposed by /proc/sys/fs/epoll/max_user_watches was encountered while | | |
| 724 | /// trying to register (EPOLL_CTL_ADD) a new file descriptor on an epoll instance. | | |
| 725 | /// See epoll(7) for further details. | | |
| 726 | UserResourceLimitReached, | | |
| 727 | | | |
| 728 | /// The target file fd does not support epoll. This error can occur if fd refers to, | | |
| 729 | /// for example, a regular file or a directory. | | |
| 730 | FileDescriptorIncompatibleWithEpoll, | | |
| 731 | } || UnexpectedError; | | |
| 732 | | | |
| 733 | pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*system.epoll_event) EpollCtlError!void { | | |
| 734 | const rc = system.epoll_ctl(epfd, op, fd, event); | | |
| 735 | switch (errno(rc)) { | | |
| 736 | .SUCCESS => return, | | |
| 737 | else => |err| return unexpectedErrno(err), | | |
| 738 | | | |
| 739 | .BADF => unreachable, // always a race condition if this happens | | |
| 740 | .EXIST => return error.FileDescriptorAlreadyPresentInSet, | | |
| 741 | .INVAL => unreachable, | | |
| 742 | .LOOP => return error.OperationCausesCircularLoop, | | |
| 743 | .NOENT => return error.FileDescriptorNotRegistered, | | |
| 744 | .NOMEM => return error.SystemResources, | | |
| 745 | .NOSPC => return error.UserResourceLimitReached, | | |
| 746 | .PERM => return error.FileDescriptorIncompatibleWithEpoll, | | |
| 747 | } | | |
| 748 | } | | |
| 749 | | | |
| 750 | /// Waits for an I/O event on an epoll file descriptor. | | |
| 751 | /// Returns the number of file descriptors ready for the requested I/O, | | |
| 752 | /// or zero if no file descriptor became ready during the requested timeout milliseconds. | | |
| 753 | pub fn epoll_wait(epfd: i32, events: []system.epoll_event, timeout: i32) usize { | | |
| 754 | while (true) { | | |
| 755 | // TODO get rid of the @intCast | | |
| 756 | const rc = system.epoll_wait(epfd, events.ptr, @intCast(events.len), timeout); | | |
| 757 | switch (errno(rc)) { | | |
| 758 | .SUCCESS => return @intCast(rc), | | |
| 759 | .INTR => continue, | | |
| 760 | .BADF => unreachable, | | |
| 761 | .FAULT => unreachable, | | |
| 762 | .INVAL => unreachable, | | |
| 763 | else => unreachable, | | |
| 764 | } | | |
| 765 | } | | |
| 766 | } | | |
| 767 | | | |
| 768 | pub const EventFdError = error{ | 680 | pub const EventFdError = error{ |
| 769 | SystemResources, | 681 | SystemResources, |
| 770 | ProcessFdQuotaExceeded, | 682 | ProcessFdQuotaExceeded, |