13.1.2 Managing Ports

► |  | The Racket Reference

1 | Language Model
2 | Notation for Documentation
3 | Syntactic Forms
4 | Datatypes
5 | Structures
6 | Classes and Objects
7 | Units
8 | Contracts
9 | Pattern Matching
10 | Control Flow
11 | Concurrency and Parallelism
12 | Macros
13 | Input and Output
14 | Reflection and Security
15 | Operating System
16 | Memory Management
17 | Unsafe Operations
18 | Running Racket
| Bibliography
| Index

► | 13 | Input and Output

13.1 | Ports
13.2 | Byte and String Input
13.3 | Byte and String Output
13.4 | Reading
13.5 | Writing
13.6 | Pretty Printing
13.7 | Reader Extension
13.8 | Printer Extension
13.9 | Serialization
13.10 | Fast-Load Serialization
13.11 | Cryptographic Hashing

▼ | 13.1 | Ports

13.1.1 | Encodings and Locales
13.1.2 | Managing Ports
13.1.3 | Port Buffers and Positions
13.1.4 | Counting Positions, Lines, and Columns
13.1.5 | File Ports
13.1.6 | String Ports
13.1.7 | Pipes
13.1.8 | Structures as Ports
13.1.9 | Custom Ports
13.1.10 | More Port Constructors, Procedures, and Events

On this page:

input-port?
output-port?
port?
close-input-port
close-output-port
port-closed?
port-closed-evt
current-input-port
current-output-port
current-error-port
file-stream-port?
terminal-port?
port-waiting-peer?
eof
eof-object?

Racket
top contents ← prev up next →

#### 13.1.2 Managing Ports🔗ℹ

> procedure (input-port? v) → boolean?
> v : any/c

Returns #t if v is an input port, #f otherwise.

> procedure (output-port? v) → boolean?
> v : any/c

Returns #t if v is an output port, #f otherwise.

> procedure (port? v) → boolean?
> v : any/c

Returns #t if either (input-port? v) or (output-port? v) is #t, #f otherwise.

> procedure (close-input-port in) → void?
> in : input-port?

Closes the input port in. For some kinds of ports, closing the port releases lower-level resources, such as a file handle. If the port is already closed, close-input-port has no effect.

> procedure (close-output-port out) → void?
> out : output-port?

Closes the output port out. For some kinds of ports, closing the port releases lower-level resources, such as a file handle. Also, if the port is buffered, closing may first flush the port before closing it, and this flushing process can block. If the port is already closed, close-output-port has no effect.

> procedure (port-closed? port) → boolean?
> port : port?

Returns #t if the input or output port port is closed, #f otherwise.

> procedure (port-closed-evt port) → evt?
> port : port?

Return a synchronizable event that becomes ready for synchronization when port is closed. The synchronization result of a port-closed event is the port-closed event itself.

> parameter (current-input-port) → input-port?
> (current-input-port in) → void?
> in : input-port?

A parameter that determines a default input port for many operations, such as read.

> parameter (current-output-port) → output-port?
> (current-output-port out) → void?
> out : output-port?

A parameter that determines a default output port for many operations, such as write.

> parameter (current-error-port) → output-port?
> (current-error-port out) → void?
> out : output-port?

A parameter that determines an output port that is typically used for errors and logging. For example, the default error display handler writes to this port.

> procedure (file-stream-port? v) → boolean?
> v : any/c

Returns #t if v is a file-stream port (see File Ports), #f otherwise.

Changed in version 7.2.0.5 of package base: Extended file-stream-port? to any value, instead of resticting the domain to ports

> procedure (terminal-port? v) → boolean?
> v : any/c

Returns #t if v is a port that is attached to an interactive terminal, #f otherwise.

Changed in version 7.2.0.5 of package base: Extended terminal-port? to any value, instead of resticting the domain to ports

> procedure (port-waiting-peer? port) → boolean?
> port : port?

Returns #t if port is not ready for reading or writing because it is waiting for a peer process to complete a stream construction, #f otherwise.

On Unix and Mac OS, opening a fifo for output creates a peer-waiting port if no reader for the same fifo is already opened. In that case, the output port is not ready for writing until a reader is opened; that is, write opertaions will block. Use sync if necessary to wait until writing will not block—that is, until the read end of the fifo is opened.

Added in version 7.4.0.5 of package base.

> value eof : eof-object?

A value (distinct from all other values) that represents an end-of-file.

> procedure (eof-object? v) → boolean?
> v : any/c

Returns #t if v is eof, #f otherwise.
top contents ← prev up next →