5.11 Ports
(require ffi/unsafe/port) | package: base |
Added in version 6.11.0.4 of package base.
procedure
(unsafe-file-descriptor->port fd name mode)
→ (or/c port? (values input-port? output-port?)) fd : exact-integer? name : any/c mode : (listof (or/c 'read 'write 'text 'regular-file))
procedure
(unsafe-socket->port socket name mode) →
input-port? output-port? socket : exact-integer? name : bytes? mode : (listof (or/c 'no-close))
The name argument determines the port’s name as reported by object-name. The name must be a UTF-8 encoding that is converted to a symbol for the socket name.
For a file descriptor, the mode list must include at least one of 'read or 'write, and two ports are returned if mode includes both 'read and 'write. The 'text mode affects only Windows ports. The 'regular-file mode indicates that the file descriptor corresponds to a regular file (which has the property, for example, that reading never blocks). Closing all returned file-descriptor ports closes the file descriptor.
For a socket, the mode list can include 'no-close, in which case closing both of the returned ports does not close the socket.
For any kind of result port, closing the resulting ports readies and unregisters any semaphores for the file descriptor or socket that were previously created with unsafe-file-descriptor->semaphore or unsafe-socket->semaphore.
procedure
(unsafe-port->file-descriptor p) → (or/c exact-integer? #f)
p : port?
procedure
(unsafe-port->socket p) → (or/c exact-integer? #f)
p : port?
On Unix and Mac OS, the result of unsafe-port->file-descriptor can be #f if it corresponds to a port that is waiting for its peer as reported by port-waiting-peer?, such as the write end of a fifo where no reader is connected. Wait until such is ready by using sync).
Changed in version 7.4.0.5 of package base: Accommodate a fifo write end blocked on a reader by returning #f.
procedure
(unsafe-file-descriptor->semaphore fd mode)
→ (or/c semaphore? #f) fd : exact-integer? mode : (or/c 'read 'write 'check-read 'check-write 'remove)
procedure
(unsafe-socket->semaphore socket mode) → (or/c semaphore? #f)
socket : exact-integer? mode : (or/c 'read 'write 'check-read 'check-write 'remove)
fd or socket is ready for reading or writing (depending on mode),
ports were created from fd or socket using unsafe-file-descriptor->port or unsafe-socket->port, and those ports were closed, or
a subsequent call occurred with the same fd or socket and with 'remove for mode.
The result is #f if a conversion to a semaphore is not supported for the current platform or for the given file descriptor or socket.
The 'check-read and 'check-write modes are like 'read and 'write, but the result if #f if a semaphore is not already generated for the specified file descriptor or socket in the specified mode.
The 'remove mode readies and unregisters any semaphores previously created for the given file descriptor or socket. Semaphores must be unregistered before the file descriptor or socket is closed. Beware that closing a port from unsafe-file-descriptor->port or unsafe-socket->port will also ready and unregister semaphores. In all of those cases, however, the semaphore is made ready asynchronously, so there may be a detectable delay.
procedure
(unsafe-fd->evt fd mode [socket?]) → (or/c evt? #f)
fd : exact-integer? mode : (or/c 'read 'write 'check-read 'check-write 'remove) socket? : any/c = #t
fd is ready for reading or writing (depending on mode),
a subsequent call occurred with the same fd and with 'remove for mode (once removed, the event is perpetually ready).
The synchronization result of the event is the event itself.
The 'check-read and 'check-write modes are like 'read and 'write, but the result is #f if an event is not already generated for the specified file descriptor or socketin the specified mode.
The 'remove mode readies and unregisters any events
previously created for the given file descriptor or socket. Events
must be unregistered before the file descriptor or socket is
closed. Unlike the semaphore result of unsafe-file-descriptor->semaphore and
unsafe-socket->semaphore, the event result of
unsafe-fd->evt is not triggered or unregistered by closing a port—
Added in version 7.2.0.6 of package base.