+always_inline void
+ldp_select_init_maps (fd_set * __restrict original,
+ clib_bitmap_t ** resultb, clib_bitmap_t ** libcb,
+ clib_bitmap_t ** vclb, int nfds, u32 minbits,
+ u32 n_bytes, uword * si_bits, uword * libc_bits)
+{
+ uword si_bits_set, libc_bits_set;
+ vls_handle_t vlsh;
+ int fd;
+
+ clib_bitmap_validate (*vclb, minbits);
+ clib_bitmap_validate (*libcb, minbits);
+ clib_bitmap_validate (*resultb, minbits);
+ clib_memcpy_fast (*resultb, original, n_bytes);
+ memset (original, 0, n_bytes);
+
+ /* *INDENT-OFF* */
+ clib_bitmap_foreach (fd, *resultb, ({
+ if (fd > nfds)
+ break;
+ vlsh = ldp_fd_to_vlsh (fd);
+ if (vlsh == VLS_INVALID_HANDLE)
+ clib_bitmap_set_no_check (*libcb, fd, 1);
+ else
+ clib_bitmap_set_no_check (*vclb, vlsh_to_session_index (vlsh), 1);
+ }));
+ /* *INDENT-ON* */
+
+ si_bits_set = clib_bitmap_last_set (*vclb) + 1;
+ *si_bits = (si_bits_set > *si_bits) ? si_bits_set : *si_bits;
+
+ libc_bits_set = clib_bitmap_last_set (*libcb) + 1;
+ *libc_bits = (libc_bits_set > *libc_bits) ? libc_bits_set : *libc_bits;
+}
+
+always_inline int
+ldp_select_vcl_map_to_libc (clib_bitmap_t * vclb, fd_set * __restrict libcb)
+{
+ vls_handle_t vlsh;
+ uword si;
+ int fd;
+
+ if (!libcb)
+ return 0;
+
+ /* *INDENT-OFF* */
+ clib_bitmap_foreach (si, vclb, ({
+ vlsh = vls_session_index_to_vlsh (si);
+ ASSERT (vlsh != VLS_INVALID_HANDLE);
+ fd = ldp_vlsh_to_fd (vlsh);
+ if (PREDICT_FALSE (fd < 0))
+ {
+ errno = EBADFD;
+ return -1;
+ }
+ FD_SET (fd, libcb);
+ }));
+ /* *INDENT-ON* */
+
+ return 0;
+}
+
+always_inline void
+ldp_select_libc_map_merge (clib_bitmap_t * result, fd_set * __restrict libcb)
+{
+ uword fd;
+
+ if (!libcb)
+ return;
+
+ /* *INDENT-OFF* */
+ clib_bitmap_foreach (fd, result, ({
+ FD_SET ((int)fd, libcb);
+ }));
+ /* *INDENT-ON* */
+}
+