Skip to content

Commit d6ae062

Browse files
committed
Some Syntax and Consistency Changes, Chapter 13
1 parent d56673e commit d6ae062

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

chapters/io.asciidoc

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ The 'group_leader/2' function uses the 'group_leader' signal to set the group le
154154
true
155155
```
156156

157-
Understanding group leaders and the difference between the bif `display` and the function `io:format` will help you manage basic I/O in Erlang.
157+
Understanding group leaders and the difference between the BIF `display` and the function `io:format` will help you manage basic I/O in Erlang.
158158

159159
* `erlang:display/1`: A BIF that writes directly to the standard output, bypassing the Erlang I/O system.
160160

@@ -217,7 +217,7 @@ a large extent pretend that everything in the world behaves like
217217
an Erlang process and communicate through message passing.
218218

219219
Each port has an owner, more on this later, but all processes
220-
who know about the port can send messages to the port.
220+
that know about the port can send messages to the port.
221221
In the figure below we see how a process can communicate with the
222222
port and how the port is communicating to the world outside the
223223
Erlang node.
@@ -255,7 +255,7 @@ When a port terminates all external resources should also be cleaned
255255
up. This is true for all ports that come with Erlang and if you
256256
implement your own port you should make sure it does this cleanup.
257257

258-
==== Different types of Ports ====
258+
==== Different Types of Ports ====
259259

260260
There are three different classes of ports: file descriptors, external
261261
programs and drivers. A file descriptor port makes it possible for a
@@ -270,7 +270,7 @@ PortSettings)`.
270270
A file descriptor port is opened with `{fd, In, Out}` as the
271271
`PortName`. This class of ports is used by some internal ERTS servers
272272
like the old shell. They are considered to not be very efficient and
273-
hence seldom used. Also the filedescriptors are non negative integers
273+
hence seldom used. Also the file descriptors are non-negative integers
274274
representing open file descriptors in the OS. The file descriptor can
275275
not be an erlang I/O server.
276276

@@ -298,7 +298,7 @@ Erlang/OTP comes with a number port drivers implementing the
298298
predefined port types. There are the common drivers available on all
299299
platforms: `tcp_inet`, `udp_inet`, `sctp_inet`, `efile`, `zlib_drv`,
300300
`ram_file_drv`, `binary_filer`, `tty_sl`. These drivers are used to
301-
implement e.g. file handling and sockets in Erlang. On Windows there
301+
implement, e.g., file handling and sockets in Erlang. On Windows there
302302
is also a driver to access the registry: `registry_drv`. And on most
303303
platforms there are example drivers to use when implementing your own
304304
driver like: `multi_drv` and `sig_drv`.
@@ -322,7 +322,7 @@ Data sent to and from a port are byte streams. The packet size can be specified
322322

323323
Ports can be used to replace standard IO and polling. This is useful when you need to interact with external programs or devices. By opening a port to a file descriptor, you can read and write data to the file. Similarly, you can open a port to an external program and communicate with it using the port interface.
324324

325-
===== Ports to file descriptors =====
325+
===== Ports to File Descriptors =====
326326

327327
File descriptor ports in Erlang provide an interface to interact with already opened file descriptors. Although they are not commonly used due to efficiency concerns, they can provide an easy interface to external resources.
328328

@@ -352,10 +352,9 @@ The primary commands for interacting with a port include:
352352
* `{control, Operation, Data}`: Sends a control command to the external program.
353353
* `{exit_status, Status}`: Receives the exit status of the external program.
354354

355-
See xref:CH-C[] for examples of how to spawn an external program as a port,
356-
you can also look at the official documentation: link:https://www.erlang.org/doc/system/c_port.html#content[erlang.org:c_port].
355+
See xref:CH-C[] for examples of how to spawn an external program as a port. You can also look at the official documentation: link:https://www.erlang.org/doc/system/c_port.html#content[erlang.org:c_port].
357356

358-
===== Ports to Linked in Drivers =====
357+
===== Ports to Linked-in Drivers =====
359358

360359
Linked-in drivers in Erlang are created using the `open_port/2` function with the `{spawn_driver, Command}` tuple as the `PortName`. This method requires the first token of the command to be the name of a loaded driver.
361360

@@ -373,7 +372,7 @@ Example:
373372
Port ! {self(), {command, <<"Hello, Driver!\n">>}}.
374373
```
375374

376-
See xref:CH-C[] for examples of how to implement and spawn a linked in driver as a port, you can also look at the official documentation: link:https://www.erlang.org/doc/system/c_portdriver.html#content[erlang.org:c_portdriver].
375+
See xref:CH-C[] for examples of how to implement and spawn a linked in driver as a port. You can also look at the official documentation: link:https://www.erlang.org/doc/system/c_portdriver.html#content[erlang.org:c_portdriver].
377376

378377
==== Flow Control in Erlang Ports
379378

@@ -532,7 +531,7 @@ distribution layer.
532531
=== Sockets, UDP and TCP ===
533532
Sockets are a fundamental aspect of network communication in Erlang. They allow processes to communicate over a network using protocols such as TCP and UDP. Here, we will explore how to work with sockets, retrieve information about sockets, and tweak socket behavior.
534533

535-
Erlang provides a robust set of functions for creating and managing sockets. The gen_tcp and gen_udp modules facilitate the use of TCP and UDP protocols, respectively. Here is a basic example of opening a TCP socket:
534+
Erlang provides a robust set of functions for creating and managing sockets. The `gen_tcp` and `gen_udp` modules facilitate the use of TCP and UDP protocols, respectively. Here is a basic example of opening a TCP socket:
536535

537536
```erlang
538537
% Open a listening socket on port 1234
@@ -546,7 +545,7 @@ ok = gen_tcp:send(Socket, <<"Hello, World!">>),
546545
{ok, Data} = gen_tcp:recv(Socket, 0).
547546
```
548547

549-
For UDP, the process is similar but uses the 'gen_udp' module:
548+
For UDP, the process is similar but uses the `gen_udp` module:
550549

551550
```erlang
552551
% Open a UDP socket on port 1234
@@ -570,7 +569,7 @@ Erlang provides several functions to retrieve information about sockets. For ins
570569
% Set options on a socket
571570
ok = inet:setopts(Socket, [{recbuf, 4096}, {sndbuf, 4096}, {nodelay, true}]).
572571
```
573-
Additionally, you can use inet:peername/1 and inet:sockname/1 to get the remote and local addresses of a socket:
572+
Additionally, you can use `inet:peername/1` and `inet:sockname/1` to get the remote and local addresses of a socket:
574573

575574
```erlang
576575
% Get the remote address of a connected socket

0 commit comments

Comments
 (0)