/** * Deliver datagram * * @v intf Data transfer interface * @v iobuf Datagram I/O buffer * @v meta Data transfer metadata * @ret rc Return status code */ int xfer_deliver ( struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta ) { struct interface *dest; xfer_deliver_TYPE ( void * ) *op = intf_get_dest_op ( intf, xfer_deliver, &dest ); void *object = intf_object ( dest ); int rc; DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " deliver %zd\n", INTF_INTF_DBG ( intf, dest ), iob_len ( iobuf ) ); if ( op ) { rc = op ( object, iobuf, meta ); } else { /* Default is to discard the I/O buffer */ free_iob ( iobuf ); rc = -EPIPE; } if ( rc != 0 ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " deliver failed: %s\n", INTF_INTF_DBG ( intf, dest ), strerror ( rc ) ); } intf_put ( dest ); return rc; }
/** * Allocate I/O buffer * * @v intf Data transfer interface * @v len I/O buffer payload length * @ret iobuf I/O buffer */ struct io_buffer * xfer_alloc_iob ( struct interface *intf, size_t len ) { struct interface *dest; xfer_alloc_iob_TYPE ( void * ) *op = intf_get_dest_op ( intf, xfer_alloc_iob, &dest ); void *object = intf_object ( dest ); struct io_buffer *iobuf; DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob %zd\n", INTF_INTF_DBG ( intf, dest ), len ); if ( op ) { iobuf = op ( object, len ); } else { /* Default is to allocate an I/O buffer with no * reserved space. */ iobuf = alloc_iob ( len ); } if ( ! iobuf ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob " "failed\n", INTF_INTF_DBG ( intf, dest ) ); } intf_put ( dest ); return iobuf; }
/** * Plug an object interface into a new destination object interface * * @v intf Object interface * @v dest New destination object interface * * The reference to the existing destination interface is dropped, a * reference to the new destination interface is obtained, and the * interface is updated to point to the new destination interface. * * Note that there is no "unplug" call; instead you must plug the * interface into a null interface. */ void intf_plug ( struct interface *intf, struct interface *dest ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " replug to " INTF_FMT "\n", INTF_INTF_DBG ( intf, intf->dest ), INTF_DBG ( dest ) ); intf_get ( dest ); intf_put ( intf->dest ); intf->dest = dest; }
/** * Send redirection event * * @v intf Data transfer interface * @v type New location type * @v args Remaining arguments depend upon location type * @ret rc Return status code */ int xfer_vredirect ( struct interface *intf, int type, va_list args ) { struct interface tmp = INTF_INIT ( null_intf_desc ); struct interface *dest; xfer_vredirect_TYPE ( void * ) *op = intf_get_dest_op_no_passthru ( intf, xfer_vredirect, &dest ); void *object = intf_object ( dest ); int rc; DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect\n", INTF_INTF_DBG ( intf, dest ) ); if ( op ) { rc = op ( object, type, args ); } else { /* Default is to reopen the interface as instructed, * then send xfer_window_changed() messages to both * new child and parent interfaces. Since our * original child interface is likely to be closed and * unplugged as a result of the call to * xfer_vreopen(), we create a temporary interface in * order to be able to send xfer_window_changed() to * the parent. */ intf_plug ( &tmp, dest ); rc = xfer_vreopen ( dest, type, args ); if ( rc == 0 ) { xfer_window_changed ( dest ); xfer_window_changed ( &tmp ); } intf_unplug ( &tmp ); } if ( rc != 0 ) { DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect " "failed: %s\n", INTF_INTF_DBG ( intf, dest ), strerror ( rc ) ); } intf_put ( dest ); return rc; }
/** * Name resolved * * @v intf Object interface * @v sa Completed socket address (if successful) */ void resolv_done ( struct interface *intf, struct sockaddr *sa ) { struct interface *dest; resolv_done_TYPE ( void * ) *op = intf_get_dest_op ( intf, resolv_done, &dest ); void *object = intf_object ( dest ); DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " resolv_done\n", INTF_INTF_DBG ( intf, dest ) ); if ( op ) { op ( object, sa ); } else { /* Default is to ignore resolutions */ } intf_put ( dest ); }
/** * Close an object interface * * @v intf Object interface * @v rc Reason for close * * Note that this function merely informs the destination object that * the interface is about to be closed; it doesn't actually disconnect * the interface. In most cases, you probably want to use * intf_shutdown() or intf_restart() instead. */ void intf_close ( struct interface *intf, int rc ) { struct interface *dest; intf_close_TYPE ( void * ) *op = intf_get_dest_op ( intf, intf_close, &dest ); void *object = intf_object ( dest ); DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " close (%s)\n", INTF_INTF_DBG ( intf, dest ), strerror ( rc ) ); if ( op ) { op ( object, rc ); } else { /* Default is to ignore intf_close() */ } intf_put ( dest ); }