ps-channel.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; This file contains the type declarations for the VM's interface to
  3. ; unbuffered i/o. Unbuffered ports are called channels in the VM
  4. ; and FD's in the OS. The external names are unixoid, but the interface
  5. ; itself is intended to be portable.
  6. (define current-input-channel
  7. (external "STDIN_FD" (=> () integer)))
  8. (define current-output-channel
  9. (external "STDOUT_FD" (=> () integer)))
  10. (define current-error-channel
  11. (external "STDERR_FD" (=> () integer)))
  12. ; Converting between ports and channels.
  13. ; Note that fileno is Unix only. The VM doesn't use these two
  14. ; anymore. If it ever does again, it will be necessary to rewrite
  15. ; their definitions.
  16. (define input-port->channel
  17. (external "fileno" (=> (input-port) integer)))
  18. (define output-port->channel
  19. (external "fileno" (=> (output-port) integer)))
  20. (define input-channel->port
  21. (external "PS_INPUT_FDOPEN" (=> (integer) input-port integer)))
  22. (define output-channel->port
  23. (external "PS_OUTPUT_FDOPEN" (=> (integer) output-port integer)))
  24. ; Opening and closing channels
  25. (define open-file-channel
  26. (external "ps_open_fd" (=> ((^ char) boolean) integer integer)))
  27. (define (open-input-file-channel name)
  28. (open-file-channel name #t))
  29. (define (open-output-file-channel name)
  30. (open-file-channel name #f))
  31. (define close-channel
  32. (external "ps_close_fd" (=> (integer) integer)))
  33. (define close-input-channel close-channel)
  34. (define close-output-channel close-channel)
  35. ; (channel-ready? channel read?)
  36. ; -> ready? status
  37. (define channel-ready?
  38. (external "ps_check_fd"
  39. (=> (integer boolean) boolean integer)))
  40. ; Read and writing blocks of data
  41. ;
  42. ; (channel-read-block channel buffer count wait?)
  43. ; -> char-count eof? pending? status
  44. ;
  45. ; (channel-write-block channel buffer count)
  46. ; -> char-count eof? pending? status
  47. ;
  48. ; CHAR-COUNT - the number of characters read/written
  49. ; EOF? - char-count is ignored if this is true
  50. ; PENDING? - true if the operation cannot complete immediately
  51. ; STATUS - from an enumeration defined as part of Pre-Scheme
  52. ;
  53. ; Pending i/o operations produce i/o-completion or i/o-error events
  54. ; when they're done.
  55. (define channel-read-block
  56. (external "ps_read_fd"
  57. (=> (integer address integer boolean) integer boolean boolean integer)))
  58. (define channel-write-block
  59. (external "ps_write_fd"
  60. (=> (integer address integer) integer boolean integer)))
  61. (define channel-buffer-size
  62. (external "ps_io_buffer_size" (=> () integer)))
  63. (define channel-crlf?
  64. (external "ps_io_crlf_p" (=> () boolean)))
  65. (define channel-console-encoding
  66. (external "ps_console_encoding" (=> (integer) (^ char))))
  67. (define channel-abort
  68. (external "ps_abort_fd_op" (=> (integer) integer)))
  69. ;----------------------------------------------------------------
  70. ; Asynchronous external events
  71. ; The different kinds of events
  72. ; The C code in event.h knows these, and there's a copy in s48-channel.scm.
  73. (define-external-enumeration events
  74. (keyboard-interrupt-event ; user interrupt
  75. io-completion-event ; a pending i/o operation completed
  76. io-error-event ; an i/o error occurred on a specific channel
  77. alarm-event ; scheduled interrupt
  78. os-signal-event ; some OS signal of no interest to the VM occured
  79. error-event ; OS error occurred
  80. external-event ; custom external event
  81. no-event ; no more pending events
  82. ))
  83. ; Initialize the event system
  84. (define initialize-events
  85. (external "interrupt_init" (=> () integer)))
  86. ; True if an event is pending
  87. (define pending-event?
  88. (external "pending_eventp" (=> () boolean)))
  89. ; Returns the next event. The second return value is the FD for
  90. ; i/o-completion or i/o error events and the third is the status for
  91. ; i/o-completion and error events.
  92. (define get-next-event
  93. (external "s48_get_next_event" (=> () integer integer integer)))
  94. ; Wait for the next event. The two arguments are maximum time to wait and
  95. ; whether that time is in minutes (#T) or milliseconds (#F).
  96. (define wait-for-event
  97. (external "s48_wait_for_event" (=> (integer boolean) unit)))