Ruby  3.4.0dev (2024-11-22 revision 0989400a925cd201defdca9eb28eb87200b30785)
win32.h
Go to the documentation of this file.
1 #ifndef RBIMPL_INTERN_SELECT_WIN32_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_INTERN_SELECT_WIN32_H
23 #include "ruby/internal/dosish.h" /* for rb_w32_select */
28 #include "ruby/assert.h"
29 
31 #define rb_fd_zero rb_fd_zero
32 #define rb_fd_clr rb_fd_clr
33 #define rb_fd_isset rb_fd_isset
34 #define rb_fd_copy rb_fd_copy
35 #define rb_fd_dup rb_fd_dup
36 #define rb_fd_ptr rb_fd_ptr
37 #define rb_fd_max rb_fd_max
41 
42 struct timeval;
43 
49 typedef struct {
50  int capa;
51  fd_set *fdset;
52 } rb_fdset_t;
53 
67 
78 
87 void rb_fd_set(int fd, rb_fdset_t *f);
88 
98 void rb_w32_fd_copy(rb_fdset_t *dst, const fd_set *src, int max);
99 
109 void rb_w32_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src);
110 
112 
121 static inline void
123 {
124  f->fdset->fd_count = 0;
125 }
126 
135 static inline void
137 {
138  rb_w32_fdclr(n, f->fdset);
139 }
140 
150 static inline int
152 {
153  return rb_w32_fdisset(n, f->fdset);
154 }
155 
165 static inline void
166 rb_fd_copy(rb_fdset_t *dst, const fd_set *src, int n)
167 {
168  rb_w32_fd_copy(dst, src, n);
169 }
170 
180 static inline void
181 rb_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src)
182 {
183  rb_w32_fd_dup(dst, src);
184 }
185 
211 static inline int
212 rb_fd_select(int n, rb_fdset_t *rfds, rb_fdset_t *wfds, rb_fdset_t *efds, struct timeval *timeout)
213 {
214  return rb_w32_select(
215  n,
216  rfds ? rfds->fdset : NULL,
217  wfds ? wfds->fdset : NULL,
218  efds ? efds->fdset : NULL,
219  timeout);
220 }
221 
236 static inline fd_set *
238 {
239  return f->fdset;
240 }
241 
250 static inline int
252 {
253  const fd_set *p = f->fdset;
254 
256  return RBIMPL_CAST((int)p->fd_count);
257 }
258 
259 #endif /* RBIMPL_INTERN_SELECT_WIN32_H */
#define RBIMPL_ASSERT_OR_ASSUME(...)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition: assert.h:311
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:65
Support for so-called dosish systems.
RBIMPL_ATTR_PURE() int rb_io_read_pending(rb_io_t *fptr)
Queries if the passed IO has any pending reads.
void rb_fd_set(int fd, rb_fdset_t *f)
Sets an fd to a fdset.
static int rb_fd_isset(int n, rb_fdset_t *f)
Queries if the given FD is in the given set.
Definition: win32.h:151
static int rb_fd_max(const rb_fdset_t *f)
It seems this function has no use.
Definition: win32.h:251
static fd_set * rb_fd_ptr(const rb_fdset_t *f)
Raw pointer to fd_set.
Definition: win32.h:237
void rb_w32_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src)
Identical to rb_w32_fd_copy(), except it copies unlimited number of file descriptors.
Definition: win32.c:3000
static void rb_fd_zero(rb_fdset_t *f)
Wipes out the current set of FDs.
Definition: win32.h:122
static void rb_fd_clr(int n, rb_fdset_t *f)
Releases a specific FD from the given fdset.
Definition: win32.h:136
void rb_fd_init(rb_fdset_t *f)
(Re-)initialises a fdset.
void rb_w32_fd_copy(rb_fdset_t *dst, const fd_set *src, int max)
Destructively overwrites an fdset with another.
Definition: win32.c:2985
static void rb_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src)
Identical to rb_fd_copy(), except it copies unlimited number of file descriptors.
Definition: win32.h:181
void rb_fd_term(rb_fdset_t *f)
Destroys the rb_fdset_t, releasing any memory and resources it used.
static int rb_fd_select(int n, rb_fdset_t *rfds, rb_fdset_t *wfds, rb_fdset_t *efds, struct timeval *timeout)
Waits for multiple file descriptors at once.
Definition: win32.h:212
static void rb_fd_copy(rb_fdset_t *dst, const fd_set *src, int n)
Destructively overwrites an fdset with another.
Definition: win32.h:166
Defines RBIMPL_ATTR_NOALIAS.
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
Definition: noalias.h:62
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
fd_set rb_fdset_t
The data structure which wraps the fd_set bitmap used by select(2).
Definition: posix.h:48
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition: defines.h:88
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition: pure.h:38
The data structure which wraps the fd_set bitmap used by select(2).
Definition: largesize.h:71
fd_set * fdset
File descriptors buffer.
Definition: largesize.h:73
int capa
Maximum allowed number of FDs.
Definition: win32.h:50