ssize_t vlc_tls_Write(vlc_tls_t *session, const void *buf, size_t len) { struct pollfd ufd; ufd.fd = session->fd; ufd.events = POLLOUT; for (size_t sent = 0;;) { if (vlc_killed()) { errno = EINTR; return -1; } ssize_t val = session->send(session, buf, len); if (val > 0) { buf = ((const char *)buf) + val; len -= val; sent += val; } if (len == 0 || val == 0) return sent; if (val == -1 && errno != EINTR && errno != EAGAIN) return sent ? (ssize_t)sent : -1; vlc_poll_i11e(&ufd, 1, -1); } }
static int vlc_rpc_mainloop(access_t *p_access, struct rpc_context *p_rpc_ctx, bool (*pf_until_cb)(access_t *)) { access_sys_t *p_sys = p_access->p_sys; while (!p_sys->b_error && !pf_until_cb(p_access)) { struct pollfd p_fds[1]; int i_ret; p_fds[0].fd = rpc_get_fd(p_rpc_ctx); p_fds[0].events = rpc_which_events(p_rpc_ctx); if ((i_ret = vlc_poll_i11e(p_fds, 1, -1)) < 0) { if (errno == EINTR) msg_Warn(p_access, "vlc_poll_i11e interrupted"); else msg_Err(p_access, "vlc_poll_i11e failed"); p_sys->b_error = true; } else if (i_ret > 0 && p_fds[0].revents && rpc_service(p_rpc_ctx, p_fds[0].revents) < 0) { msg_Err(p_access, "nfs_service failed"); p_sys->b_error = true; } } return p_sys->b_error ? -1 : 0; }
ssize_t vlc_tls_Read(vlc_tls_t *session, void *buf, size_t len, bool waitall) { struct pollfd ufd; ufd.fd = session->fd; ufd.events = POLLIN; for (size_t rcvd = 0;;) { if (vlc_killed()) { errno = EINTR; return -1; } ssize_t val = session->recv(session, buf, len); if (val > 0) { if (!waitall) return val; buf = ((char *)buf) + val; len -= val; rcvd += val; } if (len == 0 || val == 0) return rcvd; if (val == -1 && errno != EINTR && errno != EAGAIN) return rcvd ? (ssize_t)rcvd : -1; vlc_poll_i11e(&ufd, 1, -1); } }
/* Wait for data */ static int AccessPoll (access_t *access) { access_sys_t *sys = access->p_sys; struct pollfd ufd; ufd.fd = sys->fd; ufd.events = POLLIN; return vlc_poll_i11e (&ufd, 1, -1); }
/** * Reads TS data from the tuner. * @return number of bytes read, 0 on EOF, -1 if no data (yet). */ ssize_t dvb_read (dvb_device_t *d, void *buf, size_t len, int ms) { struct pollfd ufd[2]; int n; if (d->cam != NULL) en50221_Poll (d->cam); ufd[0].fd = d->demux; ufd[0].events = POLLIN; if (d->frontend != -1) { ufd[1].fd = d->frontend; ufd[1].events = POLLPRI; n = 2; } else n = 1; errno = 0; n = vlc_poll_i11e (ufd, n, ms); if (n == 0) errno = EAGAIN; if (n <= 0) return -1; if (d->frontend != -1 && ufd[1].revents) { struct dvb_frontend_event ev; if (ioctl (d->frontend, FE_GET_EVENT, &ev) < 0) { if (errno == EOVERFLOW) { msg_Err (d->obj, "cannot dequeue events fast enough!"); return -1; } msg_Err (d->obj, "cannot dequeue frontend event: %s", vlc_strerror_c(errno)); return 0; } dvb_frontend_status(d->obj, ev.status); } if (ufd[0].revents) { ssize_t val = read (d->demux, buf, len); if (val == -1 && (errno != EAGAIN && errno != EINTR)) { if (errno == EOVERFLOW) { msg_Err (d->obj, "cannot demux data fast enough!"); return -1; } msg_Err (d->obj, "cannot demux: %s", vlc_strerror_c(errno)); return 0; } return val; } return -1; }
static int ScanReadCallback( scan_t *p_scan, void *p_privdata, unsigned i_probe_timeout, size_t i_packets_max, uint8_t *p_packet, size_t *pi_count ) { access_t *p_access = (access_t *) p_privdata; access_sys_t *p_sys = p_access->p_sys; *pi_count = 0; /* Initialize file descriptor sets */ struct pollfd ufds[2]; ufds[0].fd = p_sys->dvb.i_handle; ufds[0].events = POLLIN; ufds[1].fd = p_sys->dvb.i_frontend_handle; ufds[1].events = POLLPRI; frontend_status_t status; FrontendGetStatus( &p_sys->dvb, &status ); bool b_has_lock = status.b_has_lock; mtime_t i_scan_start = mdate(); for( ; *pi_count == 0; ) { /* Find if some data is available */ int i_ret; mtime_t i_timeout = b_has_lock ? i_probe_timeout: DVB_SCAN_MAX_LOCK_TIME; do { mtime_t i_poll_timeout = i_scan_start - mdate() + i_timeout; i_ret = 0; if( vlc_killed() || scan_IsCancelled( p_scan ) ) break; if( i_poll_timeout >= 0 ) i_ret = vlc_poll_i11e( ufds, 2, i_poll_timeout / 1000 ); } while( i_ret < 0 && errno == EINTR ); if( i_ret < 0 ) { return VLC_EGENERIC; } else if( i_ret == 0 ) { return VLC_ENOITEM; } if( ufds[1].revents ) { FrontendPoll( VLC_OBJECT(p_access), &p_sys->dvb ); FrontendGetStatus( &p_sys->dvb, &status ); if( status.b_has_lock && !b_has_lock ) { i_scan_start = mdate(); b_has_lock = true; } } if ( ufds[0].revents ) { ssize_t i_read = read( p_sys->dvb.i_handle, p_packet, TS_PACKET_SIZE * i_packets_max ); if( i_read < 0 ) { msg_Warn( p_access, "read failed: %s", vlc_strerror_c(errno) ); break; } else { *pi_count = i_read / TS_PACKET_SIZE; } } } return VLC_SUCCESS; }
static DBusMessage* vlc_dbus_send_message( vlc_keystore* p_keystore, DBusMessage* p_msg ) { vlc_keystore_sys *p_sys = p_keystore->p_sys; DBusMessage *p_repmsg = NULL; DBusPendingCall *p_pending_call = NULL; struct vlc_dbus_watch_data watch_ctx[MAX_WATCHES] = {}; for( unsigned i = 0; i < MAX_WATCHES; ++i ) watch_ctx[i].pollfd.fd = -1; if( !dbus_connection_set_watch_functions( p_sys->connection, vlc_dbus_watch_add_function, NULL, vlc_dbus_watch_toggled_function, watch_ctx, NULL ) ) return NULL; if( !dbus_connection_send_with_reply( p_sys->connection, p_msg, &p_pending_call, DBUS_TIMEOUT_INFINITE ) ) goto end; if( !dbus_pending_call_set_notify( p_pending_call, vlc_dbus_pending_call_notify, &p_repmsg, NULL ) ) goto end; while( p_repmsg == NULL ) { errno = 0; struct pollfd pollfds[MAX_WATCHES]; int nfds = 0; for( unsigned i = 0; i < MAX_WATCHES; ++i ) { if( watch_ctx[i].pollfd.fd == -1 ) break; pollfds[i].fd = watch_ctx[i].pollfd.fd; pollfds[i].events = watch_ctx[i].pollfd.events; pollfds[i].revents = 0; nfds++; } if( nfds == 0 ) { msg_Err( p_keystore, "vlc_dbus_send_message: watch functions not called" ); goto end; } if( vlc_poll_i11e( pollfds, nfds, -1 ) <= 0 ) { if( errno == EINTR ) msg_Dbg( p_keystore, "vlc_dbus_send_message: poll was interrupted" ); else msg_Err( p_keystore, "vlc_dbus_send_message: poll failed" ); goto end; } for( int i = 0; i < nfds; ++ i ) { short i_events = pollfds[i].revents; if( !i_events ) continue; unsigned i_flags = 0; if( i_events & POLLIN ) i_flags |= DBUS_WATCH_READABLE; if( i_events & POLLOUT ) i_flags |= DBUS_WATCH_WRITABLE; if( i_events & POLLHUP ) i_flags |= DBUS_WATCH_HANGUP; if( i_events & POLLERR ) i_flags |= DBUS_WATCH_ERROR; if( !dbus_watch_handle( watch_ctx[i].p_watch, i_flags ) ) goto end; } DBusDispatchStatus status; while( ( status = dbus_connection_dispatch( p_sys->connection ) ) == DBUS_DISPATCH_DATA_REMAINS ); if( status == DBUS_DISPATCH_NEED_MEMORY ) goto end; } end: dbus_connection_set_watch_functions( p_sys->connection, NULL, NULL, NULL, NULL, NULL ); if( p_pending_call != NULL ) { if( p_repmsg != NULL ) dbus_pending_call_cancel( p_pending_call ); dbus_pending_call_unref( p_pending_call ); } return p_repmsg; }