exit (1);
}
- watch = _dbus_watch_new (reload_pipe[RELOAD_READ_END],
- DBUS_WATCH_READABLE, TRUE,
- handle_reload_watch, NULL, NULL);
+ watch = _dbus_watch_new (DBUS_SOCKET_GET_POLLABLE (reload_pipe[RELOAD_READ_END]),
+ DBUS_WATCH_READABLE, TRUE,
+ handle_reload_watch, NULL, NULL);
if (watch == NULL)
{
char *key,
void *value);
+#ifdef DBUS_WIN
+# define DBUS_HASH_POLLABLE DBUS_HASH_UINTPTR
+#else
+# define DBUS_HASH_POLLABLE DBUS_HASH_INT
+#endif
+
+static inline DBusPollable
+_dbus_hash_iter_get_pollable_key (DBusHashIter *iter)
+{
+#ifdef DBUS_WIN
+ return _dbus_hash_iter_get_uintptr_key (iter);
+#else
+ return _dbus_hash_iter_get_int_key (iter);
+#endif
+}
+
+static inline void *
+_dbus_hash_table_lookup_pollable (DBusHashTable *table,
+ DBusPollable key)
+{
+#ifdef DBUS_WIN
+ return _dbus_hash_table_lookup_uintptr (table, key);
+#else
+ return _dbus_hash_table_lookup_int (table, key);
+#endif
+}
+
+static inline dbus_bool_t
+_dbus_hash_table_remove_pollable (DBusHashTable *table,
+ DBusPollable key)
+{
+#ifdef DBUS_WIN
+ return _dbus_hash_table_remove_uintptr (table, key);
+#else
+ return _dbus_hash_table_remove_int (table, key);
+#endif
+}
+
+static inline dbus_bool_t
+_dbus_hash_table_insert_pollable (DBusHashTable *table,
+ DBusPollable key,
+ void *value)
+{
+#ifdef DBUS_WIN
+ return _dbus_hash_table_insert_uintptr (table, key, value);
+#else
+ return _dbus_hash_table_insert_int (table, key, value);
+#endif
+}
+
/** @} */
DBUS_END_DECLS
struct DBusLoop
{
int refcount;
- /** fd => dbus_malloc'd DBusList ** of references to DBusWatch */
+ /** DBusPollable => dbus_malloc'd DBusList ** of references to DBusWatch */
DBusHashTable *watches;
DBusSocketSet *socket_set;
DBusList *timeouts;
if (loop == NULL)
return NULL;
- loop->watches = _dbus_hash_table_new (DBUS_HASH_INT, NULL,
+ loop->watches = _dbus_hash_table_new (DBUS_HASH_POLLABLE, NULL,
free_watch_table_entry);
loop->socket_set = _dbus_socket_set_new (0);
}
static DBusList **
-ensure_watch_table_entry (DBusLoop *loop,
- int fd)
+ensure_watch_table_entry (DBusLoop *loop,
+ DBusPollable fd)
{
DBusList **watches;
- watches = _dbus_hash_table_lookup_int (loop->watches, fd);
+ watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
if (watches == NULL)
{
if (watches == NULL)
return watches;
- if (!_dbus_hash_table_insert_int (loop->watches, fd, watches))
+ if (!_dbus_hash_table_insert_pollable (loop->watches, fd, watches))
{
dbus_free (watches);
watches = NULL;
}
static void
-cull_watches_for_invalid_fd (DBusLoop *loop,
- int fd)
+cull_watches_for_invalid_fd (DBusLoop *loop,
+ DBusPollable fd)
{
DBusList *link;
DBusList **watches;
- _dbus_warn ("invalid request, socket fd %d not open\n", fd);
- watches = _dbus_hash_table_lookup_int (loop->watches, fd);
+ _dbus_warn ("invalid request, socket fd %" DBUS_POLLABLE_FORMAT " not open\n",
+ DBUS_POLLABLE_PRINTABLE (fd));
+ watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
if (watches != NULL)
{
_dbus_watch_invalidate (link->data);
}
- _dbus_hash_table_remove_int (loop->watches, fd);
+ _dbus_hash_table_remove_pollable (loop->watches, fd);
}
static dbus_bool_t
-gc_watch_table_entry (DBusLoop *loop,
- DBusList **watches,
- int fd)
+gc_watch_table_entry (DBusLoop *loop,
+ DBusList **watches,
+ DBusPollable fd)
{
/* If watches is already NULL we have nothing to do */
if (watches == NULL)
if (*watches != NULL)
return FALSE;
- _dbus_hash_table_remove_int (loop->watches, fd);
+ _dbus_hash_table_remove_pollable (loop->watches, fd);
return TRUE;
}
static void
-refresh_watches_for_fd (DBusLoop *loop,
- DBusList **watches,
- int fd)
+refresh_watches_for_fd (DBusLoop *loop,
+ DBusList **watches,
+ DBusPollable fd)
{
DBusList *link;
unsigned int flags = 0;
dbus_bool_t interested = FALSE;
- _dbus_assert (fd != -1);
+ _dbus_assert (DBUS_POLLABLE_IS_VALID (fd));
if (watches == NULL)
- watches = _dbus_hash_table_lookup_int (loop->watches, fd);
+ watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
/* we allocated this in the first _dbus_loop_add_watch for the fd, and keep
* it until there are none left */
_dbus_loop_add_watch (DBusLoop *loop,
DBusWatch *watch)
{
- DBusSocket fd;
+ DBusPollable fd;
DBusList **watches;
- fd = _dbus_watch_get_socket (watch);
- _dbus_assert (fd != DBUS_SOCKET_INVALID);
+ fd = _dbus_watch_get_pollable (watch);
+ _dbus_assert (DBUS_POLLABLE_IS_VALID (fd));
watches = ensure_watch_table_entry (loop, fd);
dbus_watch_get_flags (watch),
dbus_watch_get_enabled (watch)))
{
- _dbus_hash_table_remove_int (loop->watches, fd);
+ _dbus_hash_table_remove_pollable (loop->watches, fd);
return FALSE;
}
}
_dbus_loop_toggle_watch (DBusLoop *loop,
DBusWatch *watch)
{
- refresh_watches_for_fd (loop, NULL, dbus_watch_get_socket (watch));
+ refresh_watches_for_fd (loop, NULL, _dbus_watch_get_pollable (watch));
}
void
{
DBusList **watches;
DBusList *link;
- DBusSocket fd;
+ DBusPollable fd;
/* This relies on people removing watches before they invalidate them,
* which has been safe since fd.o #33336 was fixed. Assert about it
* so we don't regress. */
- fd = _dbus_watch_get_socket (watch);
- _dbus_assert (fd != DBUS_SOCKET_INVALID);
+ fd = _dbus_watch_get_pollable (watch);
+ _dbus_assert (DBUS_POLLABLE_IS_VALID (fd));
- watches = _dbus_hash_table_lookup_int (loop->watches, fd);
+ watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
if (watches != NULL)
{
while (_dbus_hash_iter_next (&hash_iter))
{
DBusList **watches;
- int fd;
+ DBusPollable fd;
dbus_bool_t changed;
changed = FALSE;
- fd = _dbus_hash_iter_get_int_key (&hash_iter);
+ fd = _dbus_hash_iter_get_pollable_key (&hash_iter);
watches = _dbus_hash_iter_get_value (&hash_iter);
for (link = _dbus_list_get_first_link (watches);
if (condition == 0)
continue;
- watches = _dbus_hash_table_lookup_int (loop->watches,
- ready_fds[i].fd);
+ watches = _dbus_hash_table_lookup_pollable (loop->watches,
+ ready_fds[i].fd);
if (watches == NULL)
continue;
{
DBusWatch *watch;
- watch = _dbus_watch_new (fds[i],
+ watch = _dbus_watch_new (DBUS_SOCKET_GET_POLLABLE (fds[i]),
DBUS_WATCH_READABLE,
TRUE,
socket_handle_watch, socket_server,
static dbus_bool_t
socket_set_epoll_add (DBusSocketSet *set,
- int fd,
+ DBusPollable fd,
unsigned int flags,
dbus_bool_t enabled)
{
static void
socket_set_epoll_enable (DBusSocketSet *set,
- int fd,
+ DBusPollable fd,
unsigned int flags)
{
DBusSocketSetEpoll *self = socket_set_epoll_cast (set);
static void
socket_set_epoll_disable (DBusSocketSet *set,
- int fd)
+ DBusPollable fd)
{
DBusSocketSetEpoll *self = socket_set_epoll_cast (set);
struct epoll_event event;
static void
socket_set_epoll_remove (DBusSocketSet *set,
- int fd)
+ DBusPollable fd)
{
DBusSocketSetEpoll *self = socket_set_epoll_cast (set);
int err;
static dbus_bool_t
socket_set_poll_add (DBusSocketSet *set,
- int fd,
+ DBusPollable fd,
unsigned int flags,
dbus_bool_t enabled)
{
int i;
for (i = 0; i < self->n_fds; i++)
- _dbus_assert (self->fds[i].fd != fd);
+ _dbus_assert (!DBUS_POLLABLE_EQUALS (self->fds[i].fd, fd));
#endif
if (self->n_reserved >= self->n_allocated)
self->n_allocated += REALLOC_INCREMENT;
}
- _dbus_verbose ("before adding fd %d to %p, %d en/%d res/%d alloc\n",
- fd, self, self->n_fds, self->n_reserved, self->n_allocated);
+ _dbus_verbose ("before adding fd %" DBUS_POLLABLE_FORMAT " to %p, %d en/%d res/%d alloc\n",
+ DBUS_POLLABLE_PRINTABLE (fd), self, self->n_fds, self->n_reserved, self->n_allocated);
_dbus_assert (self->n_reserved >= self->n_fds);
_dbus_assert (self->n_allocated > self->n_reserved);
static void
socket_set_poll_enable (DBusSocketSet *set,
- int fd,
+ DBusPollable fd,
unsigned int flags)
{
DBusSocketSetPoll *self = socket_set_poll_cast (set);
for (i = 0; i < self->n_fds; i++)
{
- if (self->fds[i].fd == fd)
+ if (DBUS_POLLABLE_EQUALS (self->fds[i].fd, fd))
{
self->fds[i].events = watch_flags_to_poll_events (flags);
return;
static void
socket_set_poll_disable (DBusSocketSet *set,
- int fd)
+ DBusPollable fd)
{
DBusSocketSetPoll *self = socket_set_poll_cast (set);
int i;
for (i = 0; i < self->n_fds; i++)
{
- if (self->fds[i].fd == fd)
+ if (DBUS_POLLABLE_EQUALS (self->fds[i].fd, fd))
{
if (i != self->n_fds - 1)
{
static void
socket_set_poll_remove (DBusSocketSet *set,
- int fd)
+ DBusPollable fd)
{
DBusSocketSetPoll *self = socket_set_poll_cast (set);
socket_set_poll_disable (set, fd);
self->n_reserved--;
- _dbus_verbose ("after removing fd %d from %p, %d en/%d res/%d alloc\n",
- fd, self, self->n_fds, self->n_reserved, self->n_allocated);
+ _dbus_verbose ("after removing fd %" DBUS_POLLABLE_FORMAT " from %p, %d en/%d res/%d alloc\n",
+ DBUS_POLLABLE_PRINTABLE (fd), self, self->n_fds, self->n_reserved, self->n_allocated);
_dbus_assert (self->n_fds <= self->n_reserved);
_dbus_assert (self->n_reserved <= self->n_allocated);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#include <dbus/dbus.h>
+#include <dbus/dbus-sysdeps.h>
typedef struct {
- int fd;
+ DBusPollable fd;
unsigned int flags;
} DBusSocketEvent;
struct DBusSocketSetClass {
void (*free) (DBusSocketSet *self);
dbus_bool_t (*add) (DBusSocketSet *self,
- int fd,
+ DBusPollable fd,
unsigned int flags,
dbus_bool_t enabled);
void (*remove) (DBusSocketSet *self,
- int fd);
+ DBusPollable fd);
void (*enable) (DBusSocketSet *self,
- int fd,
+ DBusPollable fd,
unsigned int flags);
void (*disable) (DBusSocketSet *self,
- int fd);
+ DBusPollable fd);
int (*poll) (DBusSocketSet *self,
DBusSocketEvent *revents,
int max_events,
static inline dbus_bool_t
_dbus_socket_set_add (DBusSocketSet *self,
- int fd,
+ DBusPollable fd,
unsigned int flags,
dbus_bool_t enabled)
{
static inline void
_dbus_socket_set_remove (DBusSocketSet *self,
- int fd)
+ DBusPollable fd)
{
(self->cls->remove) (self, fd);
}
static inline void
_dbus_socket_set_enable (DBusSocketSet *self,
- int fd,
+ DBusPollable fd,
unsigned int flags)
{
(self->cls->enable) (self, fd, flags);
static inline void
_dbus_socket_set_disable (DBusSocketSet *self,
- int fd)
+ DBusPollable fd)
{
(self->cls->disable) (self, fd);
}
struct DBusWatch
{
int refcount; /**< Reference count */
- int fd; /**< File descriptor. */
+ DBusPollable fd; /**< File descriptor. */
unsigned int flags; /**< Conditions to watch. */
DBusWatchHandler handler; /**< Watch handler. */
* @returns the new DBusWatch object.
*/
DBusWatch*
-_dbus_watch_new (int fd,
+_dbus_watch_new (DBusPollable fd,
unsigned int flags,
dbus_bool_t enabled,
DBusWatchHandler handler,
watch->refcount -= 1;
if (watch->refcount == 0)
{
- if (watch->fd != -1)
+ if (DBUS_POLLABLE_IS_VALID (watch->fd))
_dbus_warn ("this watch should have been invalidated");
dbus_watch_set_data (watch, NULL, NULL); /* call free_data_function */
void
_dbus_watch_invalidate (DBusWatch *watch)
{
- watch->fd = -1;
+ DBUS_POLLABLE_INVALIDATE (watch->fd);
watch->flags = 0;
}
{
DBusList *next = _dbus_list_get_next_link (&watch_list->watches,
link);
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+ DBusWatch *watch = link->data;
- _dbus_verbose ("Adding a %s watch on fd %d using newly-set add watch function\n",
+ _dbus_verbose ("Adding a %s watch on fd %" DBUS_POLLABLE_FORMAT " using newly-set add watch function\n",
watch_flags_to_string (dbus_watch_get_flags (link->data)),
- dbus_watch_get_socket (link->data));
+ DBUS_POLLABLE_PRINTABLE (watch->fd));
+#endif
if (!(* add_function) (link->data, data))
{
{
DBusList *next = _dbus_list_get_next_link (&watch_list->watches,
link2);
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+ DBusWatch *watch2 = link2->data;
- _dbus_verbose ("Removing watch on fd %d using newly-set remove function because initial add failed\n",
- dbus_watch_get_socket (link2->data));
+ _dbus_verbose ("Removing watch on fd %" DBUS_POLLABLE_FORMAT " using newly-set remove function because initial add failed\n",
+ DBUS_POLLABLE_PRINTABLE (watch2->fd));
+#endif
(* remove_function) (link2->data, data);
if (watch_list->add_watch_function != NULL)
{
- _dbus_verbose ("Adding watch on fd %d\n",
- dbus_watch_get_socket (watch));
+ _dbus_verbose ("Adding watch on fd %" DBUS_POLLABLE_FORMAT "\n",
+ DBUS_POLLABLE_PRINTABLE (watch->fd));
if (!(* watch_list->add_watch_function) (watch,
watch_list->watch_data))
if (watch_list->remove_watch_function != NULL)
{
- _dbus_verbose ("Removing watch on fd %d\n",
- dbus_watch_get_socket (watch));
+ _dbus_verbose ("Removing watch on fd %" DBUS_POLLABLE_FORMAT "\n",
+ DBUS_POLLABLE_PRINTABLE (watch->fd));
(* watch_list->remove_watch_function) (watch,
watch_list->watch_data);
if (watch_list->watch_toggled_function != NULL)
{
- _dbus_verbose ("Toggling watch %p on fd %d to %d\n",
- watch, dbus_watch_get_socket (watch), watch->enabled);
+ _dbus_verbose ("Toggling watch %p on fd %" DBUS_POLLABLE_FORMAT " to %d\n",
+ watch,
+ DBUS_POLLABLE_PRINTABLE (watch->fd),
+ watch->enabled);
(* watch_list->watch_toggled_function) (watch,
watch_list->watch_data);
return watch->fd;
}
+DBusPollable
+_dbus_watch_get_pollable (DBusWatch *watch)
+{
+ _dbus_assert (watch != NULL);
+
+ return watch->fd;
+}
+
/**
* Gets flags from DBusWatchFlags indicating
* what conditions should be monitored on the
{
_dbus_return_if_fail (watch != NULL);
- _dbus_verbose ("Setting watch fd %d data to data = %p function = %p from data = %p function = %p\n",
- dbus_watch_get_socket (watch),
+ _dbus_verbose ("Setting watch fd %" DBUS_POLLABLE_FORMAT " data to data = %p function = %p from data = %p function = %p\n",
+ DBUS_POLLABLE_PRINTABLE (watch->fd),
data, free_data_function, watch->data, watch->free_data_function);
if (watch->free_data_function != NULL)
_dbus_return_val_if_fail (watch != NULL, FALSE);
#ifndef DBUS_DISABLE_CHECKS
- if (watch->fd < 0 || watch->flags == 0)
+ if (!DBUS_POLLABLE_IS_VALID (watch->fd) || watch->flags == 0)
{
_dbus_warn_check_failed ("Watch is invalid, it should have been removed\n");
return TRUE;
}
#endif
- _dbus_return_val_if_fail (watch->fd >= 0 /* fails if watch was removed */, TRUE);
+ _dbus_return_val_if_fail (DBUS_POLLABLE_IS_VALID (watch->fd) /* fails if watch was removed */, TRUE);
_dbus_watch_sanitize_condition (watch, &flags);
if (flags == 0)
{
- _dbus_verbose ("After sanitization, watch flags on fd %d were 0\n",
- watch->fd);
+ _dbus_verbose ("After sanitization, watch flags on fd %" DBUS_POLLABLE_FORMAT " were 0\n",
+ DBUS_POLLABLE_PRINTABLE (watch->fd));
return TRUE;
}
else
void *data);
DBUS_PRIVATE_EXPORT
-DBusWatch* _dbus_watch_new (int fd,
+DBusWatch* _dbus_watch_new (DBusPollable fd,
unsigned int flags,
dbus_bool_t enabled,
DBusWatchHandler handler,
DBUS_PRIVATE_EXPORT
void _dbus_watch_set_oom_last_time (DBusWatch *watch,
dbus_bool_t oom);
-DBUS_PRIVATE_EXPORT
+
DBusSocket _dbus_watch_get_socket (DBusWatch *watch);
+DBUS_PRIVATE_EXPORT
+DBusPollable _dbus_watch_get_pollable (DBusWatch *watch);
/** @} */