| 27 | // based off winsock2.h: https://gist.github.com/piscisaureus/906386#file-winsock2-h-L128-L141 |
| 28 | |
| 29 | pub unsafe fn FD_SET(fd: RawFd, set: *mut fd_set) { |
| 30 | unsafe { |
| 31 | let mut slot = (&raw mut (*set).fd_array).cast::<RawFd>(); |
| 32 | let fd_count = (*set).fd_count; |
| 33 | for _ in 0..fd_count { |
| 34 | if *slot == fd { |
| 35 | return; |
| 36 | } |
| 37 | slot = slot.add(1); |
| 38 | } |
| 39 | // slot == &fd_array[fd_count] at this point |
| 40 | if fd_count < FD_SETSIZE { |
| 41 | *slot = fd as RawFd; |
| 42 | (*set).fd_count += 1; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | pub unsafe fn FD_ZERO(set: *mut fd_set) { |
| 48 | unsafe { (*set).fd_count = 0 }; |