您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <stddef.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <gpxe/refcnt.h>
  6. #include <gpxe/process.h>
  7. #include <gpxe/xfer.h>
  8. #include <gpxe/open.h>
  9. /** @file
  10. *
  11. * "Hello World" data source
  12. *
  13. */
  14. struct hw {
  15. struct refcnt refcnt;
  16. struct xfer_interface xfer;
  17. struct process process;
  18. };
  19. static const char hw_msg[] = "Hello world!\n";
  20. static void hw_finished ( struct hw *hw, int rc ) {
  21. xfer_nullify ( &hw->xfer );
  22. xfer_close ( &hw->xfer, rc );
  23. process_del ( &hw->process );
  24. }
  25. static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
  26. struct hw *hw = container_of ( xfer, struct hw, xfer );
  27. hw_finished ( hw, rc );
  28. }
  29. static struct xfer_interface_operations hw_xfer_operations = {
  30. .close = hw_xfer_close,
  31. .vredirect = ignore_xfer_vredirect,
  32. .window = unlimited_xfer_window,
  33. .alloc_iob = default_xfer_alloc_iob,
  34. .deliver_iob = xfer_deliver_as_raw,
  35. .deliver_raw = ignore_xfer_deliver_raw,
  36. };
  37. static void hw_step ( struct process *process ) {
  38. struct hw *hw = container_of ( process, struct hw, process );
  39. int rc;
  40. if ( xfer_window ( &hw->xfer ) ) {
  41. rc = xfer_deliver_raw ( &hw->xfer, hw_msg, sizeof ( hw_msg ) );
  42. hw_finished ( hw, rc );
  43. }
  44. }
  45. static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
  46. struct hw *hw;
  47. /* Allocate and initialise structure */
  48. hw = zalloc ( sizeof ( *hw ) );
  49. if ( ! hw )
  50. return -ENOMEM;
  51. xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
  52. process_init ( &hw->process, hw_step, &hw->refcnt );
  53. /* Attach parent interface, mortalise self, and return */
  54. xfer_plug_plug ( &hw->xfer, xfer );
  55. ref_put ( &hw->refcnt );
  56. return 0;
  57. }
  58. struct uri_opener hw_uri_opener __uri_opener = {
  59. .scheme = "hw",
  60. .open = hw_open,
  61. };