exit (1);
}
- watch = _dbus_watch_new (DBUS_SOCKET_GET_POLLABLE (reload_pipe[RELOAD_READ_END]),
+ watch = _dbus_watch_new (_dbus_socket_get_pollable (reload_pipe[RELOAD_READ_END]),
DBUS_WATCH_READABLE, TRUE,
handle_reload_watch, NULL, NULL);
*watch = NULL;
_dbus_close_socket (reload_pipe[RELOAD_READ_END], NULL);
- DBUS_SOCKET_INVALIDATE (reload_pipe[RELOAD_READ_END]);
+ _dbus_socket_invalidate (&reload_pipe[RELOAD_READ_END]);
_dbus_close_socket (reload_pipe[RELOAD_WRITE_END], NULL);
- DBUS_SOCKET_INVALIDATE (reload_pipe[RELOAD_WRITE_END]);
+ _dbus_socket_invalidate (&reload_pipe[RELOAD_WRITE_END]);
}
#endif /* DBUS_UNIX */
if (retval)
{
- *fd = DBUS_SOCKET_GET_INT (s);
+ *fd = _dbus_socket_get_int (s);
}
CONNECTION_UNLOCK (connection);
DBusList **watches;
_dbus_warn ("invalid request, socket fd %" DBUS_POLLABLE_FORMAT " not open\n",
- DBUS_POLLABLE_PRINTABLE (fd));
+ _dbus_pollable_printable (fd));
watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
if (watches != NULL)
unsigned int flags = 0;
dbus_bool_t interested = FALSE;
- _dbus_assert (DBUS_POLLABLE_IS_VALID (fd));
+ _dbus_assert (_dbus_pollable_is_valid (fd));
if (watches == NULL)
watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
DBusList **watches;
fd = _dbus_watch_get_pollable (watch);
- _dbus_assert (DBUS_POLLABLE_IS_VALID (fd));
+ _dbus_assert (_dbus_pollable_is_valid (fd));
watches = ensure_watch_table_entry (loop, fd);
* which has been safe since fd.o #33336 was fixed. Assert about it
* so we don't regress. */
fd = _dbus_watch_get_pollable (watch);
- _dbus_assert (DBUS_POLLABLE_IS_VALID (fd));
+ _dbus_assert (_dbus_pollable_is_valid (fd));
watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce, NULL) != TRUE)
return _dbus_socket_get_invalid ();
fd = _dbus_accept (listen_fd);
- if (!DBUS_SOCKET_IS_VALID (fd))
+ if (!_dbus_socket_is_valid (fd))
return fd;
if (do_check_nonce(fd, &nonce, NULL) != TRUE) {
_dbus_verbose ("nonce check failed. Closing socket.\n");
_dbus_string_free (&address);
- DBUS_SOCKET_INVALIDATE (client_fd);
+ _dbus_socket_invalidate (&client_fd);
server_transport = _dbus_transport_new_for_socket (server_fd,
&server->guid_hex, NULL);
return NULL;
}
- DBUS_SOCKET_INVALIDATE (server_fd);
+ _dbus_socket_invalidate (&server_fd);
if (!_dbus_transport_set_auth_mechanisms (server_transport,
(const char**) server->auth_mechanisms))
void *new_connection_data;
_dbus_verbose ("Creating new client connection with fd %" DBUS_SOCKET_FORMAT "\n",
- DBUS_SOCKET_PRINTABLE (client_fd));
+ _dbus_socket_printable (client_fd));
HAVE_LOCK_CHECK (server);
saved_errno = _dbus_save_socket_errno ();
- if (!DBUS_SOCKET_IS_VALID (client_fd))
+ if (!_dbus_socket_is_valid (client_fd))
{
/* EINTR handled for us */
}
_dbus_close_socket (socket_server->fds[i], NULL);
- DBUS_SOCKET_INVALIDATE (socket_server->fds[i]);
+ _dbus_socket_invalidate (&socket_server->fds[i]);
}
if (socket_server->socket_name != NULL)
{
DBusWatch *watch;
- watch = _dbus_watch_new (DBUS_SOCKET_GET_POLLABLE (fds[i]),
+ watch = _dbus_watch_new (_dbus_socket_get_pollable (fds[i]),
DBUS_WATCH_READABLE,
TRUE,
socket_handle_watch, socket_server,
int i;
for (i = 0; i < self->n_fds; i++)
- _dbus_assert (!DBUS_POLLABLE_EQUALS (self->fds[i].fd, fd));
+ _dbus_assert (!_dbus_pollable_equals (self->fds[i].fd, fd));
#endif
if (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_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);
for (i = 0; i < self->n_fds; i++)
{
- if (DBUS_POLLABLE_EQUALS (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;
for (i = 0; i < self->n_fds; i++)
{
- if (DBUS_POLLABLE_EQUALS (self->fds[i].fd, fd))
+ if (_dbus_pollable_equals (self->fds[i].fd, fd))
{
if (i != self->n_fds - 1)
{
self->n_reserved--;
_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_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);
}
freeaddrinfo(ai);
- if (!DBUS_SOCKET_IS_VALID (fd))
+ if (!_dbus_socket_is_valid (fd))
{
dbus_set_error (error,
_dbus_error_from_errno (errno),
retry:
client_fd.sock = accept (listen_fd.sock, NULL, NULL);
- if (!DBUS_SOCKET_IS_VALID (client_fd))
+ if (!_dbus_socket_is_valid (client_fd))
{
DBUS_SOCKET_SET_ERRNO ();
if (errno == EINTR)
typedef struct { int fd; } DBusSocket;
# define DBUS_SOCKET_FORMAT "d"
-# define DBUS_SOCKET_PRINTABLE(s) ((s).fd)
# define DBUS_SOCKET_INIT { -1 }
-# define DBUS_SOCKET_IS_VALID(s) ((s).fd >= 0)
-# define DBUS_SOCKET_INVALIDATE(s) ((s).fd = -1)
-# define DBUS_SOCKET_GET_INT(s) ((s).fd)
+
+static inline int
+_dbus_socket_printable (DBusSocket s) { return s.fd; }
+
+static inline dbus_bool_t
+_dbus_socket_is_valid (DBusSocket s) { return s.fd >= 0; }
+
+static inline void
+_dbus_socket_invalidate (DBusSocket *s) { s->fd = -1; }
+
+static inline int
+_dbus_socket_get_int (DBusSocket s) { return s.fd; }
#else /* DBUS_WIN */
typedef struct { SOCKET sock; } DBusSocket;
# define DBUS_SOCKET_FORMAT "Iu"
-# define DBUS_SOCKET_PRINTABLE(s) ((s).sock)
# define DBUS_SOCKET_INIT { INVALID_SOCKET }
-# define DBUS_SOCKET_IS_VALID(s) ((s).sock != INVALID_SOCKET)
-# define DBUS_SOCKET_INVALIDATE(s) ((s).sock = INVALID_SOCKET)
-# define DBUS_SOCKET_GET_INT(s) ((int) (s).sock)
+
+static inline SOCKET
+_dbus_socket_printable (DBusSocket s) { return s.sock; }
+
+static inline dbus_bool_t
+_dbus_socket_is_valid (DBusSocket s) { return s.sock != INVALID_SOCKET; }
+
+static inline void
+_dbus_socket_invalidate (DBusSocket *s) { s->sock = INVALID_SOCKET; }
+
+static inline int
+_dbus_socket_get_int (DBusSocket s) { return (int)s.sock; }
#endif /* DBUS_WIN */
* use DBusSocket so that the compiler can check we are doing it right.
*/
typedef DBusSocket DBusPollable;
-# define DBUS_SOCKET_GET_POLLABLE(s) (s)
# define DBUS_POLLABLE_FORMAT "Iu"
-# define DBUS_POLLABLE_PRINTABLE(p) (p.sock)
-# define DBUS_POLLABLE_IS_VALID(p) (DBUS_SOCKET_IS_VALID (p))
-# define DBUS_POLLABLE_INVALIDATE(p) (DBUS_SOCKET_INVALIDATE (p))
-# define DBUS_POLLABLE_EQUALS(a, b) ((a).sock == (b).sock)
+
+static inline DBusPollable
+_dbus_socket_get_pollable (DBusSocket s) { return s; }
+
+static inline SOCKET
+_dbus_pollable_printable (DBusPollable p) { return p.sock; }
+
+static inline dbus_bool_t
+_dbus_pollable_is_valid (DBusPollable p) { return _dbus_socket_is_valid (p); }
+
+static inline void
+_dbus_pollable_invalidate (DBusPollable *p) { _dbus_socket_invalidate (p); }
+
+static inline dbus_bool_t
+_dbus_pollable_equals (DBusPollable a, DBusPollable b) { return a.sock == b.sock; }
#else /* !DBUS_WIN */
* abstraction.)
*/
typedef int DBusPollable;
-# define DBUS_SOCKET_GET_POLLABLE(s) (s.fd)
# define DBUS_POLLABLE_FORMAT "d"
-# define DBUS_POLLABLE_PRINTABLE(p) (p)
-# define DBUS_POLLABLE_IS_VALID(p) (p >= 0)
-# define DBUS_POLLABLE_INVALIDATE(p) ((p) = -1)
-# define DBUS_POLLABLE_EQUALS(a, b) ((a) == (b))
+
+static inline DBusPollable
+_dbus_socket_get_pollable (DBusSocket s) { return s.fd; }
+
+static inline int
+_dbus_pollable_printable (DBusPollable p) { return p; }
+
+static inline dbus_bool_t
+_dbus_pollable_is_valid (DBusPollable p) { return p >= 0; }
+
+static inline void
+_dbus_pollable_invalidate (DBusPollable *p) { *p = -1; }
+
+static inline dbus_bool_t
+_dbus_pollable_equals (DBusPollable a, DBusPollable b) { return a == b; }
#endif /* !DBUS_WIN */
_dbus_verbose ("check_write_watch(): needed = %d on connection %p watch %p fd = %" DBUS_SOCKET_FORMAT " outgoing messages exist %d\n",
needed, transport->connection, socket_transport->write_watch,
- DBUS_SOCKET_PRINTABLE (socket_transport->fd),
+ _dbus_socket_printable (socket_transport->fd),
_dbus_connection_has_messages_to_send_unlocked (transport->connection));
_dbus_connection_toggle_watch_unlocked (transport->connection,
dbus_bool_t need_read_watch;
_dbus_verbose ("fd = %" DBUS_SOCKET_FORMAT "\n",
- DBUS_SOCKET_PRINTABLE (socket_transport->fd));
+ _dbus_socket_printable (socket_transport->fd));
if (transport->connection == NULL)
return;
#if 1
_dbus_verbose ("do_writing(), have_messages = %d, fd = %" DBUS_SOCKET_FORMAT "\n",
_dbus_connection_has_messages_to_send_unlocked (transport->connection),
- DBUS_SOCKET_PRINTABLE (socket_transport->fd));
+ _dbus_socket_printable (socket_transport->fd));
#endif
oom = FALSE;
int saved_errno;
_dbus_verbose ("fd = %" DBUS_SOCKET_FORMAT "\n",
- DBUS_SOCKET_PRINTABLE (socket_transport->fd));
+ _dbus_socket_printable (socket_transport->fd));
/* No messages without authentication! */
if (!_dbus_transport_try_to_authenticate (transport))
free_watches (transport);
_dbus_close_socket (socket_transport->fd, NULL);
- DBUS_SOCKET_INVALIDATE (socket_transport->fd);
+ _dbus_socket_invalidate (&socket_transport->fd);
}
static dbus_bool_t
timeout_milliseconds,
socket_transport->read_watch,
socket_transport->write_watch,
- DBUS_SOCKET_PRINTABLE (socket_transport->fd));
+ _dbus_socket_printable (socket_transport->fd));
/* the passed in DO_READING/DO_WRITING flags indicate whether to
* read/write messages, but regardless of those we may need to block
* we don't want to read any messages yet if not given DO_READING.
*/
- poll_fd.fd = DBUS_SOCKET_GET_POLLABLE (socket_transport->fd);
+ poll_fd.fd = _dbus_socket_get_pollable (socket_transport->fd);
poll_fd.events = 0;
if (_dbus_transport_try_to_authenticate (transport))
if (!_dbus_string_init (&socket_transport->encoded_incoming))
goto failed_1;
- socket_transport->write_watch = _dbus_watch_new (DBUS_SOCKET_GET_POLLABLE (fd),
+ socket_transport->write_watch = _dbus_watch_new (_dbus_socket_get_pollable (fd),
DBUS_WATCH_WRITABLE,
FALSE,
NULL, NULL, NULL);
if (socket_transport->write_watch == NULL)
goto failed_2;
- socket_transport->read_watch = _dbus_watch_new (DBUS_SOCKET_GET_POLLABLE (fd),
+ socket_transport->read_watch = _dbus_watch_new (_dbus_socket_get_pollable (fd),
DBUS_WATCH_READABLE,
FALSE,
NULL, NULL, NULL);
goto error;
fd = _dbus_connect_tcp_socket_with_nonce (host, port, family, noncefile, error);
- if (!DBUS_SOCKET_IS_VALID (fd))
+ if (!_dbus_socket_is_valid (fd))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
_dbus_string_free (&address);
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_close_socket (fd, NULL);
- DBUS_SOCKET_INVALIDATE (fd);
+ _dbus_socket_invalidate (&fd);
}
return transport;
watch->refcount -= 1;
if (watch->refcount == 0)
{
- if (DBUS_POLLABLE_IS_VALID (watch->fd))
+ 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)
{
- DBUS_POLLABLE_INVALIDATE (watch->fd);
+ _dbus_pollable_invalidate (&watch->fd);
watch->flags = 0;
}
_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_POLLABLE_PRINTABLE (watch->fd));
+ _dbus_pollable_printable (watch->fd));
#endif
if (!(* add_function) (link->data, data))
DBusWatch *watch2 = 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));
+ _dbus_pollable_printable (watch2->fd));
#endif
(* remove_function) (link2->data, data);
if (watch_list->add_watch_function != NULL)
{
_dbus_verbose ("Adding watch on fd %" DBUS_POLLABLE_FORMAT "\n",
- DBUS_POLLABLE_PRINTABLE (watch->fd));
+ _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 %" DBUS_POLLABLE_FORMAT "\n",
- DBUS_POLLABLE_PRINTABLE (watch->fd));
+ _dbus_pollable_printable (watch->fd));
(* watch_list->remove_watch_function) (watch,
watch_list->watch_data);
{
_dbus_verbose ("Toggling watch %p on fd %" DBUS_POLLABLE_FORMAT " to %d\n",
watch,
- DBUS_POLLABLE_PRINTABLE (watch->fd),
+ _dbus_pollable_printable (watch->fd),
watch->enabled);
(* watch_list->watch_toggled_function) (watch,
#ifdef DBUS_UNIX
return watch->fd;
#else
- return DBUS_SOCKET_GET_INT (watch->fd);
+ return _dbus_socket_get_int (watch->fd);
#endif
}
_dbus_return_if_fail (watch != NULL);
_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),
+ _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 (!DBUS_POLLABLE_IS_VALID (watch->fd) || 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 (DBUS_POLLABLE_IS_VALID (watch->fd) /* 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 %" DBUS_POLLABLE_FORMAT " were 0\n",
- DBUS_POLLABLE_PRINTABLE (watch->fd));
+ _dbus_pollable_printable (watch->fd));
return TRUE;
}
else