Debian Codegraph @

po/es/man2/select_tut.2.po

raw
1 # Spanish translation of manpages
2 # This file is distributed under the same license as the manpages-l10n package.
3 # Copyright © of this file:
4 # Gerardo Aburruzaga García <[email protected]>, 1998.
5 msgid ""
6 msgstr ""
7 "Project-Id-Version: manpages-l10n\n"
8 "POT-Creation-Date: 2026-06-05 06:42+0200\n"
9 "PO-Revision-Date: 2021-02-01 18:58+0100\n"
10 "Last-Translator: Gerardo Aburruzaga García <[email protected]>\n"
11 "Language-Team: Spanish <[email protected]>\n"
12 "Language: es\n"
13 "MIME-Version: 1.0\n"
14 "Content-Type: text/plain; charset=UTF-8\n"
15 "Content-Transfer-Encoding: 8bit\n"
16 "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17 "X-Generator: Lokalize 20.04.1\n"
18
19 #. type: TH
20 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
21 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
22 #, no-wrap
23 msgid "SELECT_TUT"
24 msgstr "SELECT_TUT"
25
26 #. type: TH
27 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
28 #: opensuse-tumbleweed
29 #, no-wrap
30 msgid "2026-02-08"
31 msgstr "8 Febrero 2026"
32
33 #. type: TH
34 #: archlinux debian-unstable
35 #, fuzzy, no-wrap
36 #| msgid "Linux man-pages 6.17"
37 msgid "Linux man-pages 6.18"
38 msgstr "Páginas de Manual de Linux 6.17"
39
40 #. type: SH
41 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
42 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
43 #, no-wrap
44 msgid "NAME"
45 msgstr "NOMBRE"
46
47 #. type: Plain text
48 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
49 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
50 msgid "select, pselect - synchronous I/O multiplexing"
51 msgstr "select, pselect - multiplexación de E/S síncrona"
52
53 #. type: SH
54 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
55 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
56 #, no-wrap
57 msgid "LIBRARY"
58 msgstr "BIBLIOTECA"
59
60 #. type: Plain text
61 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
62 #: opensuse-leap-16-1 opensuse-tumbleweed
63 msgid "Standard C library (I<libc>,\\ I<-lc>)"
64 msgstr "Biblioteca Estándar C (I<libc>,\\ I<-lc>)"
65
66 #. type: SH
67 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
68 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
69 #, no-wrap
70 msgid "SYNOPSIS"
71 msgstr "SINOPSIS"
72
73 #. type: Plain text
74 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
75 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
76 msgid "See B<select>(2)"
77 msgstr "Vea B<select>(2)"
78
79 #. type: SH
80 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
81 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
82 #, no-wrap
83 msgid "DESCRIPTION"
84 msgstr "DESCRIPCIÓN"
85
86 #. type: Plain text
87 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
88 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
89 msgid ""
90 "The B<select>() and B<pselect>() system calls are used to efficiently "
91 "monitor multiple file descriptors, to see if any of them is, or becomes, "
92 "\"ready\"; that is, to see whether I/O becomes possible, or an \"exceptional "
93 "condition\" has occurred on any of the file descriptors."
94 msgstr ""
95
96 #. type: Plain text
97 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
98 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
99 msgid ""
100 "This page provides background and tutorial information on the use of these "
101 "system calls. For details of the arguments and semantics of B<select>() "
102 "and B<pselect>(), see B<select>(2)."
103 msgstr ""
104
105 #. type: SS
106 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
107 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
108 #, no-wrap
109 msgid "Combining signal and data events"
110 msgstr ""
111
112 #. type: Plain text
113 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
114 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
115 msgid ""
116 "B<pselect>() is useful if you are waiting for a signal as well as for file "
117 "descriptor(s) to become ready for I/O. Programs that receive signals "
118 "normally use the signal handler only to raise a global flag. The global "
119 "flag will indicate that the event must be processed in the main loop of the "
120 "program. A signal will cause the B<select>() (or B<pselect>()) call to "
121 "return with I<errno> set to B<EINTR>. This behavior is essential so that "
122 "signals can be processed in the main loop of the program, otherwise "
123 "B<select>() would block indefinitely."
124 msgstr ""
125
126 #. type: Plain text
127 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
128 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
129 #, fuzzy
130 #| msgid ""
131 #| "B<pselect> must be used if you are waiting for a signal as well as data "
132 #| "from a file descriptor. Programs that receive signals as events normally "
133 #| "use the signal handler only to raise a global flag. The global flag will "
134 #| "indicate that the event must be processed in the main loop of the "
135 #| "program. A signal will cause the B<select> (or B<pselect>) call to "
136 #| "return with B<errno> set to B<EINTR>. This behavior is essential so that "
137 #| "signals can be processed in the main loop of the program, otherwise "
138 #| "B<select> would block indefinitely. Now, somewhere in the main loop will "
139 #| "be a conditional to check the global flag. So we must ask: what if a "
140 #| "signal arrives after the conditional, but before the B<select> call? The "
141 #| "answer is that B<select> would block indefinitely, even though an event "
142 #| "is actually pending. This race condition is solved by the B<pselect> "
143 #| "call. This call can be used to mask out signals that are not to be "
144 #| "received except within the B<pselect> call. For instance, let us say that "
145 #| "the event in question was the exit of a child process. Before the start "
146 #| "of the main loop, we would block B<SIGCHLD> using B<sigprocmask>. Our "
147 #| "B<pselect> call would enable B<SIGCHLD> by using the virgin signal mask. "
148 #| "Our program would look like:"
149 msgid ""
150 "Now, somewhere in the main loop will be a conditional to check the global "
151 "flag. So we must ask: what if a signal arrives after the conditional, but "
152 "before the B<select>() call? The answer is that B<select>() would block "
153 "indefinitely, even though an event is actually pending. This race condition "
154 "is solved by the B<pselect>() call. This call can be used to set the "
155 "signal mask to a set of signals that are to be received only within the "
156 "B<pselect>() call. For instance, let us say that the event in question was "
157 "the exit of a child process. Before the start of the main loop, we would "
158 "block B<SIGCHLD> using B<sigprocmask>(2). Our B<pselect>() call would "
159 "enable B<SIGCHLD> by using an empty signal mask. Our program would look "
160 "like:"
161 msgstr ""
162 "B<pselect> debe ser usada si está esperando una señal así como datos de un "
163 "descriptor de fichero. Los programas que reciben señales como eventos "
164 "normalmente utilizan el manejador de señales para activar una bandera "
165 "global. La bandera global indicará que el evento debe ser procesado en el "
166 "bucle principal del programa. Una señal provocará que la llamada a B<select> "
167 "(o B<pselect>) regrese tomando la variable B<errno> el valor B<EINTR>. Este "
168 "comportamiento es esencial para que las señales puedan ser procesadas en el "
169 "bucle principal del programa, de otra manera B<select> se bloquearía "
170 "indefinidamente. Ahora, en algún lugar del bucle principal habrá una "
171 "condición para comprobar la bandera global. Así que debemos preguntarnos: "
172 "¿qué ocurre si una señal llega después de la condición, pero antes de la "
173 "llamada a B<select>? La respuesta es que B<select> se bloquearía "
174 "indefinidamente, incluso aún si hay un evento pendiente. Esta condición de "
175 "carrera se soluciona con la llamada B<pselect>. Esta llamada puede "
176 "utilizarse para enmascarar señales que no van a ser recibidas salvo dentro "
177 "de la llamada B<pselect>. Por ejemplo, digamos que el evento en cuestión fue "
178 "la salida de un proceso hijo. Antes del comienzo del bucle principal, "
179 "bloquearíamos B<SIGCHLD> usando B<sigprocmask>. Nuestra llamada B<pselect> "
180 "podría habilitar B<SIGCHLD> usando la máscara de señal virgen. Nuestro "
181 "programa se podría parecer a ésto:"
182
183 #. type: Plain text
184 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
185 #: opensuse-tumbleweed
186 #, no-wrap
187 msgid ""
188 "static volatile sig_atomic_t got_SIGCHLD = 0;\n"
189 "\\&\n"
190 "static void\n"
191 "child_sig_handler(int sig)\n"
192 "{\n"
193 " got_SIGCHLD = 1;\n"
194 "}\n"
195 "\\&\n"
196 "int\n"
197 "main(int argc, char *argv[])\n"
198 "{\n"
199 " sigset_t sigmask, empty_mask;\n"
200 " struct sigaction sa;\n"
201 " fd_set readfds, writefds, exceptfds;\n"
202 " int r;\n"
203 "\\&\n"
204 " sigemptyset(&sigmask);\n"
205 " sigaddset(&sigmask, SIGCHLD);\n"
206 " if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n"
207 " perror(\"sigprocmask\");\n"
208 " exit(EXIT_FAILURE);\n"
209 " }\n"
210 "\\&\n"
211 " sa.sa_flags = 0;\n"
212 " sa.sa_handler = child_sig_handler;\n"
213 " sigemptyset(&sa.sa_mask);\n"
214 " if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n"
215 " perror(\"sigaction\");\n"
216 " exit(EXIT_FAILURE);\n"
217 " }\n"
218 "\\&\n"
219 " sigemptyset(&empty_mask);\n"
220 "\\&\n"
221 " for (;;) { /* main loop */\n"
222 " /* Initialize readfds, writefds, and exceptfds\n"
223 " before the pselect() call. (Code omitted.) */\n"
224 "\\&\n"
225 " r = pselect(nfds, &readfds, &writefds, &exceptfds,\n"
226 " NULL, &empty_mask);\n"
227 " if (r == -1 && errno != EINTR) {\n"
228 " /* Handle error */\n"
229 " }\n"
230 "\\&\n"
231 " if (got_SIGCHLD) {\n"
232 " got_SIGCHLD = 0;\n"
233 "\\&\n"
234 " /* Handle signalled event here; e.g., wait() for all\n"
235 " terminated children. (Code omitted.) */\n"
236 " }\n"
237 "\\&\n"
238 " /* main body of program */\n"
239 " }\n"
240 "}\n"
241 msgstr ""
242
243 #. type: SS
244 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
245 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
246 #, no-wrap
247 msgid "Practical"
248 msgstr ""
249
250 #. type: Plain text
251 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
252 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
253 #, fuzzy
254 #| msgid ""
255 #| "So what is the point of B<select>? Can't I just read and write to my "
256 #| "descriptors whenever I want? The point of select is that it watches "
257 #| "multiple descriptors at the same time and properly puts the process to "
258 #| "sleep if there is no activity. It does this while enabling you to handle "
259 #| "multiple simultaneous pipes and sockets. Unix programmers often find "
260 #| "themselves in a position where they have to handle IO from more than one "
261 #| "file descriptor where the data flow may be intermittent. If you were to "
262 #| "merely create a sequence of B<read> and B<write> calls, you would find "
263 #| "that one of your calls may block waiting for data from/to a file "
264 #| "descriptor, while another file descriptor is unused though available for "
265 #| "data. B<select> efficiently copes with this situation."
266 msgid ""
267 "So what is the point of B<select>()? Can't I just read and write to my file "
268 "descriptors whenever I want? The point of B<select>() is that it watches "
269 "multiple descriptors at the same time and properly puts the process to sleep "
270 "if there is no activity. UNIX programmers often find themselves in a "
271 "position where they have to handle I/O from more than one file descriptor "
272 "where the data flow may be intermittent. If you were to merely create a "
273 "sequence of B<read>(2) and B<write>(2) calls, you would find that one of "
274 "your calls may block waiting for data from/to a file descriptor, while "
275 "another file descriptor is unused though ready for I/O. B<select>() "
276 "efficiently copes with this situation."
277 msgstr ""
278 "Por lo tanto, ¿cuál es el propósito de B<select>? ¿No puedo simplemente leer "
279 "y escribir en mis descriptores siempre que quiera? El significado de select "
280 "es observar varios descriptores al mismo tiempo y poner a dormir "
281 "adecuadamente a los procesos si no hay ninguna actividad. Esto lo hace "
282 "mientras le permite manejar varias tuberías y conectores de manera "
283 "simultánea. Los programadores de Unix a menudo se encuentran en la situación "
284 "de manejar la E/S de más de un descriptor de fichero donde el flujo de datos "
285 "puede ser intermitente. Si tan sólo creara una secuencia de llamadas "
286 "B<read> y B<write>, podría encontrarse con que una de sus llamadas puede "
287 "bloquearse esperando datos de/a un descriptor de fichero, mientras que otro "
288 "descriptor de fichero está siendo inutilizado aunque haya datos "
289 "disponibles. B<select> maneja eficientemente esta situación."
290
291 #. type: SS
292 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
293 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
294 #, no-wrap
295 msgid "Select law"
296 msgstr ""
297
298 #. type: Plain text
299 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
300 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
301 #, fuzzy
302 #| msgid ""
303 #| "Many people who try to use B<select> come across behavior that is "
304 #| "difficult to understand and produces non-portable or borderline results. "
305 #| "For instance, the above program is carefully written not to block at any "
306 #| "point, even though it does not set its file descriptors to non-blocking "
307 #| "mode at all (see B<ioctl>(2)). It is easy to introduce subtle errors that "
308 #| "will remove the advantage of using B<select>, hence I will present a list "
309 #| "of essentials to watch for when using the B<select> call."
310 msgid ""
311 "Many people who try to use B<select>() come across behavior that is "
312 "difficult to understand and produces nonportable or borderline results. For "
313 "instance, the above program is carefully written not to block at any point, "
314 "even though it does not set its file descriptors to nonblocking mode. It is "
315 "easy to introduce subtle errors that will remove the advantage of using "
316 "B<select>(), so here is a list of essentials to watch for when using "
317 "B<select>()."
318 msgstr ""
319 "Muchas personas que intentan usar B<select> se encuentran con un "
320 "comportamiento que es difícil de comprender y que produce resultados no "
321 "transportables o dudosos. Por ejemplo, el programa anterior se ha escrito "
322 "cuidadosamente para que no se bloquee en ningún punto, aunque para nada ha "
323 "establecido el modo no bloqueante en sus descriptores de fichero (vea "
324 "B<ioctl>(2)). Es fácil introducir errores sutiles que hagan desaparecer la "
325 "ventaja de usar B<select>, por lo que voy a presentar una lista de los "
326 "aspectos esenciales a tener en cuenta cuando se use la llamada B<select>."
327
328 #. type: TP
329 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
330 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
331 #, no-wrap
332 msgid "1."
333 msgstr "1."
334
335 #. type: Plain text
336 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
337 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
338 msgid ""
339 "You should always try to use B<select>() without a timeout. Your program "
340 "should have nothing to do if there is no data available. Code that depends "
341 "on timeouts is not usually portable and is difficult to debug."
342 msgstr ""
343 "Siempre debe de intentar usar B<select>() sin un plazo de tiempo. Su "
344 "programa no debe tener que hacer nada si no hay datos disponibles. El código "
345 "que depende de los plazos de tiempo no es normalmente portable y es difícil "
346 "de depurar."
347
348 #. type: TP
349 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
350 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
351 #, no-wrap
352 msgid "2."
353 msgstr "2."
354
355 #. type: Plain text
356 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
357 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
358 msgid ""
359 "The value I<nfds> must be properly calculated for efficiency as explained "
360 "above."
361 msgstr ""
362 "Para un resultado eficiente, el valor de I<nfds> se debe calcular "
363 "correctamente de la forma que se explica más abajo."
364
365 #. type: TP
366 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
367 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
368 #, no-wrap
369 msgid "3."
370 msgstr "3."
371
372 #. type: Plain text
373 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
374 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
375 msgid ""
376 "No file descriptor must be added to any set if you do not intend to check "
377 "its result after the B<select>() call, and respond appropriately. See next "
378 "rule."
379 msgstr ""
380 "No debe añadir a ningún conjunto un descriptor de fichero para el que no "
381 "tenga intención de comprobar su resultado (y responder adecuadamente) tras "
382 "una llamada a B<select>(). Vea la siguiente regla."
383
384 #. type: TP
385 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
386 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
387 #, no-wrap
388 msgid "4."
389 msgstr "4."
390
391 #. type: Plain text
392 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
393 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
394 msgid ""
395 "After B<select>() returns, all file descriptors in all sets should be "
396 "checked to see if they are ready."
397 msgstr ""
398
399 #. type: TP
400 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
401 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
402 #, no-wrap
403 msgid "5."
404 msgstr "5."
405
406 #. type: Plain text
407 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
408 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
409 msgid ""
410 "The functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) do I<not> "
411 "necessarily read/write the full amount of data that you have requested. If "
412 "they do read/write the full amount, it's because you have a low traffic load "
413 "and a fast stream. This is not always going to be the case. You should "
414 "cope with the case of your functions managing to send or receive only a "
415 "single byte."
416 msgstr ""
417 "Las funciones B<read>(), B<recv>(), B<write>() y B<send>() I<no> leen/"
418 "escriben necesariamente todos los datos que haya solicitado. Si leen/"
419 "escriben todos los datos es porque tiene poco tráfico y un flujo muy rápido. "
420 "Ese no va a ser siempre el caso. Debe hacer frente al caso en el que sus "
421 "funciones sólo logren enviar o recibir un único byte."
422
423 #. type: TP
424 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
425 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
426 #, no-wrap
427 msgid "6."
428 msgstr "6."
429
430 #. type: Plain text
431 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
432 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
433 #, fuzzy
434 #| msgid ""
435 #| "Never read/write only in single bytes at a time unless your are really "
436 #| "sure that you have a small amount of data to process. It is extremely "
437 #| "inefficient not to read/write as much data as you can buffer each time. "
438 #| "The buffers in the example above are 1024 bytes although they could "
439 #| "easily be made as large as the maximum possible packet size on your local "
440 #| "network."
441 msgid ""
442 "Never read/write only in single bytes at a time unless you are really sure "
443 "that you have a small amount of data to process. It is extremely "
444 "inefficient not to read/write as much data as you can buffer each time. The "
445 "buffers in the example below are 1024 bytes although they could easily be "
446 "made larger."
447 msgstr ""
448 "Nunca lea/escriba byte a byte a menos que esté realmente seguro de que tiene "
449 "que procesar una pequeña cantidad de datos. Es extremadamente ineficiente no "
450 "leer/escribir cada vez tantos datos como pueda almacenar. Los buffers del "
451 "ejemplo anterior son de 1024 bytes aunque podrían fácilmente hacerse tan "
452 "grandes como el máximo tamaño de paquete posible en su red local."
453
454 #. type: TP
455 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
456 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
457 #, no-wrap
458 msgid "7."
459 msgstr "7."
460
461 #. Nonetheless, you should still cope with these errors for completeness.
462 #. type: Plain text
463 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
464 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
465 #, fuzzy
466 #| msgid ""
467 #| "The functions B<read()>, B<recv()>, B<write()>, and B<send()> as well as "
468 #| "the B<select()> call can return -1 with an errno of B<EINTR> or B<EAGAIN> "
469 #| "(B<EWOULDBLOCK>) which are not errors. These results must be properly "
470 #| "managed (not done properly above). If your program is not going to "
471 #| "receive any signals then it is unlikely you will get B<EINTR>. If your "
472 #| "program does not set non-blocking IO, you will not get B<EAGAIN>. "
473 #| "Nonetheless you should still cope with these errors for completeness."
474 msgid ""
475 "Calls to B<read>(2), B<recv>(2), B<write>(2), B<send>(2), and B<select>() "
476 "can fail with the error B<EINTR>, and calls to B<read>(2), B<recv>(2), "
477 "B<write>(2), and B<send>(2) can fail with I<errno> set to B<EAGAIN> "
478 "(B<EWOULDBLOCK>). These results must be properly managed (not done properly "
479 "above). If your program is not going to receive any signals, then it is "
480 "unlikely you will get B<EINTR>. If your program does not set nonblocking I/"
481 "O, you will not get B<EAGAIN>."
482 msgstr ""
483 "Además de la llamada B<select()>, las funciones B<read()>, B<recv()>, "
484 "B<write()> y B<send()> pueden devolver -1 con un errno B<EINTR> o B<EAGAIN> "
485 "(B<EWOULDBLOCK>) que no son errores. Estos resultados deben tratarse "
486 "adecuadamente (lo que no se ha hecho en el ejemplo anterior). Si su programa "
487 "no va a recibir ninguna señal, entonces es muy poco probable que obtenga "
488 "B<EINTR>. Si su programa no activa E/S no bloqueante, no obtendrá "
489 "B<EAGAIN>. Sin embargo, todavía debe hacer frente a estos errores por "
490 "completitud."
491
492 #. type: TP
493 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
494 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
495 #, no-wrap
496 msgid "8."
497 msgstr "8."
498
499 #. type: Plain text
500 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
501 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
502 msgid ""
503 "Never call B<read>(2), B<recv>(2), B<write>(2), or B<send>(2) with a buffer "
504 "length of zero."
505 msgstr ""
506 "Nunca llame a B<read>(), B<recv>(), B<write>() o B<send>() con una longitud "
507 "de buffer de cero."
508
509 #. type: TP
510 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
511 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
512 #, no-wrap
513 msgid "9."
514 msgstr "9."
515
516 #. type: Plain text
517 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
518 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
519 #, fuzzy
520 #| msgid ""
521 #| "Except as indicated in B<7.>, the functions B<read()>, B<recv()>, "
522 #| "B<write()>, and B<send()> never have a return value less than 1 except if "
523 #| "an error has occurred. For instance, a B<read()> on a pipe where the "
524 #| "other end has died returns zero (so does an end-of-file error), I<but> "
525 #| "only returns zero once (a followup read or write will return -1). Should "
526 #| "any of these functions return 0 or -1, you should I<not> pass that "
527 #| "descriptor to select ever again. In the above example, I close the "
528 #| "descriptor immediately, and then set it to -1 to prevent it being "
529 #| "included in a set."
530 msgid ""
531 "If the functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) fail "
532 "with errors other than those listed in B<7.>, or one of the input functions "
533 "returns 0, indicating end of file, then you should I<not> pass that file "
534 "descriptor to B<select>() again. In the example below, I close the file "
535 "descriptor immediately, and then set it to -1 to prevent it being included "
536 "in a set."
537 msgstr ""
538 "Excepto como se indica en B<7.>, las funciones B<read()>, B<recv()>, "
539 "B<write()> y B<send()> nunca devuelven un valor menor que 1 salvo cuando se "
540 "produce un error. Por ejemplo, un B<read()> sobre una tubería donde el otro "
541 "extremo ha muerto devuelve cero (al igual que un error de fin de fichero), "
542 "I<pero> devuelve cero sólo una vez (un lectura o escritura posterior "
543 "devolverá -1). Cuando cualquiera de estas funciones devuelva 0 o -1, I<no "
544 "debe> pasar el descriptor correspondiente a select nunca más. En el ejemplo "
545 "anterior, cierro el descriptor inmediatamente y le asigno -1 para evitar que "
546 "se vuelva a incluir en un conjunto."
547
548 #. type: TP
549 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
550 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
551 #, no-wrap
552 msgid "10."
553 msgstr "10."
554
555 #. type: Plain text
556 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
557 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
558 msgid ""
559 "The timeout value must be initialized with each new call to B<select>(), "
560 "since some operating systems modify the structure. B<pselect>() however "
561 "does not modify its timeout structure."
562 msgstr ""
563 "El valor del plazo de tiempo debe inicializarse con cada nueva llamada a "
564 "B<select>(), ya que algunos sistemas operativos modifican la estructura. "
565 "B<pselect>(), sin embargo, no modifica su estructura de plazo de tiempo."
566
567 #. type: TP
568 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
569 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
570 #, no-wrap
571 msgid "11."
572 msgstr "11."
573
574 #. "I have heard" does not fill me with confidence, and doesn't
575 #. belong in a man page, so I've commented this point out.
576 #. .TP
577 #. 11.
578 #. I have heard that the Windows socket layer does not cope with OOB data
579 #. properly.
580 #. It also does not cope with
581 #. .BR select ()
582 #. calls when no file descriptors are set at all.
583 #. Having no file descriptors set is a useful
584 #. way to sleep the process with subsecond precision by using the timeout.
585 #. (See further on.)
586 #. type: Plain text
587 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
588 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
589 msgid ""
590 "Since B<select>() modifies its file descriptor sets, if the call is being "
591 "used in a loop, then the sets must be reinitialized before each call."
592 msgstr ""
593
594 #. type: SH
595 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
596 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
597 #, no-wrap
598 msgid "RETURN VALUE"
599 msgstr "VALOR DEVUELTO"
600
601 #. type: Plain text
602 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
603 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
604 msgid "See B<select>(2)."
605 msgstr "Vea B<select>(2)."
606
607 #. type: SH
608 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
609 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
610 #, no-wrap
611 msgid "NOTES"
612 msgstr "NOTAS"
613
614 #. type: Plain text
615 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
616 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
617 #, fuzzy
618 #| msgid ""
619 #| "Generally speaking, all operating systems that support sockets, also "
620 #| "support B<select>. Some people consider B<select> to be an esoteric and "
621 #| "rarely used function. Indeed, many types of programs become extremely "
622 #| "complicated without it. B<select> can be used to solve many problems in a "
623 #| "portable and efficient way that naive programmers try to solve with "
624 #| "threads, forking, IPCs, signals, memory sharing and other dirty methods. "
625 #| "B<pselect> is a newer function that is less commonly used."
626 msgid ""
627 "Generally speaking, all operating systems that support sockets also support "
628 "B<select>(). B<select>() can be used to solve many problems in a portable "
629 "and efficient way that naive programmers try to solve in a more complicated "
630 "manner using threads, forking, IPCs, signals, memory sharing, and so on."
631 msgstr ""
632 "Generalmente hablando, todos los sistemas operativos que soportan "
633 "conectores, también soportan B<select>. Algunas personas consideran que "
634 "B<select> es una función esotérica y raramente usada. De hecho, muchos tipos "
635 "de programas se vuelven extremadamente complicados sin ella. B<select> puede "
636 "utilizarse para solucionar muchos problemas de manera eficiente y portable. "
637 "Problemas que los programadores ingenuos tratan de resolver usando hilos, "
638 "procesos hijos, IPCs, señales, memoria compartida y otros oscuros métodos. "
639 "B<pselect> es una función más reciente que es menos comúnmente usada."
640
641 #. type: Plain text
642 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
643 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
644 #, fuzzy
645 #| msgid ""
646 #| "The B<poll>(2) system call has the same functionality as B<select>, but "
647 #| "with less subtle behavior. It is less portable than B<select>."
648 msgid ""
649 "The B<poll>(2) system call has the same functionality as B<select>(), and "
650 "is somewhat more efficient when monitoring sparse file descriptor sets. It "
651 "is nowadays widely available, but historically was less portable than "
652 "B<select>()."
653 msgstr ""
654 "La llamada al sistema B<poll>(2) tiene la misma funcionalidad que "
655 "B<select>, pero con un comportamiento menos sutil. Es menos portable que "
656 "B<select>."
657
658 #. type: Plain text
659 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
660 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
661 msgid ""
662 "The Linux-specific B<epoll>(7) API provides an interface that is more "
663 "efficient than B<select>(2) and B<poll>(2) when monitoring large numbers "
664 "of file descriptors."
665 msgstr ""
666
667 #. type: SH
668 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
669 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
670 #, no-wrap
671 msgid "EXAMPLES"
672 msgstr "EJEMPLOS"
673
674 #. type: Plain text
675 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
676 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
677 msgid ""
678 "Here is an example that better demonstrates the true utility of "
679 "B<select>(). The listing below is a TCP forwarding program that forwards "
680 "from one TCP port to another."
681 msgstr ""
682 "Aquí viene un ejemplo que ilustra mejor la verdadera utilidad de "
683 "B<select>(). El listado de abajo es un programa de reenvío TCP que redirige "
684 "de un puerto TCP a otro."
685
686 #. type: Plain text
687 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
688 #: opensuse-tumbleweed
689 #, no-wrap
690 msgid ""
691 "#include E<lt>arpa/inet.hE<gt>\n"
692 "#include E<lt>errno.hE<gt>\n"
693 "#include E<lt>netinet/in.hE<gt>\n"
694 "#include E<lt>signal.hE<gt>\n"
695 "#include E<lt>stdio.hE<gt>\n"
696 "#include E<lt>stdlib.hE<gt>\n"
697 "#include E<lt>string.hE<gt>\n"
698 "#include E<lt>sys/select.hE<gt>\n"
699 "#include E<lt>sys/socket.hE<gt>\n"
700 "#include E<lt>sys/types.hE<gt>\n"
701 "#include E<lt>unistd.hE<gt>\n"
702 "\\&\n"
703 "static int forward_port;\n"
704 "\\&\n"
705 "#undef max\n"
706 "#define max(x, y) ((x) E<gt> (y) ? (x) : (y))\n"
707 "\\&\n"
708 "static int\n"
709 "listen_socket(int listen_port)\n"
710 "{\n"
711 " int lfd;\n"
712 " int yes;\n"
713 " struct sockaddr_in addr;\n"
714 "\\&\n"
715 " lfd = socket(AF_INET, SOCK_STREAM, 0);\n"
716 " if (lfd == -1) {\n"
717 " perror(\"socket\");\n"
718 " return -1;\n"
719 " }\n"
720 "\\&\n"
721 " yes = 1;\n"
722 " if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n"
723 " &yes, sizeof(yes)) == -1)\n"
724 " {\n"
725 " perror(\"setsockopt\");\n"
726 " close(lfd);\n"
727 " return -1;\n"
728 " }\n"
729 "\\&\n"
730 " memset(&addr, 0, sizeof(addr));\n"
731 " addr.sin_port = htons(listen_port);\n"
732 " addr.sin_family = AF_INET;\n"
733 " if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n"
734 " perror(\"bind\");\n"
735 " close(lfd);\n"
736 " return -1;\n"
737 " }\n"
738 "\\&\n"
739 " printf(\"accepting connections on port %d\\[rs]n\", listen_port);\n"
740 " listen(lfd, 10);\n"
741 " return lfd;\n"
742 "}\n"
743 "\\&\n"
744 "static int\n"
745 "connect_socket(int connect_port, char *address)\n"
746 "{\n"
747 " int cfd;\n"
748 " struct sockaddr_in addr;\n"
749 "\\&\n"
750 " cfd = socket(AF_INET, SOCK_STREAM, 0);\n"
751 " if (cfd == -1) {\n"
752 " perror(\"socket\");\n"
753 " return -1;\n"
754 " }\n"
755 "\\&\n"
756 " memset(&addr, 0, sizeof(addr));\n"
757 " addr.sin_port = htons(connect_port);\n"
758 " addr.sin_family = AF_INET;\n"
759 "\\&\n"
760 " if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n"
761 " fprintf(stderr, \"inet_aton(): bad IP address format\\[rs]n\");\n"
762 " close(cfd);\n"
763 " return -1;\n"
764 " }\n"
765 "\\&\n"
766 " if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n"
767 " perror(\"connect()\");\n"
768 " shutdown(cfd, SHUT_RDWR);\n"
769 " close(cfd);\n"
770 " return -1;\n"
771 " }\n"
772 " return cfd;\n"
773 "}\n"
774 "\\&\n"
775 "#define SHUT_FD1 do { \\[rs]\n"
776 " if (fd1 E<gt>= 0) { \\[rs]\n"
777 " shutdown(fd1, SHUT_RDWR); \\[rs]\n"
778 " close(fd1); \\[rs]\n"
779 " fd1 = -1; \\[rs]\n"
780 " } \\[rs]\n"
781 " } while (0)\n"
782 "\\&\n"
783 "#define SHUT_FD2 do { \\[rs]\n"
784 " if (fd2 E<gt>= 0) { \\[rs]\n"
785 " shutdown(fd2, SHUT_RDWR); \\[rs]\n"
786 " close(fd2); \\[rs]\n"
787 " fd2 = -1; \\[rs]\n"
788 " } \\[rs]\n"
789 " } while (0)\n"
790 "\\&\n"
791 "#define BUF_SIZE 1024\n"
792 "\\&\n"
793 "int\n"
794 "main(int argc, char *argv[])\n"
795 "{\n"
796 " int h;\n"
797 " int ready, nfds;\n"
798 " int fd1 = -1, fd2 = -1;\n"
799 " int buf1_avail = 0, buf1_written = 0;\n"
800 " int buf2_avail = 0, buf2_written = 0;\n"
801 " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n"
802 " fd_set readfds, writefds, exceptfds;\n"
803 " ssize_t nbytes;\n"
804 "\\&\n"
805 " if (argc != 4) {\n"
806 " fprintf(stderr, \"Usage\\[rs]n\\[rs]tfwd E<lt>listen-portE<gt> \"\n"
807 " \"E<lt>forward-to-portE<gt> E<lt>forward-to-ip-addressE<gt>\\[rs]n\");\n"
808 " exit(EXIT_FAILURE);\n"
809 " }\n"
810 "\\&\n"
811 " signal(SIGPIPE, SIG_IGN);\n"
812 "\\&\n"
813 " forward_port = atoi(argv[2]);\n"
814 "\\&\n"
815 " h = listen_socket(atoi(argv[1]));\n"
816 " if (h == -1)\n"
817 " exit(EXIT_FAILURE);\n"
818 "\\&\n"
819 " for (;;) {\n"
820 " nfds = 0;\n"
821 "\\&\n"
822 " FD_ZERO(&readfds);\n"
823 " FD_ZERO(&writefds);\n"
824 " FD_ZERO(&exceptfds);\n"
825 " FD_SET(h, &readfds);\n"
826 " nfds = max(nfds, h);\n"
827 "\\&\n"
828 " if (fd1 E<gt> 0 && buf1_avail E<lt> BUF_SIZE)\n"
829 " FD_SET(fd1, &readfds);\n"
830 " /* Note: nfds is updated below, when fd1 is added to\n"
831 " exceptfds. */\n"
832 " if (fd2 E<gt> 0 && buf2_avail E<lt> BUF_SIZE)\n"
833 " FD_SET(fd2, &readfds);\n"
834 "\\&\n"
835 " if (fd1 E<gt> 0 && buf2_avail - buf2_written E<gt> 0)\n"
836 " FD_SET(fd1, &writefds);\n"
837 " if (fd2 E<gt> 0 && buf1_avail - buf1_written E<gt> 0)\n"
838 " FD_SET(fd2, &writefds);\n"
839 "\\&\n"
840 " if (fd1 E<gt> 0) {\n"
841 " FD_SET(fd1, &exceptfds);\n"
842 " nfds = max(nfds, fd1);\n"
843 " }\n"
844 " if (fd2 E<gt> 0) {\n"
845 " FD_SET(fd2, &exceptfds);\n"
846 " nfds = max(nfds, fd2);\n"
847 " }\n"
848 "\\&\n"
849 " ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n"
850 "\\&\n"
851 " if (ready == -1 && errno == EINTR)\n"
852 " continue;\n"
853 "\\&\n"
854 " if (ready == -1) {\n"
855 " perror(\"select()\");\n"
856 " exit(EXIT_FAILURE);\n"
857 " }\n"
858 "\\&\n"
859 " if (FD_ISSET(h, &readfds)) {\n"
860 " socklen_t addrlen;\n"
861 " struct sockaddr_in client_addr;\n"
862 " int fd;\n"
863 "\\&\n"
864 " addrlen = sizeof(client_addr);\n"
865 " memset(&client_addr, 0, addrlen);\n"
866 " fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n"
867 " if (fd == -1) {\n"
868 " perror(\"accept()\");\n"
869 " } else {\n"
870 " SHUT_FD1;\n"
871 " SHUT_FD2;\n"
872 " buf1_avail = buf1_written = 0;\n"
873 " buf2_avail = buf2_written = 0;\n"
874 " fd1 = fd;\n"
875 " fd2 = connect_socket(forward_port, argv[3]);\n"
876 " if (fd2 == -1)\n"
877 " SHUT_FD1;\n"
878 " else\n"
879 " printf(\"connect from %s\\[rs]n\",\n"
880 " inet_ntoa(client_addr.sin_addr));\n"
881 "\\&\n"
882 " /* Skip any events on the old, closed file\n"
883 " descriptors. */\n"
884 "\\&\n"
885 " continue;\n"
886 " }\n"
887 " }\n"
888 "\\&\n"
889 " /* NB: read OOB data before normal reads. */\n"
890 "\\&\n"
891 " if (fd1 E<gt> 0 && FD_ISSET(fd1, &exceptfds)) {\n"
892 " char c;\n"
893 "\\&\n"
894 " nbytes = recv(fd1, &c, 1, MSG_OOB);\n"
895 " if (nbytes E<lt> 1)\n"
896 " SHUT_FD1;\n"
897 " else\n"
898 " send(fd2, &c, 1, MSG_OOB);\n"
899 " }\n"
900 " if (fd2 E<gt> 0 && FD_ISSET(fd2, &exceptfds)) {\n"
901 " char c;\n"
902 "\\&\n"
903 " nbytes = recv(fd2, &c, 1, MSG_OOB);\n"
904 " if (nbytes E<lt> 1)\n"
905 " SHUT_FD2;\n"
906 " else\n"
907 " send(fd1, &c, 1, MSG_OOB);\n"
908 " }\n"
909 " if (fd1 E<gt> 0 && FD_ISSET(fd1, &readfds)) {\n"
910 " nbytes = read(fd1, buf1 + buf1_avail,\n"
911 " BUF_SIZE - buf1_avail);\n"
912 " if (nbytes E<lt> 1)\n"
913 " SHUT_FD1;\n"
914 " else\n"
915 " buf1_avail += nbytes;\n"
916 " }\n"
917 " if (fd2 E<gt> 0 && FD_ISSET(fd2, &readfds)) {\n"
918 " nbytes = read(fd2, buf2 + buf2_avail,\n"
919 " BUF_SIZE - buf2_avail);\n"
920 " if (nbytes E<lt> 1)\n"
921 " SHUT_FD2;\n"
922 " else\n"
923 " buf2_avail += nbytes;\n"
924 " }\n"
925 " if (fd1 E<gt> 0 && FD_ISSET(fd1, &writefds) && buf2_avail E<gt> 0) {\n"
926 " nbytes = write(fd1, buf2 + buf2_written,\n"
927 " buf2_avail - buf2_written);\n"
928 " if (nbytes E<lt> 1)\n"
929 " SHUT_FD1;\n"
930 " else\n"
931 " buf2_written += nbytes;\n"
932 " }\n"
933 " if (fd2 E<gt> 0 && FD_ISSET(fd2, &writefds) && buf1_avail E<gt> 0) {\n"
934 " nbytes = write(fd2, buf1 + buf1_written,\n"
935 " buf1_avail - buf1_written);\n"
936 " if (nbytes E<lt> 1)\n"
937 " SHUT_FD2;\n"
938 " else\n"
939 " buf1_written += nbytes;\n"
940 " }\n"
941 "\\&\n"
942 " /* Check if write data has caught read data. */\n"
943 "\\&\n"
944 " if (buf1_written == buf1_avail)\n"
945 " buf1_written = buf1_avail = 0;\n"
946 " if (buf2_written == buf2_avail)\n"
947 " buf2_written = buf2_avail = 0;\n"
948 "\\&\n"
949 " /* One side has closed the connection, keep\n"
950 " writing to the other side until empty. */\n"
951 "\\&\n"
952 " if (fd1 E<lt> 0 && buf1_avail - buf1_written == 0)\n"
953 " SHUT_FD2;\n"
954 " if (fd2 E<lt> 0 && buf2_avail - buf2_written == 0)\n"
955 " SHUT_FD1;\n"
956 " }\n"
957 " exit(EXIT_SUCCESS);\n"
958 "}\n"
959 msgstr ""
960
961 #. type: Plain text
962 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
963 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
964 #, fuzzy
965 #| msgid ""
966 #| "The above program properly forwards most kinds of TCP connections "
967 #| "including OOB signal data transmitted by B<telnet> servers. It handles "
968 #| "the tricky problem of having data flow in both directions simultaneously. "
969 #| "You might think it more efficient to use a B<fork()> call and devote a "
970 #| "thread to each stream. This becomes more tricky than you might suspect. "
971 #| "Another idea is to set non-blocking IO using an B<ioctl()> call. This "
972 #| "also has its problems because you end up having to have inefficient "
973 #| "timeouts."
974 msgid ""
975 "The above program properly forwards most kinds of TCP connections including "
976 "OOB signal data transmitted by B<telnet> servers. It handles the tricky "
977 "problem of having data flow in both directions simultaneously. You might "
978 "think it more efficient to use a B<fork>(2) call and devote a thread to "
979 "each stream. This becomes more tricky than you might suspect. Another idea "
980 "is to set nonblocking I/O using B<fcntl>(2). This also has its problems "
981 "because you end up using inefficient timeouts."
982 msgstr ""
983 "El programa anterior reenvía correctamente la mayoría de los tipos de "
984 "conexiones TCP, incluyendo los datos OOB de señal transmitidos por los "
985 "servidores B<telnet>. También es capaz de manejar el difícil problema de "
986 "tener flujos de datos en ambas direcciones a la vez. Podría pensar que es "
987 "más eficiente hacer una llamada B<fork()> y dedicar un hilo a cada flujo. "
988 "Esto es más complicado de lo que podría pensar. Otra idea es activar E/S no "
989 "bloqueante haciendo una llamada B<ioctl()>. Esto también tiene sus problemas "
990 "ya que acaba teniendo que utilizar plazos de tiempo (I<timeouts>) "
991 "ineficientes."
992
993 #. type: Plain text
994 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
995 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
996 #, fuzzy
997 #| msgid ""
998 #| "The program does not handle more than one simultaneous connection at a "
999 #| "time, although it could easily be extended to do this with a linked list "
1000 #| "of buffers\\(emone for each connection. At the moment, new connections "
1001 #| "cause the current connection to be dropped."
1002 msgid ""
1003 "The program does not handle more than one simultaneous connection at a time, "
1004 "although it could easily be extended to do this with a linked list of "
1005 "buffers\\[em]one for each connection. At the moment, new connections cause "
1006 "the current connection to be dropped."
1007 msgstr ""
1008 "El programa no maneja más de una conexión simultánea a la vez, aunque podría "
1009 "extenderse fácilmente para hacer esto con una lista ligada de buffers \\"
1010 "(emuno para cada conexión. Por ahora, una nueva conexión hace que la "
1011 "conexión actual se caiga."
1012
1013 #. type: SH
1014 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1015 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1016 #, no-wrap
1017 msgid "SEE ALSO"
1018 msgstr "VÉASE TAMBIÉN"
1019
1020 #. type: Plain text
1021 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1022 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1023 msgid ""
1024 "B<accept>(2), B<connect>(2), B<poll>(2), B<read>(2), B<recv>(2), "
1025 "B<select>(2), B<send>(2), B<sigprocmask>(2), B<write>(2), B<epoll>(7)"
1026 msgstr ""
1027 "B<accept>(2), B<connect>(2), B<poll>(2), B<read>(2), B<recv>(2), "
1028 "B<select>(2), B<send>(2), B<sigprocmask>(2), B<write>(2), B<epoll>(7)"
1029
1030 #. type: TH
1031 #: debian-trixie
1032 #, no-wrap
1033 msgid "2024-06-15"
1034 msgstr "15 Junio 2024"
1035
1036 #. type: TH
1037 #: debian-trixie
1038 #, no-wrap
1039 msgid "Linux man-pages 6.9.1"
1040 msgstr "Páginas de Manual de Linux 6.9.1"
1041
1042 #. type: Plain text
1043 #: debian-trixie
1044 msgid "Standard C library (I<libc>, I<-lc>)"
1045 msgstr "Biblioteca Estándar C (I<libc>, I<-lc>)"
1046
1047 #. type: Plain text
1048 #: debian-trixie fedora-44 fedora-rawhide
1049 #, no-wrap
1050 msgid ""
1051 "static volatile sig_atomic_t got_SIGCHLD = 0;\n"
1052 "\\&\n"
1053 "static void\n"
1054 "child_sig_handler(int sig)\n"
1055 "{\n"
1056 " got_SIGCHLD = 1;\n"
1057 "}\n"
1058 "\\&\n"
1059 "int\n"
1060 "main(int argc, char *argv[])\n"
1061 "{\n"
1062 " sigset_t sigmask, empty_mask;\n"
1063 " struct sigaction sa;\n"
1064 " fd_set readfds, writefds, exceptfds;\n"
1065 " int r;\n"
1066 "\\&\n"
1067 " sigemptyset(&sigmask);\n"
1068 " sigaddset(&sigmask, SIGCHLD);\n"
1069 " if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n"
1070 " perror(\"sigprocmask\");\n"
1071 " exit(EXIT_FAILURE);\n"
1072 " }\n"
1073 "\\&\n"
1074 " sa.sa_flags = 0;\n"
1075 " sa.sa_handler = child_sig_handler;\n"
1076 " sigemptyset(&sa.sa_mask);\n"
1077 " if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n"
1078 " perror(\"sigaction\");\n"
1079 " exit(EXIT_FAILURE);\n"
1080 " }\n"
1081 "\\&\n"
1082 " sigemptyset(&empty_mask);\n"
1083 "\\&\n"
1084 " for (;;) { /* main loop */\n"
1085 " /* Initialize readfds, writefds, and exceptfds\n"
1086 " before the pselect() call. (Code omitted.) */\n"
1087 "\\&\n"
1088 " r = pselect(nfds, &readfds, &writefds, &exceptfds,\n"
1089 " NULL, &empty_mask);\n"
1090 " if (r == -1 && errno != EINTR) {\n"
1091 " /* Handle error */\n"
1092 " }\n"
1093 "\\&\n"
1094 " if (got_SIGCHLD) {\n"
1095 " got_SIGCHLD = 0;\n"
1096 "\\&\n"
1097 " /* Handle signalled event here; e.g., wait() for all\n"
1098 " terminated children. (Code omitted.) */\n"
1099 " }\n"
1100 "\\&\n"
1101 " /* main body of program */\n"
1102 " }\n"
1103 "}\n"
1104 msgstr ""
1105
1106 #. type: Plain text
1107 #: debian-trixie fedora-44 fedora-rawhide
1108 #, no-wrap
1109 msgid ""
1110 "#include E<lt>arpa/inet.hE<gt>\n"
1111 "#include E<lt>errno.hE<gt>\n"
1112 "#include E<lt>netinet/in.hE<gt>\n"
1113 "#include E<lt>signal.hE<gt>\n"
1114 "#include E<lt>stdio.hE<gt>\n"
1115 "#include E<lt>stdlib.hE<gt>\n"
1116 "#include E<lt>string.hE<gt>\n"
1117 "#include E<lt>sys/select.hE<gt>\n"
1118 "#include E<lt>sys/socket.hE<gt>\n"
1119 "#include E<lt>sys/types.hE<gt>\n"
1120 "#include E<lt>unistd.hE<gt>\n"
1121 "\\&\n"
1122 "static int forward_port;\n"
1123 "\\&\n"
1124 "#undef max\n"
1125 "#define max(x, y) ((x) E<gt> (y) ? (x) : (y))\n"
1126 "\\&\n"
1127 "static int\n"
1128 "listen_socket(int listen_port)\n"
1129 "{\n"
1130 " int lfd;\n"
1131 " int yes;\n"
1132 " struct sockaddr_in addr;\n"
1133 "\\&\n"
1134 " lfd = socket(AF_INET, SOCK_STREAM, 0);\n"
1135 " if (lfd == -1) {\n"
1136 " perror(\"socket\");\n"
1137 " return -1;\n"
1138 " }\n"
1139 "\\&\n"
1140 " yes = 1;\n"
1141 " if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n"
1142 " &yes, sizeof(yes)) == -1)\n"
1143 " {\n"
1144 " perror(\"setsockopt\");\n"
1145 " close(lfd);\n"
1146 " return -1;\n"
1147 " }\n"
1148 "\\&\n"
1149 " memset(&addr, 0, sizeof(addr));\n"
1150 " addr.sin_port = htons(listen_port);\n"
1151 " addr.sin_family = AF_INET;\n"
1152 " if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n"
1153 " perror(\"bind\");\n"
1154 " close(lfd);\n"
1155 " return -1;\n"
1156 " }\n"
1157 "\\&\n"
1158 " printf(\"accepting connections on port %d\\[rs]n\", listen_port);\n"
1159 " listen(lfd, 10);\n"
1160 " return lfd;\n"
1161 "}\n"
1162 "\\&\n"
1163 "static int\n"
1164 "connect_socket(int connect_port, char *address)\n"
1165 "{\n"
1166 " int cfd;\n"
1167 " struct sockaddr_in addr;\n"
1168 "\\&\n"
1169 " cfd = socket(AF_INET, SOCK_STREAM, 0);\n"
1170 " if (cfd == -1) {\n"
1171 " perror(\"socket\");\n"
1172 " return -1;\n"
1173 " }\n"
1174 "\\&\n"
1175 " memset(&addr, 0, sizeof(addr));\n"
1176 " addr.sin_port = htons(connect_port);\n"
1177 " addr.sin_family = AF_INET;\n"
1178 "\\&\n"
1179 " if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n"
1180 " fprintf(stderr, \"inet_aton(): bad IP address format\\[rs]n\");\n"
1181 " close(cfd);\n"
1182 " return -1;\n"
1183 " }\n"
1184 "\\&\n"
1185 " if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n"
1186 " perror(\"connect()\");\n"
1187 " shutdown(cfd, SHUT_RDWR);\n"
1188 " close(cfd);\n"
1189 " return -1;\n"
1190 " }\n"
1191 " return cfd;\n"
1192 "}\n"
1193 "\\&\n"
1194 "#define SHUT_FD1 do { \\[rs]\n"
1195 " if (fd1 E<gt>= 0) { \\[rs]\n"
1196 " shutdown(fd1, SHUT_RDWR); \\[rs]\n"
1197 " close(fd1); \\[rs]\n"
1198 " fd1 = -1; \\[rs]\n"
1199 " } \\[rs]\n"
1200 " } while (0)\n"
1201 "\\&\n"
1202 "#define SHUT_FD2 do { \\[rs]\n"
1203 " if (fd2 E<gt>= 0) { \\[rs]\n"
1204 " shutdown(fd2, SHUT_RDWR); \\[rs]\n"
1205 " close(fd2); \\[rs]\n"
1206 " fd2 = -1; \\[rs]\n"
1207 " } \\[rs]\n"
1208 " } while (0)\n"
1209 "\\&\n"
1210 "#define BUF_SIZE 1024\n"
1211 "\\&\n"
1212 "int\n"
1213 "main(int argc, char *argv[])\n"
1214 "{\n"
1215 " int h;\n"
1216 " int ready, nfds;\n"
1217 " int fd1 = -1, fd2 = -1;\n"
1218 " int buf1_avail = 0, buf1_written = 0;\n"
1219 " int buf2_avail = 0, buf2_written = 0;\n"
1220 " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n"
1221 " fd_set readfds, writefds, exceptfds;\n"
1222 " ssize_t nbytes;\n"
1223 "\\&\n"
1224 " if (argc != 4) {\n"
1225 " fprintf(stderr, \"Usage\\[rs]n\\[rs]tfwd E<lt>listen-portE<gt> \"\n"
1226 " \"E<lt>forward-to-portE<gt> E<lt>forward-to-ip-addressE<gt>\\[rs]n\");\n"
1227 " exit(EXIT_FAILURE);\n"
1228 " }\n"
1229 "\\&\n"
1230 " signal(SIGPIPE, SIG_IGN);\n"
1231 "\\&\n"
1232 " forward_port = atoi(argv[2]);\n"
1233 "\\&\n"
1234 " h = listen_socket(atoi(argv[1]));\n"
1235 " if (h == -1)\n"
1236 " exit(EXIT_FAILURE);\n"
1237 "\\&\n"
1238 " for (;;) {\n"
1239 " nfds = 0;\n"
1240 "\\&\n"
1241 " FD_ZERO(&readfds);\n"
1242 " FD_ZERO(&writefds);\n"
1243 " FD_ZERO(&exceptfds);\n"
1244 " FD_SET(h, &readfds);\n"
1245 " nfds = max(nfds, h);\n"
1246 "\\&\n"
1247 " if (fd1 E<gt> 0 && buf1_avail E<lt> BUF_SIZE)\n"
1248 " FD_SET(fd1, &readfds);\n"
1249 " /* Note: nfds is updated below, when fd1 is added to\n"
1250 " exceptfds. */\n"
1251 " if (fd2 E<gt> 0 && buf2_avail E<lt> BUF_SIZE)\n"
1252 " FD_SET(fd2, &readfds);\n"
1253 "\\&\n"
1254 " if (fd1 E<gt> 0 && buf2_avail - buf2_written E<gt> 0)\n"
1255 " FD_SET(fd1, &writefds);\n"
1256 " if (fd2 E<gt> 0 && buf1_avail - buf1_written E<gt> 0)\n"
1257 " FD_SET(fd2, &writefds);\n"
1258 "\\&\n"
1259 " if (fd1 E<gt> 0) {\n"
1260 " FD_SET(fd1, &exceptfds);\n"
1261 " nfds = max(nfds, fd1);\n"
1262 " }\n"
1263 " if (fd2 E<gt> 0) {\n"
1264 " FD_SET(fd2, &exceptfds);\n"
1265 " nfds = max(nfds, fd2);\n"
1266 " }\n"
1267 "\\&\n"
1268 " ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n"
1269 "\\&\n"
1270 " if (ready == -1 && errno == EINTR)\n"
1271 " continue;\n"
1272 "\\&\n"
1273 " if (ready == -1) {\n"
1274 " perror(\"select()\");\n"
1275 " exit(EXIT_FAILURE);\n"
1276 " }\n"
1277 "\\&\n"
1278 " if (FD_ISSET(h, &readfds)) {\n"
1279 " socklen_t addrlen;\n"
1280 " struct sockaddr_in client_addr;\n"
1281 " int fd;\n"
1282 "\\&\n"
1283 " addrlen = sizeof(client_addr);\n"
1284 " memset(&client_addr, 0, addrlen);\n"
1285 " fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n"
1286 " if (fd == -1) {\n"
1287 " perror(\"accept()\");\n"
1288 " } else {\n"
1289 " SHUT_FD1;\n"
1290 " SHUT_FD2;\n"
1291 " buf1_avail = buf1_written = 0;\n"
1292 " buf2_avail = buf2_written = 0;\n"
1293 " fd1 = fd;\n"
1294 " fd2 = connect_socket(forward_port, argv[3]);\n"
1295 " if (fd2 == -1)\n"
1296 " SHUT_FD1;\n"
1297 " else\n"
1298 " printf(\"connect from %s\\[rs]n\",\n"
1299 " inet_ntoa(client_addr.sin_addr));\n"
1300 "\\&\n"
1301 " /* Skip any events on the old, closed file\n"
1302 " descriptors. */\n"
1303 "\\&\n"
1304 " continue;\n"
1305 " }\n"
1306 " }\n"
1307 "\\&\n"
1308 " /* NB: read OOB data before normal reads. */\n"
1309 "\\&\n"
1310 " if (fd1 E<gt> 0 && FD_ISSET(fd1, &exceptfds)) {\n"
1311 " char c;\n"
1312 "\\&\n"
1313 " nbytes = recv(fd1, &c, 1, MSG_OOB);\n"
1314 " if (nbytes E<lt> 1)\n"
1315 " SHUT_FD1;\n"
1316 " else\n"
1317 " send(fd2, &c, 1, MSG_OOB);\n"
1318 " }\n"
1319 " if (fd2 E<gt> 0 && FD_ISSET(fd2, &exceptfds)) {\n"
1320 " char c;\n"
1321 "\\&\n"
1322 " nbytes = recv(fd2, &c, 1, MSG_OOB);\n"
1323 " if (nbytes E<lt> 1)\n"
1324 " SHUT_FD2;\n"
1325 " else\n"
1326 " send(fd1, &c, 1, MSG_OOB);\n"
1327 " }\n"
1328 " if (fd1 E<gt> 0 && FD_ISSET(fd1, &readfds)) {\n"
1329 " nbytes = read(fd1, buf1 + buf1_avail,\n"
1330 " BUF_SIZE - buf1_avail);\n"
1331 " if (nbytes E<lt> 1)\n"
1332 " SHUT_FD1;\n"
1333 " else\n"
1334 " buf1_avail += nbytes;\n"
1335 " }\n"
1336 " if (fd2 E<gt> 0 && FD_ISSET(fd2, &readfds)) {\n"
1337 " nbytes = read(fd2, buf2 + buf2_avail,\n"
1338 " BUF_SIZE - buf2_avail);\n"
1339 " if (nbytes E<lt> 1)\n"
1340 " SHUT_FD2;\n"
1341 " else\n"
1342 " buf2_avail += nbytes;\n"
1343 " }\n"
1344 " if (fd1 E<gt> 0 && FD_ISSET(fd1, &writefds) && buf2_avail E<gt> 0) {\n"
1345 " nbytes = write(fd1, buf2 + buf2_written,\n"
1346 " buf2_avail - buf2_written);\n"
1347 " if (nbytes E<lt> 1)\n"
1348 " SHUT_FD1;\n"
1349 " else\n"
1350 " buf2_written += nbytes;\n"
1351 " }\n"
1352 " if (fd2 E<gt> 0 && FD_ISSET(fd2, &writefds) && buf1_avail E<gt> 0) {\n"
1353 " nbytes = write(fd2, buf1 + buf1_written,\n"
1354 " buf1_avail - buf1_written);\n"
1355 " if (nbytes E<lt> 1)\n"
1356 " SHUT_FD2;\n"
1357 " else\n"
1358 " buf1_written += nbytes;\n"
1359 " }\n"
1360 "\\&\n"
1361 " /* Check if write data has caught read data. */\n"
1362 "\\&\n"
1363 " if (buf1_written == buf1_avail)\n"
1364 " buf1_written = buf1_avail = 0;\n"
1365 " if (buf2_written == buf2_avail)\n"
1366 " buf2_written = buf2_avail = 0;\n"
1367 "\\&\n"
1368 " /* One side has closed the connection, keep\n"
1369 " writing to the other side until empty. */\n"
1370 "\\&\n"
1371 " if (fd1 E<lt> 0 && buf1_avail - buf1_written == 0)\n"
1372 " SHUT_FD2;\n"
1373 " if (fd2 E<lt> 0 && buf2_avail - buf2_written == 0)\n"
1374 " SHUT_FD1;\n"
1375 " }\n"
1376 " exit(EXIT_SUCCESS);\n"
1377 "}\n"
1378 msgstr ""
1379
1380 #. type: TH
1381 #: fedora-44 fedora-rawhide
1382 #, no-wrap
1383 msgid "2024-07-23"
1384 msgstr "23 ​​Julio 2024"
1385
1386 #. type: TH
1387 #: fedora-44 fedora-rawhide
1388 #, no-wrap
1389 msgid "Linux man-pages 6.13"
1390 msgstr "Páginas de Manual de Linux 6.13"
1391
1392 #. type: TH
1393 #: mageia-cauldron
1394 #, no-wrap
1395 msgid "Linux man-pages 6.17"
1396 msgstr "Páginas de Manual de Linux 6.17"
1397
1398 #. type: TH
1399 #: opensuse-leap-16-1 opensuse-tumbleweed
1400 #, no-wrap
1401 msgid "Linux man-pages (unreleased)"
1402 msgstr "Páginas de Manual de Linux (no publicadas)"