/** * Updates all registered GPollFD objects, unregisters old ones, * registers new ones. */ static void http_client_update_fds(void) { fd_set rfds, wfds, efds; int max_fd; CURLMcode mcode; GSList *fds; FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&efds); mcode = curl_multi_fdset(http_client.multi, &rfds, &wfds, &efds, &max_fd); if (mcode != CURLM_OK) { mpdcron_log(LOG_WARNING, "curl_multi_fdset() failed: %s\n", curl_multi_strerror(mcode)); return; } fds = http_client.fds; http_client.fds = NULL; while (fds != NULL) { GPollFD *poll_fd = fds->data; gushort events = http_client_fd_events(poll_fd->fd, &rfds, &wfds, &efds); assert(poll_fd->events != 0); fds = g_slist_remove(fds, poll_fd); if (events != poll_fd->events) g_source_remove_poll(http_client.source, poll_fd); if (events != 0) { if (events != poll_fd->events) { poll_fd->events = events; g_source_add_poll(http_client.source, poll_fd); } http_client.fds = g_slist_prepend(http_client.fds, poll_fd); } else { g_free(poll_fd); } } for (int fd = 0; fd <= max_fd; ++fd) { gushort events = http_client_fd_events(fd, &rfds, &wfds, &efds); if (events != 0) { GPollFD *poll_fd = g_new(GPollFD, 1); poll_fd->fd = fd; poll_fd->events = events; g_source_add_poll(http_client.source, poll_fd); http_client.fds = g_slist_prepend(http_client.fds, poll_fd); } } }
/* * Create a event source object for connection. The object * will be added to "Event Context" for polling. */ __export HmWatch * hm_watch_create(HmConnection *conn, HmWatchFuncs *funcs, gint size) { GSource *source; HmWatch *watch; G_ASSERT(conn != NULL && funcs != NULL && size >= sizeof(HmWatch)); source = g_source_new(&hm_watch_funcs, size); watch = (HmWatch*)source; watch->buffer = hm_net_buf_alloc( hm_connection_is_heavy(conn) ? LARGE_BUFFER_BLOCKS : SMALL_BUFFER_BLOCKS, hm_connection_get_buffer_size(conn), hm_watch_write_out); if (!watch->buffer) { g_source_unref(source); hm_warning( "Net create watch, alloc buffer failed." ); return NULL; } watch->lock = g_mutex_new(); watch->conn = conn; watch->funcs = funcs; watch->r_fd.fd = hm_connection_get_fd(conn); watch->w_fd.fd = hm_connection_get_fd(conn); watch->r_fd.events = READ_COND; watch->w_fd.events = WRITE_COND; watch->r_fd.revents = 0; watch->w_fd.revents = 0; hm_watch_init_time(watch); watch->w_pending = 0; watch->killed = 0; watch->heavy_io_load = hm_connection_is_heavy(conn); watch->block_size = hm_connection_get_buffer_size(conn); hm_watch_set_callback(watch, hm_watch_rw_dispatch, NULL); if (hm_connection_is_ingrogress(conn, 0)) g_source_add_poll(source, &watch->w_fd); else g_source_add_poll(source, &watch->r_fd); g_atomic_int_add(&total_watch_count, 1); return watch; }
/* * Add an IPC_channel to the gmainloop world... */ GCHSource* G_main_IPC_Channel_constructor(GSource* source, IPC_Channel* ch , gpointer userdata , GDestroyNotify notify) { int rfd, wfd; GCHSource* chp; if( !source ) { cl_log(LOG_WARNING, "%s:%d: got null source", __FUNCTION__,__LINE__); return NULL; } if( !ch ) { cl_log(LOG_WARNING, "%s:%d: got null channel", __FUNCTION__,__LINE__); return NULL; } chp = (GCHSource*)source; chp->magno = MAG_GCHSOURCE; chp->maxdispatchdelayms = DEFAULT_MAXDELAY; chp->maxdispatchms = DEFAULT_MAXDISPATCH; lc_store((chp->detecttime), zero_longclock); ch->refcount++; chp->ch = ch; chp->udata=userdata; chp->dnotify = notify; chp->dontread = FALSE; rfd = ch->ops->get_recv_select_fd(ch); wfd = ch->ops->get_send_select_fd(ch); chp->fd_fdx = (rfd == wfd); if (debug_level > 1) { cl_log(LOG_DEBUG, "%s(sock=%d,%d)",__FUNCTION__, rfd,wfd); } chp->infd.fd = rfd; chp->infd.events = DEF_EVENTS; g_source_add_poll(source, &chp->infd); if (!chp->fd_fdx) { chp->outfd.fd = wfd; chp->outfd.events = DEF_EVENTS; g_source_add_poll(source, &chp->outfd); } chp->dispatch = NULL; chp->description = "IPC channel(base)"; chp->gsourceid = 0; return chp; }
LOCAL_SYMBOL MetaEventQueue* meta_event_queue_new (Display *display, MetaEventQueueFunc func, gpointer data) { GSource *source; MetaEventQueue *eq; source = g_source_new (&eq_funcs, sizeof (MetaEventQueue)); eq = (MetaEventQueue*) source; eq->connection_fd = ConnectionNumber (display); eq->poll_fd.fd = eq->connection_fd; eq->poll_fd.events = G_IO_IN; eq->events = g_queue_new (); eq->display = display; g_source_set_priority (source, G_PRIORITY_DEFAULT); g_source_add_poll (source, &eq->poll_fd); g_source_set_can_recurse (source, TRUE); g_source_set_callback (source, (GSourceFunc) func, data, NULL); g_source_attach (source, NULL); g_source_unref (source); return eq; }
GSource * _g_fd_source_new (int fd, gushort events, GCancellable *cancellable) { GSource *source; FDSource *fd_source; source = g_source_new (&fd_source_funcs, sizeof (FDSource)); fd_source = (FDSource *)source; if (cancellable) fd_source->cancellable = g_object_ref (cancellable); fd_source->pollfd.fd = fd; fd_source->pollfd.events = events; g_source_add_poll (source, &fd_source->pollfd); if (cancellable) fd_source->cancelled_tag = g_cancellable_connect (cancellable, (GCallback)fd_source_cancelled_cb, NULL, NULL); return source; }
/**Set mask for a registered event. @internal * * Sets the mask describing events that can signal the registered callback. * * @param port pointer to port object * @param index registration index * @param socket socket * @param events new event mask * * @retval 0 when successful, * @retval -1 upon an error. */ static int su_source_eventmask(su_port_t *self, int index, int socket, int events) { unsigned n; int retval; enter; assert(self); assert(SU_SOURCE_OWN_THREAD(self)); assert(0 < index && (unsigned)index <= self->sup_max_index); if (index <= 0 || (unsigned)index > self->sup_max_index) return -1; n = self->sup_indices[index - 1]; if (n == UINT_MAX) return -1; g_source_remove_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]); retval = su_wait_mask(&self->sup_waits[n], socket, events); g_source_add_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]); return retval; }
GSource * _g_fd_source_new (int fd, gushort events, GCancellable *cancellable) { GSource *source; FDSource *fd_source; source = g_source_new (&fd_source_funcs, sizeof (FDSource)); fd_source = (FDSource *)source; fd_source->pollfd.fd = fd; fd_source->pollfd.events = events; g_source_add_poll (source, &fd_source->pollfd); if (cancellable) { GSource *cancellable_source = g_cancellable_source_new (cancellable); g_source_set_dummy_callback (cancellable_source); g_source_add_child_source (source, cancellable_source); g_source_unref (cancellable_source); } return source; }
std::unique_ptr<PlatformDisplayWayland> PlatformDisplayWayland::create() { struct wl_display* wlDisplay = wl_display_connect(nullptr); if (!wlDisplay) { WTFLogAlways("PlatformDisplayWayland initialization: failed to connect to the Wayland server socket. Check your WAYLAND_DISPLAY or WAYLAND_SOCKET environment variables."); return nullptr; } std::unique_ptr<PlatformDisplayWayland> display(new PlatformDisplayWayland(wlDisplay)); if (!display->isInitialized()) { WTFLogAlways("PlatformDisplayWayland initialization: failed to complete the initialization of the display."); return nullptr; } GSource* baseSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource)); auto* source = reinterpret_cast<EventSource*>(baseSource); source->display = display->m_display; source->pfd.fd = wl_display_get_fd(display->m_display); source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; source->pfd.revents = 0; g_source_add_poll(baseSource, &source->pfd); g_source_set_name(baseSource, "[WebKit] WaylandDisplay"); g_source_set_priority(baseSource, G_PRIORITY_HIGH + 30); g_source_set_can_recurse(baseSource, TRUE); g_source_attach(baseSource, g_main_context_get_thread_default()); return display; }
static GSource *g_io_gnutls_create_watch(GIOChannel *channel, GIOCondition condition) { GIOGnuTLSChannel *gnutls_channel = (GIOGnuTLSChannel *) channel; GIOGnuTLSWatch *watch; GSource *source; DBG("channel %p condition %u", channel, condition); source = g_source_new(&gnutls_watch_funcs, sizeof(GIOGnuTLSWatch)); watch = (GIOGnuTLSWatch *) source; watch->channel = channel; g_io_channel_ref(channel); watch->condition = condition; watch->pollfd.fd = gnutls_channel->fd; watch->pollfd.events = condition; g_source_add_poll(source, &watch->pollfd); return source; }
void _clutter_backend_x11_events_init (ClutterBackend *backend) { ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend); GSource *source; ClutterEventSource *event_source; int connection_number; gchar *name; connection_number = ConnectionNumber (backend_x11->xdpy); CLUTTER_NOTE (EVENT, "Connection number: %d", connection_number); source = backend_x11->event_source = clutter_event_source_new (backend); event_source = (ClutterEventSource *) source; g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS); name = g_strdup_printf ("Clutter X11 Event (connection: %d)", connection_number); g_source_set_name (source, name); g_free (name); event_source->event_poll_fd.fd = connection_number; event_source->event_poll_fd.events = G_IO_IN; event_sources = g_list_prepend (event_sources, event_source); g_source_add_poll (source, &event_source->event_poll_fd); g_source_set_can_recurse (source, TRUE); g_source_attach (source, NULL); }
/* Each FD may have at most one valid dispatcher. * If a new dispatch is added for an FD, the old one is removed. * mode determines what types of events are watched for, and may be any combination of: * OWL_IO_READ, OWL_IO_WRITE, OWL_IO_EXCEPT */ const owl_io_dispatch *owl_select_add_io_dispatch(int fd, int mode, void (*cb)(const owl_io_dispatch *, void *), void (*destroy)(const owl_io_dispatch *), void *data) { owl_io_dispatch *d = g_new(owl_io_dispatch, 1); owl_list *dl = owl_global_get_io_dispatch_list(&g); owl_io_dispatch *other; d->fd = fd; d->valid = true; d->needs_gc = 0; d->mode = mode; d->callback = cb; d->destroy = destroy; d->data = data; /* TODO: Allow changing fd and mode in the middle? Probably don't care... */ d->pollfd.fd = fd; d->pollfd.events = 0; if (d->mode & OWL_IO_READ) d->pollfd.events |= G_IO_IN | G_IO_HUP | G_IO_ERR; if (d->mode & OWL_IO_WRITE) d->pollfd.events |= G_IO_OUT | G_IO_ERR; if (d->mode & OWL_IO_EXCEPT) d->pollfd.events |= G_IO_PRI | G_IO_ERR; g_source_add_poll(owl_io_dispatch_source, &d->pollfd); other = owl_select_find_valid_io_dispatch_by_fd(fd); if (other) owl_select_invalidate_io_dispatch(other); owl_list_append_element(dl, d); return d; }
static void sync_pollfds (ProtobufSource *protobuf_source) { RigProtobufCDispatch *dispatch = protobuf_source->dispatch; GSource *source = &protobuf_source->source; int i; if (pollfds_up_to_date (protobuf_source)) return; for (i = 0; i < protobuf_source->n_pollfds; i++) g_source_remove_poll (source, &protobuf_source->pollfds[i]); g_free (protobuf_source->pollfds); protobuf_source->n_pollfds = dispatch->n_notifies_desired; protobuf_source->pollfds = g_new (GPollFD, dispatch->n_notifies_desired); for (i = 0; i < protobuf_source->n_pollfds; i++) { protobuf_source->pollfds[i].fd = dispatch->notifies_desired[i].fd; protobuf_source->pollfds[i].events = protobuf_events_to_gpollfd_events (dispatch->notifies_desired[i].events); g_source_add_poll (source, &protobuf_source->pollfds[i]); } }
WaylandDisplay::WaylandDisplay() { m_display = wl_display_connect(nullptr); m_registry = wl_display_get_registry(m_display); wl_registry_add_listener(m_registry, &g_registryListener, &m_interfaces); wl_display_roundtrip(m_display); m_eventSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource)); auto* source = reinterpret_cast<EventSource*>(m_eventSource); source->display = m_display; source->pfd.fd = wl_display_get_fd(m_display); source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; source->pfd.revents = 0; g_source_add_poll(m_eventSource, &source->pfd); g_source_set_name(m_eventSource, "[WPE] WaylandDisplay"); g_source_set_priority(m_eventSource, G_PRIORITY_HIGH + 30); g_source_set_can_recurse(m_eventSource, TRUE); g_source_attach(m_eventSource, g_main_context_get_thread_default()); if (m_interfaces.xdg) { xdg_shell_add_listener(m_interfaces.xdg, &g_xdgShellListener, nullptr); xdg_shell_use_unstable_version(m_interfaces.xdg, 5); } wl_seat_add_listener(m_interfaces.seat, &g_seatListener, &m_seatData); m_seatData.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); m_seatData.xkb.composeTable = xkb_compose_table_new_from_locale(m_seatData.xkb.context, setlocale(LC_CTYPE, nullptr), XKB_COMPOSE_COMPILE_NO_FLAGS); if (m_seatData.xkb.composeTable) m_seatData.xkb.composeState = xkb_compose_state_new(m_seatData.xkb.composeTable, XKB_COMPOSE_STATE_NO_FLAGS); }
WaylandDisplay::WaylandDisplay() { m_display = wl_display_connect(nullptr); m_registry = wl_display_get_registry(m_display); wl_registry_add_listener(m_registry, &g_registryListener, &m_interfaces); wl_display_roundtrip(m_display); m_eventSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource)); auto* source = reinterpret_cast<EventSource*>(m_eventSource); source->display = m_display; source->pfd.fd = wl_display_get_fd(m_display); source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; source->pfd.revents = 0; g_source_add_poll(m_eventSource, &source->pfd); g_source_set_name(m_eventSource, "[WPE] WaylandDisplay"); g_source_set_priority(m_eventSource, G_PRIORITY_HIGH + 30); g_source_set_can_recurse(m_eventSource, TRUE); g_source_attach(m_eventSource, g_main_context_get_thread_default()); if (m_interfaces.xdg) { xdg_shell_add_listener(m_interfaces.xdg, &g_xdgShellListener, nullptr); xdg_shell_use_unstable_version(m_interfaces.xdg, 5); } }
GSource * _clutter_x11_event_source_new (ClutterBackendX11 *backend_x11) { ClutterEventSource *event_source; int connection_number; GSource *source; gchar *name; connection_number = ConnectionNumber (backend_x11->xdpy); CLUTTER_NOTE (EVENT, "Connection number: %d", connection_number); source = g_source_new (&event_funcs, sizeof (ClutterEventSource)); event_source = (ClutterEventSource *) source; name = g_strdup_printf ("Clutter X11 Event (connection: %d)", connection_number); g_source_set_name (source, name); g_free (name); event_source->backend = backend_x11; event_source->event_poll_fd.fd = connection_number; event_source->event_poll_fd.events = G_IO_IN; g_source_add_poll (source, &event_source->event_poll_fd); g_source_set_can_recurse (source, TRUE); return source; }
GSource * _gdk_wayland_display_event_source_new (GdkDisplay *display) { GSource *source; GdkWaylandEventSource *wl_source; GdkWaylandDisplay *display_wayland; char *name; source = g_source_new (&wl_glib_source_funcs, sizeof (GdkWaylandEventSource)); name = g_strdup_printf ("GDK Wayland Event source (%s)", "display name"); g_source_set_name (source, name); g_free (name); wl_source = (GdkWaylandEventSource *) source; display_wayland = GDK_WAYLAND_DISPLAY (display); wl_source->display = display; wl_source->pfd.fd = wl_display_get_fd(display_wayland->wl_display); wl_source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; g_source_add_poll(source, &wl_source->pfd); g_source_set_priority (source, GDK_PRIORITY_EVENTS); g_source_set_can_recurse (source, TRUE); g_source_attach (source, NULL); event_sources = g_list_prepend (event_sources, source); return source; }
static AvahiWatch* watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent events, AvahiWatchCallback callback, void *userdata) { AvahiWatch *w; AvahiGLibPoll *g; assert(api); assert(fd >= 0); assert(callback); g = api->userdata; assert(g); if (!(w = avahi_new(AvahiWatch, 1))) return NULL; w->glib_poll = g; w->pollfd.fd = fd; w->pollfd.events = map_events_to_glib(events); w->pollfd.revents = 0; w->callback = callback; w->userdata = userdata; w->dead = FALSE; g_source_add_poll(&g->source, &w->pollfd); w->pollfd_added = TRUE; AVAHI_LLIST_PREPEND(AvahiWatch, watches, g->watches, w); return w; }
gboolean xevent_init() { X11Source* xsource; int fd; dpy = XOpenDisplay( g_getenv("DISPLAY") ); if( ! dpy ) return FALSE; /* according to the spec, private Atoms should prefix their names with _. */ CMD_ATOM = XInternAtom( dpy, "_LXSESSION", False ); fd = ConnectionNumber(dpy); /* fd of XDisplay connection */ if( G_UNLIKELY(fd == -1) ) return FALSE; /* set up main loop event source for XDisplay */ source = g_source_new (&event_funcs, sizeof(X11Source)); xsource = (X11Source*)source; xsource->poll_fd.fd = fd; xsource->poll_fd.events = G_IO_IN; g_source_add_poll(source, &xsource->poll_fd); g_source_set_can_recurse(source, TRUE); g_source_attach(source, NULL); return TRUE; }
void register_service (int port) { int dnsfd; GSource *source; if (DNSServiceRegister (&g_sdref, 0, 0, NULL, "_xmms2._tcp", NULL, NULL, g_htons (port), 0, NULL, dns_callback, NULL) != kDNSServiceErr_NoError) { printf ("failed to register!\n"); exit (1); } dnsfd = DNSServiceRefSockFD (g_sdref); if (dnsfd == -1) { printf ("no fd!?\n"); exit (1); } pollfd = g_new0 (GPollFD, 1); pollfd->fd = dnsfd; pollfd->events = G_IO_IN | G_IO_HUP | G_IO_ERR; source = g_source_new (&dns_ipc_func, sizeof (GSource)); g_source_add_poll (source, pollfd); g_source_attach (source, NULL); }
/* * Create a event source object for connection. The object * will be added to "Event Context" for polling. */ __export HmWatch * hm_listen_watch_create(HmConnection *conn, HmWatchFuncs *funcs, gint size) { GSource *source; HmWatch *watch; G_ASSERT(conn != NULL && funcs != NULL && size >= sizeof(HmWatch)); source = g_source_new(&hm_watch_funcs, size); watch = (HmWatch*)source; watch->buffer = NULL; watch->lock = g_mutex_new(); watch->conn = conn; watch->funcs = funcs; watch->r_fd.fd = hm_connection_get_fd(conn); watch->r_fd.events = READ_COND; watch->r_fd.revents = 0; hm_watch_init_time(watch); watch->w_pending = 0; watch->killed = 0; watch->heavy_io_load = hm_connection_is_heavy(conn); watch->block_size = hm_connection_get_buffer_size(conn); hm_watch_set_callback(watch, hm_watch_listen_dispatch, NULL); g_source_add_poll(source, &watch->r_fd); g_atomic_int_add(&total_watch_count, 1); return watch; }
static gboolean g_mdns_poll_add (GMDNS *mdns, GMDNSUserData *ud, DNSServiceRef client) { ud->fd = g_new0 (GPollFD, 1); ud->fd->fd = DNSServiceRefSockFD (client); ud->client = client; ud->mdns = mdns; if (ud->fd->fd == -1) { g_free (ud->fd); g_free (ud); return FALSE; } ud->fd->events = G_IO_IN | G_IO_HUP | G_IO_ERR; ud->source = g_source_new (&g_mdns_poll_funcs, sizeof (GSource)); g_source_set_callback (ud->source, (GSourceFunc) g_mdns_source_dispatch, ud, NULL); g_source_add_poll (ud->source, ud->fd); g_source_attach (ud->source, NULL); return TRUE; }
static GSource * g_io_unix_create_watch (GIOChannel *channel, GIOCondition condition) { GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel; GSource *source; GIOUnixWatch *watch; source = g_source_new (&g_io_watch_funcs, sizeof (GIOUnixWatch)); g_source_set_name (source, "GIOChannel (Unix)"); watch = (GIOUnixWatch *)source; watch->channel = channel; g_io_channel_ref (channel); watch->condition = condition; watch->pollfd.fd = unix_channel->fd; watch->pollfd.events = condition; g_source_add_poll (source, &watch->pollfd); return source; }
GSource * _g_fd_source_new_with_object (GObject *object, int fd, gushort events, GCancellable *cancellable) { GSource *source; FDSource *fd_source; source = g_source_new (&fd_source_funcs, sizeof (FDSource)); fd_source = (FDSource *)source; if (cancellable) fd_source->cancellable = g_object_ref (cancellable); if (object) fd_source->object = g_object_ref (object); fd_source->pollfd.fd = fd; fd_source->pollfd.events = events; g_source_add_poll (source, &fd_source->pollfd); if (cancellable) fd_source->cancelled_tag = g_signal_connect_data (cancellable, "cancelled", (GCallback)fd_source_cancelled_cb, NULL, NULL, 0); return source; }
GSource * _g_posix_signal_source_new (gint signum) { sigset_t sigset; gint fd; GSource *_source; _GPosixSignalSource *source; _source = NULL; sigemptyset (&sigset); sigaddset (&sigset, signum); if (sigprocmask (SIG_BLOCK, &sigset, NULL) == -1) g_assert_not_reached (); fd = signalfd (-1, &sigset, SFD_NONBLOCK | SFD_CLOEXEC); _source = g_source_new (&_g_posix_signal_source_funcs, sizeof (_GPosixSignalSource)); source = (_GPosixSignalSource *) _source; source->pollfd.fd = fd; source->pollfd.events = G_IO_IN; g_source_add_poll (_source, &source->pollfd); source->signum = signum; return _source; }
ViewBackend::ViewBackend(struct wpe_view_backend* backend) : backend(backend) { ipcHost.initialize(*this); bcm_host_init(); displayHandle = vc_dispmanx_display_open(0); graphics_get_display_size(DISPMANX_ID_HDMI, &width, &height); updateFd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (updateFd == -1) { fprintf(stderr, "ViewBackend: failed to create the update eventfd\n"); return; } updateSource = g_source_new(&UpdateSource::sourceFuncs, sizeof(UpdateSource)); auto& source = *reinterpret_cast<UpdateSource*>(updateSource); source.backend = this; source.pfd.fd = updateFd; source.pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; source.pfd.revents = 0; g_source_add_poll(updateSource, &source.pfd); g_source_set_name(updateSource, "[WPE] BCMRPi update"); g_source_set_priority(updateSource, G_PRIORITY_HIGH + 30); g_source_set_can_recurse(updateSource, TRUE); g_source_attach(updateSource, g_main_context_get_thread_default()); }
GSource * gdk_x11_event_source_new (GdkDisplay *display) { GSource *source; GdkEventSource *event_source; GdkX11Display *display_x11; int connection_number; char *name; source = g_source_new (&event_funcs, sizeof (GdkEventSource)); name = g_strdup_printf ("GDK X11 Event source (%s)", gdk_display_get_name (display)); g_source_set_name (source, name); g_free (name); event_source = (GdkEventSource *) source; event_source->display = display; display_x11 = GDK_X11_DISPLAY (display); connection_number = ConnectionNumber (display_x11->xdisplay); event_source->event_poll_fd.fd = connection_number; event_source->event_poll_fd.events = G_IO_IN; g_source_add_poll (source, &event_source->event_poll_fd); g_source_set_priority (source, GDK_PRIORITY_EVENTS); g_source_set_can_recurse (source, TRUE); g_source_attach (source, NULL); event_sources = g_list_prepend (event_sources, source); return source; }
static __inline__ gint __hm_watch_write_message(HmWatch *watch, gpointer msg) { gchar packet[MAX_IO_BUFFER_SIZE]; gint ret = 0, pending = 0; HmWatchFuncs *funcs; funcs = watch->funcs; BUG_ON(!funcs); if (funcs->format) /* if !funcs->format, return 0 */ { ret = (*funcs->format)(watch, msg, packet, MAX_IO_BUFFER_SIZE); if (ret > 0) { ret = hm_net_buf_write(watch->buffer, packet, ret, watch, &pending); if (!ret) { #ifdef __HANDLE_SENDING_FAIL_EVENT hm_print( "Net watch '%p' snd buffer full, drop 1 packet.", watch ); g_source_destroy((GSource*)watch); __hm_watch_error(watch, 1, -E_SNDBUFFULL); #endif } else if (ret < 0) { hm_print( "Net IO '%p' send failed.", NET_IO(watch) ); g_source_destroy((GSource*)watch); __hm_watch_error(watch, 1, ret); } else { if (pending && !watch->w_pending) { watch->w_fd.revents = 0; g_source_add_poll((GSource*)watch, &watch->w_fd); watch->w_pending = 1; } } } else { hm_print( "Net format packet failed while sending, drop." ); } } return ret; }
void mdm_wm_init (Window login_window) { XWindowAttributes attribs = { 0, }; GSource *source; gchar *display; wm_login_window = login_window; if (wm_disp != NULL) { return; } display = gdk_get_display (); wm_disp = XOpenDisplay (display); g_free (display); if (wm_disp == NULL) { /* EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEK! */ wm_disp = GDK_DISPLAY (); return; } trap_push (); XA_WM_PROTOCOLS = XInternAtom (wm_disp, "WM_PROTOCOLS", False); XA_WM_STATE = XInternAtom (wm_disp, "WM_STATE", False); XA_WM_TAKE_FOCUS = XInternAtom (wm_disp, "WM_TAKE_FOCUS", False); XA_COMPOUND_TEXT = XInternAtom (wm_disp, "COMPOUND_TEXT", False); XA_NET_WM_STRUT = XInternAtom (wm_disp, "_NET_WM_STRUT", False); wm_root = DefaultRootWindow (wm_disp); /* set event mask for events on root window */ XGetWindowAttributes (wm_disp, wm_root, &attribs); XSelectInput (wm_disp, wm_root, attribs.your_event_mask | SubstructureNotifyMask | SubstructureRedirectMask); if (trap_pop () != 0) return; trap_push (); add_all_current_windows (); source = g_source_new (&event_funcs, sizeof (GSource)); event_poll_fd.fd = ConnectionNumber (wm_disp); event_poll_fd.events = G_IO_IN; g_source_add_poll (source, &event_poll_fd); g_source_set_priority (source, GDK_PRIORITY_EVENTS); g_source_set_can_recurse (source, FALSE); g_source_attach (source, NULL); trap_pop (); }
/** Deregister a su_wait_t object. * * The function su_source_deregister() deregisters a su_wait_t registrattion. * The wait object, a callback function and a argument are removed from the * port object. * * @param self - pointer to port object * @param i - registration index * * @return Index of the wait object, or -1 upon an error. */ int su_source_deregister(su_port_t *self, int i) { unsigned j, n, N; unsigned I, *indices; su_wait_t wait[1]; enter; assert(self); assert(SU_SOURCE_OWN_THREAD(self)); if (i <= 0) return -1; N = self->sup_n_waits; I = self->sup_max_index; indices = self->sup_indices; assert((unsigned)i < I + 1); n = indices[i - 1]; if (n == UINT_MAX) return -1; self->sup_n_waits = N = N - 1; wait[0] = self->sup_waits[n]; g_source_remove_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]); if (n < N) for (j = 0; j < I; j++) if (self->sup_indices[j] != UINT_MAX && self->sup_indices[j] > n) self->sup_indices[j]--; for (; n < N; n++) { g_source_remove_poll(self->sup_source, (GPollFD*)&self->sup_waits[n + 1]); self->sup_waits[n] = self->sup_waits[n+1]; g_source_add_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]); self->sup_wait_cbs[n] = self->sup_wait_cbs[n+1]; self->sup_wait_args[n] = self->sup_wait_args[n+1]; self->sup_wait_roots[n] = self->sup_wait_roots[n+1]; } indices[i - 1] = UINT_MAX; if ((unsigned)i == I) self->sup_max_index--; su_wait_destroy(wait); self->sup_registers++; return (int)i; }
void monkey_prepare_input(void) { MonkeySource *gs = (MonkeySource *)g_source_new(&monkey_source_funcs, sizeof *gs); gs->pf.fd = 0; gs->pf.events = G_IO_IN | G_IO_ERR; g_source_add_poll((GSource *)gs, &gs->pf); g_source_attach((GSource *)gs, NULL); }