Differences From Artifact [6084d13774]:
- File
src/OFKernelEventObserver_select.m
— part of check-in
[a2738e1a3d]
at
2015-05-02 21:46:28
on branch trunk
— FD_SETSIZE is not (maximum FD number + 1) on Win32
Instead, FD_SETSIZE is the number of file descriptors supported by
select(), independent of the actual file descriptor number.The default value is 64, even though it seems that Win32 supports much
more than that. Thus, this is defined to 1024 on Win32 now. (user: js, size: 4209) [annotate] [blame] [check-ins using]
To Artifact [9c1fba606a]:
- File src/OFKernelEventObserver_select.m — part of check-in [bbe4040126] at 2015-05-04 20:34:57 on branch trunk — Refactor OFKernelEventObserver (user: js, size: 4806) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <sys/time.h> #import "OFKernelEventObserver.h" #import "OFKernelEventObserver+Private.h" #import "OFKernelEventObserver_select.h" #import "OFArray.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" #import "socket_helpers.h" @implementation OFKernelEventObserver_select - init { self = [super init]; FD_ZERO(&_readFDs); FD_ZERO(&_writeFDs); | > > > > > > > | > > | | > > > > > > > > | | > > > > > > > > > > | | > > > > | | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #include <sys/time.h> #import "OFKernelEventObserver.h" #import "OFKernelEventObserver+Private.h" #import "OFKernelEventObserver_select.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" #import "socket_helpers.h" @implementation OFKernelEventObserver_select - init { self = [super init]; #ifndef _WIN32 if (_cancelFD[0] >= FD_SETSIZE) @throw [OFInitializationFailedException exception]; #endif FD_ZERO(&_readFDs); FD_ZERO(&_writeFDs); FD_SET(_cancelFD[0], &_readFDs); _maxFD = _cancelFD[0]; return self; } - (void)OF_addObjectForReading: (id)object { int fd = [object fileDescriptorForReading]; if (fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef _WIN32 if (fd >= FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; FD_SET(fd, &_readFDs); } - (void)OF_addObjectForWriting: (id)object { int fd = [object fileDescriptorForWriting]; if (fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef _WIN32 if (fd >= FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; FD_SET(fd, &_writeFDs); } - (void)OF_removeObjectForReading: (id)object { /* TODO: Adjust _maxFD */ int fd = [object fileDescriptorForReading]; if (fd >= FD_SETSIZE) @throw [OFOutOfRangeException exception]; FD_CLR(fd, &_readFDs); } - (void)OF_removeObjectForWriting: (id)object { /* TODO: Adjust _maxFD */ int fd = [object fileDescriptorForWriting]; if (fd >= FD_SETSIZE) @throw [OFOutOfRangeException exception]; FD_CLR(fd, &_writeFDs); } - (bool)observeForTimeInterval: (of_time_interval_t)timeInterval |
︙ | ︙ | |||
124 125 126 127 128 129 130 | #ifndef _WIN32 timeout.tv_sec = (time_t)timeInterval; #else timeout.tv_sec = (long)timeInterval; #endif timeout.tv_usec = (int)lrint((timeInterval - timeout.tv_sec) * 1000); | | | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | #ifndef _WIN32 timeout.tv_sec = (time_t)timeInterval; #else timeout.tv_sec = (long)timeInterval; #endif timeout.tv_usec = (int)lrint((timeInterval - timeout.tv_sec) * 1000); events = select(_maxFD + 1, &readFDs, &writeFDs, NULL, (timeInterval != -1 ? &timeout : NULL)); if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; if (events == 0) |
︙ | ︙ |