Next: , Previous: , Up: srfi basic-socket spec   [Index]


2.34.3.4 Port conversion

The following bindings are exported by the libraries (srfi :106) and (srfi :106 socket).

Function: socket-input-port socket
Function: socket-output-port socket

Return a fresh binary input or output port associated with a socket, respectively. Whenever the returned port is closed: the associated socket must not be closed along.

For Vicare: it is fine to use transcoded-port from (rnrs io ports (6)) to put a textual port on top of the returned binary ports. Example:

(import (vicare)
  (prefix (srfi :106) srfi.))

(with-compensations
  (define socket
    (compensate
        (srfi.make-client-socket "reddit.com" "http")
      (with
       (srfi.socket-shutdown socket
         (srfi.shutdown-method read write))
       (srfi.socket-close socket))))

  (define in-port
    (compensate
        (transcoded-port (srfi.socket-input-port socket)
                         (native-transcoder))
      (with
       (close-port in-port))))

  (define ou-port
    (compensate
        (transcoded-port (srfi.socket-output-port socket)
                         (native-transcoder))
      (with
       (close-port ou-port))))

  ---)

It is also fine to use the returned ports as port argument to the functions select-port, select-port-readable?, select-port-writable?, select-port-exceptional?.