/** * Initialize the driver. * * Always succeeds, so never returns NULL. */ static gpointer tx_link_init(txdrv_t *tx, gpointer args) { struct tx_link_args *targs = args; struct attr *attr; g_assert(tx); g_assert(targs->cb != NULL); WALLOC(attr); /* * Because we handle servicing of the upper layers explicitely within * the TX stack (i.e. upper layers detect that we were unable to comply * with the whole write and enable us), there is no I/O callback attached * to the I/O source: we only create it to benefit from bandwidth limiting * through calls to bio_write() and bio_writev(). */ attr->cb = targs->cb; attr->wio = targs->wio; attr->bio = bsched_source_add(targs->bws, attr->wio, BIO_F_WRITE, NULL, NULL); tx->opaque = attr; g_assert(attr->wio->write != NULL); g_assert(attr->wio->writev != NULL); return tx; /* OK */ }
/** * Update the socket-related information in the UDP scheduler. */ void udp_sched_update_sockets(udp_sched_t *us) { uint i; bio_source_t *bio = NULL; udp_sched_clear_sockets(us); for (i = 0; i < N_ITEMS(us->bio); i++) { gnutella_socket_t *s = (*us->get_socket)(udp_sched_net_type[i]); if (s != NULL) { struct wrap_io *wio = &s->wio; wrap_io_check(wio); g_assert(wio->sendto != NULL); us->bio[i] = bsched_source_add( us->bws, wio, BIO_F_WRITE, NULL, NULL); if (NULL == bio) bio = us->bio[i]; /* Remember first I/O source seen */ } } /* * Make sure we are informed about the start of each bandwidth scheduling * periods so that we may schedule data out and expire old data. * * We just need one of the IPv4 or IPv6 I/O source since they are linked * to the same bandwidth scheduler. */ if (bio != NULL) bio_add_passive_callback(bio, udp_sched_begin, us); }