2004-11-03 13:51:07 +00:00
|
|
|
.\" This manpage is copyright (C) 2001 Paul Sheer.
|
|
|
|
.\"
|
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir.2, chmod.2, chown.2, chroot.2, clock_getres.2, clock_nanosleep.2, close.2, connect.2, delete_module.2, dup.2, execve.2, exit_group.2, faccessat.2, fchmodat.2, fchownat.2, fcntl.2, fork.2, fstatat.2, fsync.2, futimesat.2, get_robust_list.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getpagesize.2, getpid.2, getresuid.2, getrlimit.2, getrusage.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, idle.2, init_module.2, intro.2, iopl.2, kcmp.2, kexec_load.2, kill.2, link.2, linkat.2, llseek.2, lookup_dcookie.2, madvise.2, mincore.2, mkdirat.2, mknodat.2, mmap.2, mmap2.2, mount.2, mprotect.2, mq_getsetattr.2, msgctl.2, msgget.2, msgop.2, msync.2, nice.2, open.2, openat.2, pause.2, perfmonctl.2, personality.2, pipe.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, quotactl.2, read.2, readahead.2, readdir.2, readlinkat.2, readv.2, reboot.2, recvmmsg.2, remap_file_pages.2, rename.2, renameat.2, rmdir.2, rt_sigqueueinfo.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, sendmmsg.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setresuid.2, setuid.2, setup.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, signal.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, splice.2, stat.2, statfs.2, stime.2, subpage_prot.2, swapon.2, symlink.2, symlinkat.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysfs.2, syslog.2, tee.2, time.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, times.2, tkill.2, umask.2, umount.2, uname.2, unlink.2, unlinkat.2, uselib.2, ustat.2, utime.2, utimensat.2, vfork.2, vhangup.2, vm86.2, vmsplice.2, wait.2, wait4.2, write.2, CPU_SET.3, INFINITY.3, abort.3, abs.3, acos.3, acosh.3, adjtime.3, aio_init.3, asin.3, asinh.3, asprintf.3, assert.3, assert_perror.3, atan.3, atan2.3, atanh.3, atexit.3, atof.3, atoi.3, basename.3, bcmp.3, bcopy.3, bindresvport.3, bsd_signal.3, bsearch.3, bstring.3, byteorder.3, bzero.3, catgets.3, catopen.3, cbrt.3, ceil.3, clearenv.3, clock.3, clock_getcpuclockid.3, closedir.3, confstr.3, copysign.3, cos.3, cosh.3, ctermid.3, ctime.3, difftime.3, dirfd.3, div.3, dl_iterate_phdr.3, dprintf.3, drand48.3, drand48_r.3, dysize.3, ecvt.3, ecvt_r.3, end.3, endian.3, erf.3, erfc.3, ether_aton.3, euidaccess.3, exit.3, exp.3, exp10.3, exp2.3, expm1.3, fabs.3, fcloseall.3, fexecve.3, ffs.3, fgetgrent.3, fgetpwent.3, finite.3, flockfile.3, floor.3, fmod.3, fnmatch.3, fopencookie.3, fpathconf.3, fpurge.3, frexp.3, fseeko.3, ftok.3, futimes.3, gcvt.3, get_nprocs_conf.3, getaddrinfo.3, getaddrinfo_a.3, getauxval.3, getcontext.3, getcwd.3, getdate.3, getdirentries.3, getdtablesize.3, getenv.3, getfsent.3, getgrent.3, getgrnam.3, getgrouplist.3, gethostbyname.3, gethostid.3, getifaddrs.3, getipnodebyname.3, getline.3, getlogin.3, getmntent.3, getnetent.3, getnetent_r.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwnam.3, getrpcent_r.3, gets.3, getservent.3, getservent_r.3, getumask.3, getusershell.3, getutmp.3, getw.3, glob.3, gnu_get_libc_version.3, gsignal.3, hypot.3, if_nameindex.3, if_nametoindex.3, ilogb.3, index.3, inet.3, inet_ntop.3, inet_pton.3, infnan.3, initgroups.3, insque.3, intro.3, isalpha.3, isatty.3, j0.3, ldexp.3, localeconv.3, log.3, log10.3, log1p.3, log2.3, logb.3, lrint.3, lround.3, lsearch.3, lseek64.3, makecontext.3, makedev.3, mallinfo.3, malloc.3, malloc_get_state.3, malloc_info.3, malloc_stats.3, malloc_trim.3, malloc_usable_size.3, mallopt.3, matherr.3, mcheck.3, memccpy.3, memchr.3, memcmp.3, memcpy.3, memfrob.3, memmem.3, memmove.3, memset.3, mkdtemp.3, mkfifo.3, mkfifoat.3, mkstemp.3, mktemp.3, modf.3, mq_close.3, mq_getattr.3, mq_notify.3, mq_open.3, mq_receive.3, mq_send.3, mq_unlink.3, mtrace.3, on_exit.3, opendir.3, posix_fallocate.3, posix_memalign.3, posix_openpt.3, pow.3, pow10.3, profil.3, psignal.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_detach.3, pthread_equal.3, pthread_exit.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_join.3, pthread_kill.3, pthread_kill_other_threads_np.3, pthread_self.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_setschedprio.3, pthread_sigmask.3, pthread_sigqueue.3, pthread_testcancel.3, pthread_tryjoin_np.3, pthread_yield.3, putenv.3, putpwent.3, puts.3, qecvt.3, qsort.3, raise.3, rand.3, random.3, random_r.3, re_comp.3, readdir.3, realpath.3, regex.3, remainder.3, remove.3, resolver.3, rewinddir.3, rint.3, round.3, scalb.3, scalbln.3, scandir.3, sched_getcpu.3, seekdir.3, sem_close.3, sem_destroy.3, sem_getvalue.3, sem_init.3, sem_open.3, sem_post.3, sem_unlink.3, sem_wait.3, setenv.3, setlocale.3, setlogmask.3, shm_open.3, siginterrupt.3, sigpause.3, sigqueue.3, sigset.3, sigsetops.3, sigvec.3, sigwait.3, sin.3, sinh.3, sleep.3, sockatmark.3, sqrt.3, statvfs.3, stdio_ext.3, stpcpy.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strdup.3, strerror.3, strfry.3, strftime.3, string.3, strlen.3, strpbrk.3, strptime.3, strsep.3, strsignal.3, strspn.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, swab.3, sysconf.3, syslog.3, system.3, sysv_signal.3, tan.3, tanh.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tempnam.3, timegm.3, timeradd.3, tmpfile.3, tmpnam.3, toascii.3, toupper.3, trunc.3, tsearch.3, ttyslot.3, tzset.3, ulimit.3, undocumented.3, unlocked_stdio.3, usleep.3, y0.3, cpuid.4, full.4, initrd.4, mouse.4, msr.4, sd.4, st.4, acct.5, core.5, services.5, slabinfo.5, aio.7, capabilities.7, credentials.7, feature_test_macros.7, hier.7, inotify.7, libc.7, locale.7, man-pages.7, man.7, math_error.7, mq_overview.7, numa.7, path_resolution.7, pipe.7, pthreads.7, pty.7, rtld-audit.7, sem_overview.7, shm_overview.7, sigevent.7, signal.7, suffixes.7, svipc.7, termio.7, time.7, udplite.7, units.7, uri.7, sln.8: s/LICENSE_START(verbatim)/LICENSE_START(VERBATIM)/
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-10 09:29:01 +00:00
|
|
|
.\" %%%LICENSE_START(VERBATIM)
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir.2, chmod.2, chown.2, chroot.2, clock_getres.2, clock_nanosleep.2, close.2, connect.2, delete_module.2, dup.2, execve.2, exit_group.2, faccessat.2, fchmodat.2, fchownat.2, fcntl.2, fork.2, fstatat.2, fsync.2, futimesat.2, get_robust_list.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getpagesize.2, getpid.2, getresuid.2, getrlimit.2, getrusage.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, idle.2, init_module.2, intro.2, iopl.2, kcmp.2, kexec_load.2, kill.2, link.2, linkat.2, llseek.2, lookup_dcookie.2, madvise.2, mincore.2, mkdirat.2, mknodat.2, mmap.2, mmap2.2, mount.2, mprotect.2, mq_getsetattr.2, msgctl.2, msgget.2, msgop.2, msync.2, nice.2, open.2, openat.2, pause.2, perfmonctl.2, personality.2, pipe.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, quotactl.2, read.2, readahead.2, readdir.2, readlinkat.2, readv.2, reboot.2, recvmmsg.2, remap_file_pages.2, rename.2, renameat.2, rmdir.2, rt_sigqueueinfo.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, sendmmsg.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setresuid.2, setuid.2, setup.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, signal.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, splice.2, stat.2, statfs.2, stime.2, subpage_prot.2, swapon.2, symlink.2, symlinkat.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysfs.2, syslog.2, tee.2, time.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, times.2, tkill.2, umask.2, umount.2, uname.2, unlink.2, unlinkat.2, uselib.2, ustat.2, utime.2, utimensat.2, vfork.2, vhangup.2, vm86.2, vmsplice.2, wait.2, wait4.2, write.2, CPU_SET.3, INFINITY.3, abort.3, abs.3, acos.3, acosh.3, adjtime.3, aio_init.3, asin.3, asinh.3, asprintf.3, assert.3, assert_perror.3, atan.3, atan2.3, atanh.3, atexit.3, atof.3, atoi.3, basename.3, bcmp.3, bcopy.3, bindresvport.3, bsd_signal.3, bsearch.3, bstring.3, byteorder.3, bzero.3, catgets.3, catopen.3, cbrt.3, ceil.3, clearenv.3, clock.3, clock_getcpuclockid.3, closedir.3, confstr.3, copysign.3, cos.3, cosh.3, ctermid.3, ctime.3, difftime.3, dirfd.3, div.3, dl_iterate_phdr.3, dprintf.3, drand48.3, drand48_r.3, dysize.3, ecvt.3, ecvt_r.3, end.3, endian.3, erf.3, erfc.3, ether_aton.3, euidaccess.3, exit.3, exp.3, exp10.3, exp2.3, expm1.3, fabs.3, fcloseall.3, fexecve.3, ffs.3, fgetgrent.3, fgetpwent.3, finite.3, flockfile.3, floor.3, fmod.3, fnmatch.3, fopencookie.3, fpathconf.3, fpurge.3, frexp.3, fseeko.3, ftok.3, futimes.3, gcvt.3, get_nprocs_conf.3, getaddrinfo.3, getaddrinfo_a.3, getauxval.3, getcontext.3, getcwd.3, getdate.3, getdirentries.3, getdtablesize.3, getenv.3, getfsent.3, getgrent.3, getgrnam.3, getgrouplist.3, gethostbyname.3, gethostid.3, getifaddrs.3, getipnodebyname.3, getline.3, getlogin.3, getmntent.3, getnetent.3, getnetent_r.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwnam.3, getrpcent_r.3, gets.3, getservent.3, getservent_r.3, getumask.3, getusershell.3, getutmp.3, getw.3, glob.3, gnu_get_libc_version.3, gsignal.3, hypot.3, if_nameindex.3, if_nametoindex.3, ilogb.3, index.3, inet.3, inet_ntop.3, inet_pton.3, infnan.3, initgroups.3, insque.3, intro.3, isalpha.3, isatty.3, j0.3, ldexp.3, localeconv.3, log.3, log10.3, log1p.3, log2.3, logb.3, lrint.3, lround.3, lsearch.3, lseek64.3, makecontext.3, makedev.3, mallinfo.3, malloc.3, malloc_get_state.3, malloc_info.3, malloc_stats.3, malloc_trim.3, malloc_usable_size.3, mallopt.3, matherr.3, mcheck.3, memccpy.3, memchr.3, memcmp.3, memcpy.3, memfrob.3, memmem.3, memmove.3, memset.3, mkdtemp.3, mkfifo.3, mkfifoat.3, mkstemp.3, mktemp.3, modf.3, mq_close.3, mq_getattr.3, mq_notify.3, mq_open.3, mq_receive.3, mq_send.3, mq_unlink.3, mtrace.3, on_exit.3, opendir.3, posix_fallocate.3, posix_memalign.3, posix_openpt.3, pow.3, pow10.3, profil.3, psignal.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_detach.3, pthread_equal.3, pthread_exit.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_join.3, pthread_kill.3, pthread_kill_other_threads_np.3, pthread_self.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_setschedprio.3, pthread_sigmask.3, pthread_sigqueue.3, pthread_testcancel.3, pthread_tryjoin_np.3, pthread_yield.3, putenv.3, putpwent.3, puts.3, qecvt.3, qsort.3, raise.3, rand.3, random.3, random_r.3, re_comp.3, readdir.3, realpath.3, regex.3, remainder.3, remove.3, resolver.3, rewinddir.3, rint.3, round.3, scalb.3, scalbln.3, scandir.3, sched_getcpu.3, seekdir.3, sem_close.3, sem_destroy.3, sem_getvalue.3, sem_init.3, sem_open.3, sem_post.3, sem_unlink.3, sem_wait.3, setenv.3, setlocale.3, setlogmask.3, shm_open.3, siginterrupt.3, sigpause.3, sigqueue.3, sigset.3, sigsetops.3, sigvec.3, sigwait.3, sin.3, sinh.3, sleep.3, sockatmark.3, sqrt.3, statvfs.3, stdio_ext.3, stpcpy.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strdup.3, strerror.3, strfry.3, strftime.3, string.3, strlen.3, strpbrk.3, strptime.3, strsep.3, strsignal.3, strspn.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, swab.3, sysconf.3, syslog.3, system.3, sysv_signal.3, tan.3, tanh.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tempnam.3, timegm.3, timeradd.3, tmpfile.3, tmpnam.3, toascii.3, toupper.3, trunc.3, tsearch.3, ttyslot.3, tzset.3, ulimit.3, undocumented.3, unlocked_stdio.3, usleep.3, y0.3, cpuid.4, full.4, initrd.4, mouse.4, msr.4, sd.4, st.4, acct.5, core.5, services.5, slabinfo.5, aio.7, capabilities.7, credentials.7, feature_test_macros.7, hier.7, inotify.7, libc.7, locale.7, man-pages.7, man.7, math_error.7, mq_overview.7, numa.7, path_resolution.7, pipe.7, pthreads.7, pty.7, rtld-audit.7, sem_overview.7, shm_overview.7, sigevent.7, signal.7, suffixes.7, svipc.7, termio.7, time.7, udplite.7, units.7, uri.7, sln.8: Global fix: Add LICENSE_START(verbatim)
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-10 09:28:40 +00:00
|
|
|
.\" %%%LICENSE_END
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
|
|
|
.\" very minor changes, aeb
|
|
|
|
.\"
|
2007-09-20 06:52:22 +00:00
|
|
|
.\" Modified 5 June 2002, Michael Kerrisk <mtk.manpages@gmail.com>
|
2006-05-13 06:04:35 +00:00
|
|
|
.\" 2006-05-13, mtk, removed much material that is redundant with select.2
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" various other changes
|
2009-01-26 02:04:19 +00:00
|
|
|
.\" 2008-01-26, mtk, substantial changes and rewrites
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
getent.1, localedef.1, accept.2, arch_prctl.2, clock_getres.2, clock_nanosleep.2, connect.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, execve.2, getitimer.2, getsockopt.2, gettid.2, inotify_add_watch.2, inotify_init.2, io_submit.2, ioctl.2, lseek.2, madvise.2, mlock.2, mmap.2, mprotect.2, msgctl.2, msgop.2, open_by_handle_at.2, openat2.2, pidfd_open.2, poll.2, prctl.2, quotactl.2, s390_sthyi.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, setns.2, shmctl.2, shmget.2, shmop.2, sigaction.2, stat.2, statx.2, syscalls.2, timer_create.2, timerfd_create.2, unshare.2, wait.2, CPU_SET.3, aio_init.3, atoi.3, des_crypt.3, dirfd.3, fmemopen.3, fopencookie.3, ftok.3, fts.3, getaddrinfo.3, getifaddrs.3, getrpcent.3, gsignal.3, lio_listio.3, nl_langinfo.3, posix_memalign.3, posix_openpt.3, posix_spawn.3, scanf.3, sem_init.3, sem_post.3, shm_open.3, strcmp.3, strftime.3, st.4, elf.5, group.5, proc.5, services.5, aio.7, cgroups.7, feature_test_macros.7, keyrings.7, man-pages.7, namespaces.7, path_resolution.7, sigevent.7, signal.7, socket.7, sysvipc.7, time.7, udp.7: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-04-11 20:07:24 +00:00
|
|
|
.TH SELECT_TUT 2 2020-04-11 "Linux" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
2020-02-18 10:14:45 +00:00
|
|
|
select, pselect \- synchronous I/O multiplexing
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH SYNOPSIS
|
2020-02-18 08:22:16 +00:00
|
|
|
See
|
|
|
|
.BR select (2)
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
2020-02-19 08:37:46 +00:00
|
|
|
The
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR select ()
|
2020-02-19 08:37:46 +00:00
|
|
|
and
|
|
|
|
.BR pselect ()
|
|
|
|
system calls are used to efficiently monitor multiple file descriptors,
|
2009-01-26 02:04:19 +00:00
|
|
|
to see if any of them is, or becomes, "ready";
|
|
|
|
that is, to see whether I/O becomes possible,
|
2016-01-01 10:45:50 +00:00
|
|
|
or an "exceptional condition" has occurred on any of the file descriptors.
|
_syscall.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, copy_file_range.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, execveat.2, fallocate.2, flock.2, fork.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_mempolicy.2, get_robust_list.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpriority.2, getrandom.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl_fat.2, ioctl_ficlonerange.2, ioctl_fideduperange.2, ioctl_tty.2, ioctl_userfaultfd.2, ioperm.2, iopl.2, ioprio_set.2, kcmp.2, kexec_load.2, keyctl.2, kill.2, link.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, mbind.2, membarrier.2, memfd_create.2, migrate_pages.2, mincore.2, mkdir.2, mknod.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open_by_handle_at.2, outb.2, perf_event_open.2, perfmonctl.2, personality.2, pivot_root.2, pkey_alloc.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readv.2, reboot.2, recv.2, recvmmsg.2, remap_file_pages.2, rename.2, request_key.2, restart_syscall.2, rt_sigqueueinfo.2, s390_pci_mmio_write.2, s390_runtime_instr.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, seccomp.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, sendmmsg.2, set_mempolicy.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setns.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, spu_create.2, spu_run.2, stat.2, statfs.2, statx.2, subpage_prot.2, swapon.2, symlink.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysinfo.2, syslog.2, tee.2, time.2, timer_create.2, timer_getoverrun.2, timer_settime.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, unimplemented.2, unlink.2, unshare.2, uselib.2, userfaultfd.2, utime.2, utimensat.2, vfork.2, vmsplice.2, wait.2, wait4.2, write.2: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 07:30:51 +00:00
|
|
|
.PP
|
2020-02-18 10:14:45 +00:00
|
|
|
This page provides background and tutorial information
|
|
|
|
on the use of these system calls.
|
|
|
|
For details of the arguments and semantics of
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR select ()
|
|
|
|
and
|
2020-02-18 10:14:45 +00:00
|
|
|
.BR pselect (),
|
|
|
|
see
|
|
|
|
.BR select (2).
|
|
|
|
.\"
|
intro.1, time.1, _syscall.2, accept.2, brk.2, capget.2, faccessat.2, futimesat.2, gethostname.2, intro.2, ioprio_set.2, kill.2, madvise.2, mlock.2, mount.2, msgget.2, perf_event_open.2, poll.2, readv.2, sched_rr_get_interval.2, sched_setscheduler.2, select.2, select_tut.2, shmget.2, stat.2, timer_create.2, ustat.2, vfork.2, wait.2, alloca.3, atexit.3, catopen.3, crypt.3, dbopen.3, fenv.3, fopen.3, getaddrinfo_a.3, gethostbyname.3, getutent.3, intro.3, login.3, mallopt.3, queue.3, regex.3, sigpause.3, sigsetops.3, stdio.3, strftime.3, strptime.3, sysconf.3, ttyslot.3, undocumented.3, cciss.4, console_codes.4, hpsa.4, initrd.4, intro.4, rtc.4, st.4, tty_ioctl.4, wavelan.4, acct.5, charmap.5, dir_colors.5, hosts.5, intro.5, termcap.5, utmp.5, intro.6, armscii-8.7, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, ddp.7, epoll.7, glob.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, man-pages.7, man.7, math_error.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, pthreads.7, raw.7, rtnetlink.7, signal.7, socket.7, spufs.7, svipc.7, tcp.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, intro.8: Global fix: use consistent capitalization in .SS headings
Capitalization in .SS sections across pages (and sometimes even
within a single page) is wildly inconsistent. Make it consistent.
Capitalize first word in heading, but otherwise use lower case,
except where English usage (e.g., proper nouns) or programming
language requirements (e.g., identifier names) dictate otherwise.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 14:08:38 +00:00
|
|
|
.SS Combining signal and data events
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR pselect ()
|
2009-01-26 02:04:19 +00:00
|
|
|
is useful if you are waiting for a signal as well as
|
|
|
|
for file descriptor(s) to become ready for I/O.
|
|
|
|
Programs that receive signals
|
2007-04-12 22:42:49 +00:00
|
|
|
normally use the signal handler only to raise a global flag.
|
2009-01-26 02:04:19 +00:00
|
|
|
The global flag will indicate that the event must be processed
|
|
|
|
in the main loop of the program.
|
2007-05-12 09:06:04 +00:00
|
|
|
A signal will cause the
|
|
|
|
.BR select ()
|
|
|
|
(or
|
|
|
|
.BR pselect ())
|
2007-04-12 22:42:49 +00:00
|
|
|
call to return with \fIerrno\fP set to \fBEINTR\fP.
|
2009-01-26 02:04:19 +00:00
|
|
|
This behavior is essential so that signals can be processed
|
|
|
|
in the main loop of the program, otherwise
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR select ()
|
|
|
|
would block indefinitely.
|
2020-02-18 10:18:38 +00:00
|
|
|
.PP
|
2007-04-12 22:42:49 +00:00
|
|
|
Now, somewhere
|
|
|
|
in the main loop will be a conditional to check the global flag.
|
2009-01-26 02:04:19 +00:00
|
|
|
So we must ask:
|
|
|
|
what if a signal arrives after the conditional, but before the
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR select ()
|
|
|
|
call?
|
|
|
|
The answer is that
|
|
|
|
.BR select ()
|
2009-01-26 02:04:19 +00:00
|
|
|
would block indefinitely, even though an event is actually pending.
|
|
|
|
This race condition is solved by the
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR pselect ()
|
|
|
|
call.
|
2009-09-27 07:26:31 +00:00
|
|
|
This call can be used to set the signal mask to a set of signals
|
2015-01-28 09:21:36 +00:00
|
|
|
that are to be received only within the
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR pselect ()
|
|
|
|
call.
|
2007-04-12 22:42:49 +00:00
|
|
|
For instance, let us say that the event in question
|
|
|
|
was the exit of a child process.
|
|
|
|
Before the start of the main loop, we
|
2007-05-12 09:06:04 +00:00
|
|
|
would block \fBSIGCHLD\fP using
|
|
|
|
.BR sigprocmask (2).
|
|
|
|
Our
|
|
|
|
.BR pselect ()
|
2009-01-26 02:04:19 +00:00
|
|
|
call would enable
|
|
|
|
.B SIGCHLD
|
|
|
|
by using an empty signal mask.
|
|
|
|
Our program would look like:
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
intro.1, locale.1, ioctl_list.2, listxattr.2, memfd_create.2, nfsservctl.2, open_by_handle_at.2, perf_event_open.2, poll.2, process_vm_readv.2, ptrace.2, select.2, select_tut.2, semop.2, sendmmsg.2, shmget.2, sigaction.2, spu_run.2, umask.2, wait4.2, nan.3, setlocale.3, feature_test_macros.7, glob.7, posixoptions.7, rtld-audit.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-19 10:56:40 +00:00
|
|
|
.EX
|
2009-01-26 01:59:50 +00:00
|
|
|
static volatile sig_atomic_t got_SIGCHLD = 0;
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2009-01-26 01:59:50 +00:00
|
|
|
static void
|
|
|
|
child_sig_handler(int sig)
|
2007-04-05 12:36:57 +00:00
|
|
|
{
|
2009-01-26 01:59:50 +00:00
|
|
|
got_SIGCHLD = 1;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
int
|
2009-01-26 01:59:50 +00:00
|
|
|
main(int argc, char *argv[])
|
2007-04-05 12:36:57 +00:00
|
|
|
{
|
2009-01-26 01:59:50 +00:00
|
|
|
sigset_t sigmask, empty_mask;
|
|
|
|
struct sigaction sa;
|
|
|
|
fd_set readfds, writefds, exceptfds;
|
|
|
|
int r;
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2007-04-05 12:36:57 +00:00
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGCHLD);
|
2009-01-26 01:59:50 +00:00
|
|
|
if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == \-1) {
|
|
|
|
perror("sigprocmask");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
sa.sa_handler = child_sig_handler;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
if (sigaction(SIGCHLD, &sa, NULL) == \-1) {
|
|
|
|
perror("sigaction");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2009-02-10 06:26:37 +00:00
|
|
|
sigemptyset(&empty_mask);
|
2009-01-26 01:59:50 +00:00
|
|
|
|
|
|
|
for (;;) { /* main loop */
|
|
|
|
/* Initialize readfds, writefds, and exceptfds
|
|
|
|
before the pselect() call. (Code omitted.) */
|
|
|
|
|
|
|
|
r = pselect(nfds, &readfds, &writefds, &exceptfds,
|
|
|
|
NULL, &empty_mask);
|
|
|
|
if (r == \-1 && errno != EINTR) {
|
|
|
|
/* Handle error */
|
|
|
|
}
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2009-01-26 01:59:50 +00:00
|
|
|
if (got_SIGCHLD) {
|
|
|
|
got_SIGCHLD = 0;
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2009-01-26 01:59:50 +00:00
|
|
|
/* Handle signalled event here; e.g., wait() for all
|
|
|
|
terminated children. (Code omitted.) */
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* main body of program */
|
|
|
|
}
|
|
|
|
}
|
intro.1, locale.1, ioctl_list.2, listxattr.2, memfd_create.2, nfsservctl.2, open_by_handle_at.2, perf_event_open.2, poll.2, process_vm_readv.2, ptrace.2, select.2, select_tut.2, semop.2, sendmmsg.2, shmget.2, sigaction.2, spu_run.2, umask.2, wait4.2, nan.3, setlocale.3, feature_test_macros.7, glob.7, posixoptions.7, rtld-audit.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-19 10:56:40 +00:00
|
|
|
.EE
|
2007-05-16 01:56:31 +00:00
|
|
|
.SS Practical
|
2007-05-12 09:06:04 +00:00
|
|
|
So what is the point of
|
|
|
|
.BR select ()?
|
2016-01-01 10:45:50 +00:00
|
|
|
Can't I just read and write to my file descriptors whenever I want?
|
2007-05-12 09:06:04 +00:00
|
|
|
The point of
|
|
|
|
.BR select ()
|
|
|
|
is that it watches
|
2004-11-03 13:51:07 +00:00
|
|
|
multiple descriptors at the same time and properly puts the process to
|
2007-04-12 22:42:49 +00:00
|
|
|
sleep if there is no activity.
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
UNIX programmers often find
|
2006-05-13 06:04:35 +00:00
|
|
|
themselves in a position where they have to handle I/O from more than one
|
2007-04-12 22:42:49 +00:00
|
|
|
file descriptor where the data flow may be intermittent.
|
2009-01-26 02:04:19 +00:00
|
|
|
If you were to merely create a sequence of
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR read (2)
|
|
|
|
and
|
|
|
|
.BR write (2)
|
|
|
|
calls, you would
|
2004-11-03 13:51:07 +00:00
|
|
|
find that one of your calls may block waiting for data from/to a file
|
2009-01-26 02:04:19 +00:00
|
|
|
descriptor, while another file descriptor is unused though ready for I/O.
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR select ()
|
|
|
|
efficiently copes with this situation.
|
intro.1, time.1, _syscall.2, accept.2, brk.2, capget.2, faccessat.2, futimesat.2, gethostname.2, intro.2, ioprio_set.2, kill.2, madvise.2, mlock.2, mount.2, msgget.2, perf_event_open.2, poll.2, readv.2, sched_rr_get_interval.2, sched_setscheduler.2, select.2, select_tut.2, shmget.2, stat.2, timer_create.2, ustat.2, vfork.2, wait.2, alloca.3, atexit.3, catopen.3, crypt.3, dbopen.3, fenv.3, fopen.3, getaddrinfo_a.3, gethostbyname.3, getutent.3, intro.3, login.3, mallopt.3, queue.3, regex.3, sigpause.3, sigsetops.3, stdio.3, strftime.3, strptime.3, sysconf.3, ttyslot.3, undocumented.3, cciss.4, console_codes.4, hpsa.4, initrd.4, intro.4, rtc.4, st.4, tty_ioctl.4, wavelan.4, acct.5, charmap.5, dir_colors.5, hosts.5, intro.5, termcap.5, utmp.5, intro.6, armscii-8.7, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, ddp.7, epoll.7, glob.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, man-pages.7, man.7, math_error.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, pthreads.7, raw.7, rtnetlink.7, signal.7, socket.7, spufs.7, svipc.7, tcp.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, intro.8: Global fix: use consistent capitalization in .SS headings
Capitalization in .SS sections across pages (and sometimes even
within a single page) is wildly inconsistent. Make it consistent.
Capitalize first word in heading, but otherwise use lower case,
except where English usage (e.g., proper nouns) or programming
language requirements (e.g., identifier names) dictate otherwise.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 14:08:38 +00:00
|
|
|
.SS Select law
|
2007-05-16 02:01:52 +00:00
|
|
|
Many people who try to use
|
|
|
|
.BR select ()
|
|
|
|
come across behavior that is
|
execve.2, fallocate.2, futex.2, sched_rr_get_interval.2, select_tut.2, shmget.2, timer_getoverrun.2, times.2, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_cleanup_push_defer_np.3, pthread_getattr_np.3, pthread_self.3, pthread_setaffinity_np.3, pthread_tryjoin_np.3, sem_open.3, stdin.3, rtc.4, tty_ioctl.4, unix.7: Global fix: s/non-portable/nonportable/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:46:09 +00:00
|
|
|
difficult to understand and produces nonportable or borderline results.
|
2007-05-16 02:01:52 +00:00
|
|
|
For instance, the above program is carefully written not to
|
|
|
|
block at any point, even though it does not set its file descriptors to
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
nonblocking mode.
|
2007-05-16 02:01:52 +00:00
|
|
|
It is easy to introduce
|
|
|
|
subtle errors that will remove the advantage of using
|
|
|
|
.BR select (),
|
2009-01-26 02:04:19 +00:00
|
|
|
so here is a list of essentials to watch for when using
|
|
|
|
.BR select ().
|
2007-12-23 22:20:16 +00:00
|
|
|
.TP 4
|
|
|
|
1.
|
2007-05-16 02:01:52 +00:00
|
|
|
You should always try to use
|
|
|
|
.BR select ()
|
|
|
|
without a timeout.
|
|
|
|
Your program
|
|
|
|
should have nothing to do if there is no data available.
|
|
|
|
Code that
|
|
|
|
depends on timeouts is not usually portable and is difficult to debug.
|
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
2.
|
2007-05-16 02:01:52 +00:00
|
|
|
The value \fInfds\fP must be properly calculated for efficiency as
|
|
|
|
explained above.
|
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
3.
|
2007-05-16 02:01:52 +00:00
|
|
|
No file descriptor must be added to any set if you do not intend
|
|
|
|
to check its result after the
|
|
|
|
.BR select ()
|
2009-01-26 02:04:19 +00:00
|
|
|
call, and respond appropriately.
|
2007-05-16 02:01:52 +00:00
|
|
|
See next rule.
|
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
4.
|
2007-05-16 02:01:52 +00:00
|
|
|
After
|
|
|
|
.BR select ()
|
|
|
|
returns, all file descriptors in all sets
|
|
|
|
should be checked to see if they are ready.
|
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
5.
|
2007-05-16 02:01:52 +00:00
|
|
|
The functions
|
|
|
|
.BR read (2),
|
|
|
|
.BR recv (2),
|
|
|
|
.BR write (2),
|
|
|
|
and
|
|
|
|
.BR send (2)
|
|
|
|
do \fInot\fP necessarily read/write the full amount of data
|
|
|
|
that you have requested.
|
2008-04-18 07:40:33 +00:00
|
|
|
If they do read/write the full amount, it's
|
2007-05-16 02:01:52 +00:00
|
|
|
because you have a low traffic load and a fast stream.
|
2009-01-26 02:04:19 +00:00
|
|
|
This is not always going to be the case.
|
2007-05-16 02:01:52 +00:00
|
|
|
You should cope with the case of your
|
intro.1, _syscall.2, access.2, arch_prctl.2, cacheflush.2, chown.2, clock_getres.2, clone.2, create_module.2, fcntl.2, flock.2, get_kernel_syms.2, get_robust_list.2, get_thread_area.2, getcpu.2, getpriority.2, getrlimit.2, getrusage.2, ioprio_set.2, kexec_load.2, madvise.2, mbind.2, migrate_pages.2, mknod.2, mmap.2, mount.2, move_pages.2, mprotect.2, open.2, pause.2, pciconfig_read.2, perf_event_open.2, prctl.2, ptrace.2, query_module.2, read.2, reboot.2, recv.2, s390_runtime_instr.2, sched_setscheduler.2, select_tut.2, send.2, set_mempolicy.2, setfsgid.2, setfsuid.2, sigaction.2, spu_create.2, spu_run.2, stime.2, swapon.2, syslog.2, timer_create.2, timer_getoverrun.2, times.2, tkill.2, umount.2, unimplemented.2, ustat.2, vm86.2, wait.2, abs.3, aio_read.3, aio_write.3, bsd_signal.3, catgets.3, clearenv.3, cmsg.3, dbopen.3, dirfd.3, dlopen.3, exec.3, fenv.3, ferror.3, fmemopen.3, fnmatch.3, fopen.3, futimes.3, getaddrinfo.3, getifaddrs.3, getipnodebyname.3, hsearch.3, if_nameindex.3, inet_pton.3, mblen.3, mbrlen.3, mbsrtowcs.3, mbtowc.3, mcheck.3, memfrob.3, mq_notify.3, netlink.3, posix_memalign.3, printf.3, pthread_attr_setscope.3, pthread_cleanup_push.3, pthread_kill_other_threads_np.3, pthread_self.3, pthread_setcancelstate.3, pthread_setconcurrency.3, raise.3, resolver.3, rpc.3, rtime.3, rtnetlink.3, scanf.3, setbuf.3, setnetgrent.3, shm_open.3, sigpause.3, sigset.3, sigwait.3, sockatmark.3, strcasecmp.3, strcmp.3, strdup.3, strftime.3, strptime.3, strsignal.3, strverscmp.3, sysv_signal.3, termios.3, wcrtomb.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wctomb.3, wprintf.3, console_codes.4, cpuid.4, msr.4, rtc.4, sk98lin.4, st.4, tty.4, charmap.5, core.5, elf.5, hosts.equiv.5, proc.5, resolv.conf.5, services.5, slabinfo.5, arp.7, bootparam.7, capabilities.7, charsets.7, cpuset.7, ddp.7, epoll.7, feature_test_macros.7, futex.7, hier.7, icmp.7, inotify.7, ip.7, ipv6.7, man-pages.7, mdoc.7, mdoc.samples.7, netdevice.7, netlink.7, numa.7, packet.7, path_resolution.7, posixoptions.7, pthreads.7, raw.7, rtld-audit.7, rtnetlink.7, sem_overview.7, sigevent.7, socket.7, spufs.7, tcp.7, udp.7, unicode.7, uri.7, utf-8.7, intro.8, ldconfig.8, sync.8: Global fix: fix placement of word "only"
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-31 08:53:00 +00:00
|
|
|
functions managing to send or receive only a single byte.
|
2007-05-16 02:01:52 +00:00
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
6.
|
2008-04-18 07:40:33 +00:00
|
|
|
Never read/write only in single bytes at a time unless you are really
|
2007-05-16 02:01:52 +00:00
|
|
|
sure that you have a small amount of data to process.
|
|
|
|
It is extremely
|
|
|
|
inefficient not to read/write as much data as you can buffer each time.
|
2009-01-26 02:04:19 +00:00
|
|
|
The buffers in the example below are 1024 bytes although they could
|
2007-05-16 02:01:52 +00:00
|
|
|
easily be made larger.
|
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
7.
|
2017-07-22 07:44:17 +00:00
|
|
|
Calls to
|
2007-05-16 02:01:52 +00:00
|
|
|
.BR read (2),
|
|
|
|
.BR recv (2),
|
|
|
|
.BR write (2),
|
2017-07-22 07:44:17 +00:00
|
|
|
.BR send (2),
|
2007-05-16 02:01:52 +00:00
|
|
|
and
|
|
|
|
.BR select ()
|
2017-07-22 07:44:17 +00:00
|
|
|
can fail with the error
|
|
|
|
\fBEINTR\fP,
|
|
|
|
and calls to
|
|
|
|
.BR read (2),
|
|
|
|
.BR recv (2)
|
|
|
|
.BR write (2),
|
|
|
|
and
|
|
|
|
.BR send (2)
|
|
|
|
can fail with
|
2007-05-16 02:01:52 +00:00
|
|
|
.I errno
|
|
|
|
set to \fBEAGAIN\fP (\fBEWOULDBLOCK\fP).
|
2009-01-26 02:04:19 +00:00
|
|
|
These results must be properly managed (not done properly above).
|
2008-04-18 07:40:33 +00:00
|
|
|
If your program is not going to receive any signals, then
|
2007-05-16 02:01:52 +00:00
|
|
|
it is unlikely you will get \fBEINTR\fP.
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
If your program does not set nonblocking I/O,
|
2009-01-26 02:04:19 +00:00
|
|
|
you will not get \fBEAGAIN\fP.
|
|
|
|
.\" Nonetheless, you should still cope with these errors for completeness.
|
2007-05-16 02:01:52 +00:00
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
8.
|
2007-05-16 02:01:52 +00:00
|
|
|
Never call
|
|
|
|
.BR read (2),
|
|
|
|
.BR recv (2),
|
|
|
|
.BR write (2),
|
|
|
|
or
|
|
|
|
.BR send (2)
|
|
|
|
with a buffer length of zero.
|
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
9.
|
2007-05-16 02:01:52 +00:00
|
|
|
If the functions
|
|
|
|
.BR read (2),
|
|
|
|
.BR recv (2),
|
|
|
|
.BR write (2),
|
|
|
|
and
|
|
|
|
.BR send (2)
|
2009-01-26 02:04:19 +00:00
|
|
|
fail with errors other than those listed in \fB7.\fP,
|
2007-05-16 02:01:52 +00:00
|
|
|
or one of the input functions returns 0, indicating end of file,
|
2016-01-01 10:45:50 +00:00
|
|
|
then you should \fInot\fP pass that file descriptor to
|
2007-05-16 02:01:52 +00:00
|
|
|
.BR select ()
|
|
|
|
again.
|
2009-01-26 02:04:19 +00:00
|
|
|
In the example below,
|
2016-01-01 10:45:50 +00:00
|
|
|
I close the file descriptor immediately, and then set it to \-1
|
2007-05-16 02:01:52 +00:00
|
|
|
to prevent it being included in a set.
|
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
10.
|
2007-05-16 02:01:52 +00:00
|
|
|
The timeout value must be initialized with each new call to
|
|
|
|
.BR select (),
|
|
|
|
since some operating systems modify the structure.
|
|
|
|
.BR pselect ()
|
|
|
|
however does not modify its timeout structure.
|
|
|
|
.TP
|
2007-12-23 22:20:16 +00:00
|
|
|
11.
|
2009-01-26 02:04:19 +00:00
|
|
|
Since
|
2007-05-16 02:01:52 +00:00
|
|
|
.BR select ()
|
2009-01-26 02:04:19 +00:00
|
|
|
modifies its file descriptor sets,
|
|
|
|
if the call is being used in a loop,
|
close.2, epoll_create.2, epoll_ctl.2, fcntl.2, madvise.2, mmap.2, mremap.2, select_tut.2, setgid.2, setuid.2, syscalls.2, vmsplice.2, dlopen.3, fts.3, getpw.3, stdio.3, fd.4, initrd.4, random.4, sd.4, bootparam.7, capabilities.7, cpuset.7, epoll.7, inotify.7, man.7, socket.7, x25.7: Global fix: s/re-/re/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "re-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 17:45:23 +00:00
|
|
|
then the sets must be reinitialized before each call.
|
2009-01-26 02:04:19 +00:00
|
|
|
.\" "I have heard" does not fill me with confidence, and doesn't
|
|
|
|
.\" belong in a man page, so I've commented this point out.
|
|
|
|
.\" .TP
|
|
|
|
.\" 11.
|
|
|
|
.\" I have heard that the Windows socket layer does not cope with OOB data
|
|
|
|
.\" properly.
|
|
|
|
.\" It also does not cope with
|
|
|
|
.\" .BR select ()
|
|
|
|
.\" calls when no file descriptors are set at all.
|
|
|
|
.\" Having no file descriptors set is a useful
|
ioctl_list.2, mount.2, select_tut.2, stat.2, getifaddrs.3, pthread_cleanup_push_defer_np.3, pthread_getcpuclockid.3, proc.5, bootparam.7: Global fix: s/sub-/sub/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "sub-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 17:36:10 +00:00
|
|
|
.\" way to sleep the process with subsecond precision by using the timeout.
|
2009-01-26 02:04:19 +00:00
|
|
|
.\" (See further on.)
|
2007-05-19 04:30:20 +00:00
|
|
|
.SH RETURN VALUE
|
2020-02-18 09:10:01 +00:00
|
|
|
See
|
|
|
|
.BR select (2).
|
2007-05-19 04:30:20 +00:00
|
|
|
.SH NOTES
|
2009-01-26 02:04:19 +00:00
|
|
|
Generally speaking,
|
|
|
|
all operating systems that support sockets also support
|
2007-05-19 04:30:20 +00:00
|
|
|
.BR select ().
|
|
|
|
.BR select ()
|
|
|
|
can be used to solve
|
|
|
|
many problems in a portable and efficient way that naive programmers try
|
|
|
|
to solve in a more complicated manner using
|
|
|
|
threads, forking, IPCs, signals, memory sharing, and so on.
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.BR poll (2)
|
|
|
|
system call has the same functionality as
|
|
|
|
.BR select (),
|
|
|
|
and is somewhat more efficient when monitoring sparse
|
|
|
|
file descriptor sets.
|
2009-01-26 02:04:19 +00:00
|
|
|
It is nowadays widely available, but historically was less portable than
|
2007-05-19 04:30:20 +00:00
|
|
|
.BR select ().
|
|
|
|
.PP
|
|
|
|
The Linux-specific
|
|
|
|
.BR epoll (7)
|
|
|
|
API provides an interface that is more efficient than
|
|
|
|
.BR select (2)
|
|
|
|
and
|
|
|
|
.BR poll (2)
|
|
|
|
when monitoring large numbers of file descriptors.
|
2020-05-21 08:00:37 +00:00
|
|
|
.SH EXAMPLES
|
2004-11-03 13:51:07 +00:00
|
|
|
Here is an example that better demonstrates the true utility of
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR select ().
|
2010-10-06 05:13:25 +00:00
|
|
|
The listing below is a TCP forwarding program that forwards
|
2004-11-03 13:51:07 +00:00
|
|
|
from one TCP port to another.
|
|
|
|
.PP
|
intro.1, locale.1, ioctl_list.2, listxattr.2, memfd_create.2, nfsservctl.2, open_by_handle_at.2, perf_event_open.2, poll.2, process_vm_readv.2, ptrace.2, select.2, select_tut.2, semop.2, sendmmsg.2, shmget.2, sigaction.2, spu_run.2, umask.2, wait4.2, nan.3, setlocale.3, feature_test_macros.7, glob.7, posixoptions.7, rtld-audit.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-19 10:56:40 +00:00
|
|
|
.EX
|
2004-11-03 13:51:07 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2020-02-18 08:56:23 +00:00
|
|
|
#include <sys/select.h>
|
2004-11-03 13:51:07 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
static int forward_port;
|
|
|
|
|
|
|
|
#undef max
|
|
|
|
#define max(x,y) ((x) > (y) ? (x) : (y))
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
static int
|
|
|
|
listen_socket(int listen_port)
|
2007-04-05 12:36:57 +00:00
|
|
|
{
|
accept.2, bind.2, connect.2, getpeername.2, getsockname.2, recv.2, recvmmsg.2, select_tut.2, send.2, sendmmsg.2, getaddrinfo.3, getnameinfo.3, epoll.7, unix.7: Use consistent argument/variable names for socket addresses and lengths
As noted by Carlos, there's quite a bit of inconsistency across
pages. Use 'addr' and 'addrlen' consistently in variables and
function arguments.
Cowritten-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-02-03 12:10:04 +00:00
|
|
|
struct sockaddr_in addr;
|
2016-02-03 13:26:25 +00:00
|
|
|
int lfd;
|
2004-11-03 13:51:07 +00:00
|
|
|
int yes;
|
2007-12-23 22:20:16 +00:00
|
|
|
|
2016-02-03 13:26:25 +00:00
|
|
|
lfd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (lfd == \-1) {
|
2007-04-05 12:36:57 +00:00
|
|
|
perror("socket");
|
2005-07-06 12:57:38 +00:00
|
|
|
return \-1;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
2016-02-03 13:18:21 +00:00
|
|
|
|
2004-11-03 13:51:07 +00:00
|
|
|
yes = 1;
|
2016-02-03 13:26:25 +00:00
|
|
|
if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,
|
2012-08-03 06:10:17 +00:00
|
|
|
&yes, sizeof(yes)) == \-1) {
|
2007-04-05 12:36:57 +00:00
|
|
|
perror("setsockopt");
|
2016-02-03 13:26:25 +00:00
|
|
|
close(lfd);
|
2005-07-06 12:57:38 +00:00
|
|
|
return \-1;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
2016-02-03 13:18:21 +00:00
|
|
|
|
accept.2, bind.2, connect.2, getpeername.2, getsockname.2, recv.2, recvmmsg.2, select_tut.2, send.2, sendmmsg.2, getaddrinfo.3, getnameinfo.3, epoll.7, unix.7: Use consistent argument/variable names for socket addresses and lengths
As noted by Carlos, there's quite a bit of inconsistency across
pages. Use 'addr' and 'addrlen' consistently in variables and
function arguments.
Cowritten-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-02-03 12:10:04 +00:00
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sin_port = htons(listen_port);
|
|
|
|
addr.sin_family = AF_INET;
|
2016-02-03 13:26:25 +00:00
|
|
|
if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == \-1) {
|
2007-04-05 12:36:57 +00:00
|
|
|
perror("bind");
|
2016-02-03 13:26:25 +00:00
|
|
|
close(lfd);
|
2005-07-06 12:57:38 +00:00
|
|
|
return \-1;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
2016-02-03 13:18:21 +00:00
|
|
|
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
printf("accepting connections on port %d\en", listen_port);
|
2016-02-03 13:26:25 +00:00
|
|
|
listen(lfd, 10);
|
|
|
|
return lfd;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
static int
|
|
|
|
connect_socket(int connect_port, char *address)
|
2007-04-05 12:36:57 +00:00
|
|
|
{
|
accept.2, bind.2, connect.2, getpeername.2, getsockname.2, recv.2, recvmmsg.2, select_tut.2, send.2, sendmmsg.2, getaddrinfo.3, getnameinfo.3, epoll.7, unix.7: Use consistent argument/variable names for socket addresses and lengths
As noted by Carlos, there's quite a bit of inconsistency across
pages. Use 'addr' and 'addrlen' consistently in variables and
function arguments.
Cowritten-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-02-03 12:10:04 +00:00
|
|
|
struct sockaddr_in addr;
|
2016-02-03 13:26:25 +00:00
|
|
|
int cfd;
|
2007-12-23 22:20:16 +00:00
|
|
|
|
2016-02-03 13:26:25 +00:00
|
|
|
cfd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (cfd == \-1) {
|
2007-04-05 12:36:57 +00:00
|
|
|
perror("socket");
|
2005-07-06 12:57:38 +00:00
|
|
|
return \-1;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
accept.2, bind.2, connect.2, getpeername.2, getsockname.2, recv.2, recvmmsg.2, select_tut.2, send.2, sendmmsg.2, getaddrinfo.3, getnameinfo.3, epoll.7, unix.7: Use consistent argument/variable names for socket addresses and lengths
As noted by Carlos, there's quite a bit of inconsistency across
pages. Use 'addr' and 'addrlen' consistently in variables and
function arguments.
Cowritten-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-02-03 12:10:04 +00:00
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sin_port = htons(connect_port);
|
|
|
|
addr.sin_family = AF_INET;
|
2004-11-03 13:51:07 +00:00
|
|
|
|
accept.2, bind.2, connect.2, getpeername.2, getsockname.2, recv.2, recvmmsg.2, select_tut.2, send.2, sendmmsg.2, getaddrinfo.3, getnameinfo.3, epoll.7, unix.7: Use consistent argument/variable names for socket addresses and lengths
As noted by Carlos, there's quite a bit of inconsistency across
pages. Use 'addr' and 'addrlen' consistently in variables and
function arguments.
Cowritten-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-02-03 12:10:04 +00:00
|
|
|
if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
fprintf(stderr, "inet_aton(): bad IP address format\en");
|
2016-02-03 13:26:25 +00:00
|
|
|
close(cfd);
|
2005-07-06 12:57:38 +00:00
|
|
|
return \-1;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 13:26:25 +00:00
|
|
|
if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == \-1) {
|
2007-04-05 12:36:57 +00:00
|
|
|
perror("connect()");
|
2016-02-03 13:26:25 +00:00
|
|
|
shutdown(cfd, SHUT_RDWR);
|
|
|
|
close(cfd);
|
2005-07-06 12:57:38 +00:00
|
|
|
return \-1;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
2016-02-03 13:26:25 +00:00
|
|
|
return cfd;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
#define SHUT_FD1 do { \e
|
|
|
|
if (fd1 >= 0) { \e
|
|
|
|
shutdown(fd1, SHUT_RDWR); \e
|
|
|
|
close(fd1); \e
|
|
|
|
fd1 = \-1; \e
|
|
|
|
} \e
|
2008-12-05 20:26:20 +00:00
|
|
|
} while (0)
|
|
|
|
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
#define SHUT_FD2 do { \e
|
|
|
|
if (fd2 >= 0) { \e
|
|
|
|
shutdown(fd2, SHUT_RDWR); \e
|
|
|
|
close(fd2); \e
|
|
|
|
fd2 = \-1; \e
|
|
|
|
} \e
|
2008-12-05 20:26:20 +00:00
|
|
|
} while (0)
|
2004-11-03 13:51:07 +00:00
|
|
|
|
|
|
|
#define BUF_SIZE 1024
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
int
|
2009-01-26 02:04:19 +00:00
|
|
|
main(int argc, char *argv[])
|
2007-04-05 12:36:57 +00:00
|
|
|
{
|
2004-11-03 13:51:07 +00:00
|
|
|
int h;
|
2005-07-06 12:57:38 +00:00
|
|
|
int fd1 = \-1, fd2 = \-1;
|
2004-11-03 13:51:07 +00:00
|
|
|
char buf1[BUF_SIZE], buf2[BUF_SIZE];
|
2016-08-10 15:23:16 +00:00
|
|
|
int buf1_avail = 0, buf1_written = 0;
|
|
|
|
int buf2_avail = 0, buf2_written = 0;
|
2004-11-03 13:51:07 +00:00
|
|
|
|
|
|
|
if (argc != 4) {
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
fprintf(stderr, "Usage\en\etfwd <listen\-port> "
|
|
|
|
"<forward\-to\-port> <forward\-to\-ip\-address>\en");
|
2007-05-14 21:11:42 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-05 12:36:57 +00:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2007-04-05 12:36:57 +00:00
|
|
|
forward_port = atoi(argv[2]);
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2007-04-05 12:36:57 +00:00
|
|
|
h = listen_socket(atoi(argv[1]));
|
2009-01-24 22:34:23 +00:00
|
|
|
if (h == \-1)
|
2007-05-14 21:11:42 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2004-11-03 13:51:07 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2016-02-03 13:26:25 +00:00
|
|
|
int ready, nfds = 0;
|
2016-08-10 15:23:16 +00:00
|
|
|
ssize_t nbytes;
|
2016-02-03 13:26:25 +00:00
|
|
|
fd_set readfds, writefds, exceptfds;
|
|
|
|
|
|
|
|
FD_ZERO(&readfds);
|
|
|
|
FD_ZERO(&writefds);
|
|
|
|
FD_ZERO(&exceptfds);
|
|
|
|
FD_SET(h, &readfds);
|
2007-04-05 12:36:57 +00:00
|
|
|
nfds = max(nfds, h);
|
2016-08-10 15:23:16 +00:00
|
|
|
|
|
|
|
if (fd1 > 0 && buf1_avail < BUF_SIZE)
|
2016-02-03 13:26:25 +00:00
|
|
|
FD_SET(fd1, &readfds);
|
2016-08-11 19:14:01 +00:00
|
|
|
/* Note: nfds is updated below, when fd1 is added to
|
|
|
|
exceptfds. */
|
2016-08-10 15:23:16 +00:00
|
|
|
if (fd2 > 0 && buf2_avail < BUF_SIZE)
|
2016-02-03 13:26:25 +00:00
|
|
|
FD_SET(fd2, &readfds);
|
2016-08-10 15:23:16 +00:00
|
|
|
|
|
|
|
if (fd1 > 0 && buf2_avail \- buf2_written > 0)
|
2016-02-03 13:26:25 +00:00
|
|
|
FD_SET(fd1, &writefds);
|
2016-08-10 15:23:16 +00:00
|
|
|
if (fd2 > 0 && buf1_avail \- buf1_written > 0)
|
2016-02-03 13:26:25 +00:00
|
|
|
FD_SET(fd2, &writefds);
|
2016-08-10 15:23:16 +00:00
|
|
|
|
2004-11-03 13:51:07 +00:00
|
|
|
if (fd1 > 0) {
|
2016-02-03 13:26:25 +00:00
|
|
|
FD_SET(fd1, &exceptfds);
|
2007-04-05 12:36:57 +00:00
|
|
|
nfds = max(nfds, fd1);
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
if (fd2 > 0) {
|
2016-02-03 13:26:25 +00:00
|
|
|
FD_SET(fd2, &exceptfds);
|
2007-04-05 12:36:57 +00:00
|
|
|
nfds = max(nfds, fd2);
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 13:26:25 +00:00
|
|
|
ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2016-02-03 13:26:25 +00:00
|
|
|
if (ready == \-1 && errno == EINTR)
|
2004-11-03 13:51:07 +00:00
|
|
|
continue;
|
2009-01-26 02:04:19 +00:00
|
|
|
|
2016-02-03 13:26:25 +00:00
|
|
|
if (ready == \-1) {
|
2007-04-05 12:36:57 +00:00
|
|
|
perror("select()");
|
2007-05-14 21:11:42 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
2009-01-26 02:04:19 +00:00
|
|
|
|
2016-02-03 13:26:25 +00:00
|
|
|
if (FD_ISSET(h, &readfds)) {
|
2016-02-03 13:34:37 +00:00
|
|
|
socklen_t addrlen;
|
accept.2, bind.2, connect.2, getpeername.2, getsockname.2, recv.2, recvmmsg.2, select_tut.2, send.2, sendmmsg.2, getaddrinfo.3, getnameinfo.3, epoll.7, unix.7: Use consistent argument/variable names for socket addresses and lengths
As noted by Carlos, there's quite a bit of inconsistency across
pages. Use 'addr' and 'addrlen' consistently in variables and
function arguments.
Cowritten-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-02-03 12:10:04 +00:00
|
|
|
struct sockaddr_in client_addr;
|
2016-08-10 15:23:16 +00:00
|
|
|
int fd;
|
2008-12-05 20:13:41 +00:00
|
|
|
|
2016-08-10 15:23:16 +00:00
|
|
|
addrlen = sizeof(client_addr);
|
2016-02-03 13:03:27 +00:00
|
|
|
memset(&client_addr, 0, addrlen);
|
2016-02-03 13:26:25 +00:00
|
|
|
fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);
|
|
|
|
if (fd == \-1) {
|
2007-04-05 12:36:57 +00:00
|
|
|
perror("accept()");
|
2004-11-03 13:51:07 +00:00
|
|
|
} else {
|
|
|
|
SHUT_FD1;
|
|
|
|
SHUT_FD2;
|
|
|
|
buf1_avail = buf1_written = 0;
|
|
|
|
buf2_avail = buf2_written = 0;
|
2016-02-03 13:26:25 +00:00
|
|
|
fd1 = fd;
|
2008-12-05 20:13:41 +00:00
|
|
|
fd2 = connect_socket(forward_port, argv[3]);
|
2009-01-24 22:34:23 +00:00
|
|
|
if (fd2 == \-1)
|
2004-11-03 13:51:07 +00:00
|
|
|
SHUT_FD1;
|
2008-12-05 20:26:20 +00:00
|
|
|
else
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
printf("connect from %s\en",
|
accept.2, bind.2, connect.2, getpeername.2, getsockname.2, recv.2, recvmmsg.2, select_tut.2, send.2, sendmmsg.2, getaddrinfo.3, getnameinfo.3, epoll.7, unix.7: Use consistent argument/variable names for socket addresses and lengths
As noted by Carlos, there's quite a bit of inconsistency across
pages. Use 'addr' and 'addrlen' consistently in variables and
function arguments.
Cowritten-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-02-03 12:10:04 +00:00
|
|
|
inet_ntoa(client_addr.sin_addr));
|
2016-08-10 15:23:16 +00:00
|
|
|
|
2020-02-18 10:21:57 +00:00
|
|
|
/* Skip any events on the old, closed file
|
|
|
|
descriptors. */
|
|
|
|
|
2016-08-10 15:23:16 +00:00
|
|
|
continue;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-06 03:53:52 +00:00
|
|
|
|
2016-02-03 13:18:21 +00:00
|
|
|
/* NB: read OOB data before normal reads */
|
2008-12-05 20:13:41 +00:00
|
|
|
|
2016-02-03 13:36:49 +00:00
|
|
|
if (fd1 > 0 && FD_ISSET(fd1, &exceptfds)) {
|
|
|
|
char c;
|
2009-01-26 02:04:19 +00:00
|
|
|
|
2016-02-03 13:36:49 +00:00
|
|
|
nbytes = recv(fd1, &c, 1, MSG_OOB);
|
|
|
|
if (nbytes < 1)
|
|
|
|
SHUT_FD1;
|
|
|
|
else
|
|
|
|
send(fd2, &c, 1, MSG_OOB);
|
|
|
|
}
|
|
|
|
if (fd2 > 0 && FD_ISSET(fd2, &exceptfds)) {
|
|
|
|
char c;
|
2009-01-26 02:04:19 +00:00
|
|
|
|
2016-02-03 13:36:49 +00:00
|
|
|
nbytes = recv(fd2, &c, 1, MSG_OOB);
|
|
|
|
if (nbytes < 1)
|
|
|
|
SHUT_FD2;
|
|
|
|
else
|
|
|
|
send(fd1, &c, 1, MSG_OOB);
|
|
|
|
}
|
|
|
|
if (fd1 > 0 && FD_ISSET(fd1, &readfds)) {
|
|
|
|
nbytes = read(fd1, buf1 + buf1_avail,
|
|
|
|
BUF_SIZE \- buf1_avail);
|
|
|
|
if (nbytes < 1)
|
|
|
|
SHUT_FD1;
|
|
|
|
else
|
|
|
|
buf1_avail += nbytes;
|
|
|
|
}
|
|
|
|
if (fd2 > 0 && FD_ISSET(fd2, &readfds)) {
|
|
|
|
nbytes = read(fd2, buf2 + buf2_avail,
|
|
|
|
BUF_SIZE \- buf2_avail);
|
|
|
|
if (nbytes < 1)
|
|
|
|
SHUT_FD2;
|
|
|
|
else
|
|
|
|
buf2_avail += nbytes;
|
|
|
|
}
|
2016-08-10 15:23:16 +00:00
|
|
|
if (fd1 > 0 && FD_ISSET(fd1, &writefds) && buf2_avail > 0) {
|
2016-02-03 13:36:49 +00:00
|
|
|
nbytes = write(fd1, buf2 + buf2_written,
|
|
|
|
buf2_avail \- buf2_written);
|
|
|
|
if (nbytes < 1)
|
|
|
|
SHUT_FD1;
|
|
|
|
else
|
|
|
|
buf2_written += nbytes;
|
|
|
|
}
|
2016-08-10 15:23:16 +00:00
|
|
|
if (fd2 > 0 && FD_ISSET(fd2, &writefds) && buf1_avail > 0) {
|
2016-02-03 13:36:49 +00:00
|
|
|
nbytes = write(fd2, buf1 + buf1_written,
|
|
|
|
buf1_avail \- buf1_written);
|
|
|
|
if (nbytes < 1)
|
|
|
|
SHUT_FD2;
|
|
|
|
else
|
|
|
|
buf1_written += nbytes;
|
|
|
|
}
|
2008-12-06 03:53:52 +00:00
|
|
|
|
2016-02-03 13:18:21 +00:00
|
|
|
/* Check if write data has caught read data */
|
2008-12-05 20:13:41 +00:00
|
|
|
|
2004-11-03 13:51:07 +00:00
|
|
|
if (buf1_written == buf1_avail)
|
|
|
|
buf1_written = buf1_avail = 0;
|
|
|
|
if (buf2_written == buf2_avail)
|
|
|
|
buf2_written = buf2_avail = 0;
|
2008-12-05 20:13:41 +00:00
|
|
|
|
2016-02-03 13:18:21 +00:00
|
|
|
/* One side has closed the connection, keep
|
2008-12-05 20:13:41 +00:00
|
|
|
writing to the other side until empty */
|
|
|
|
|
2008-12-05 20:26:20 +00:00
|
|
|
if (fd1 < 0 && buf1_avail \- buf1_written == 0)
|
2004-11-03 13:51:07 +00:00
|
|
|
SHUT_FD2;
|
2008-12-05 20:26:20 +00:00
|
|
|
if (fd2 < 0 && buf2_avail \- buf2_written == 0)
|
2004-11-03 13:51:07 +00:00
|
|
|
SHUT_FD1;
|
|
|
|
}
|
2007-05-16 01:57:36 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
intro.1, locale.1, ioctl_list.2, listxattr.2, memfd_create.2, nfsservctl.2, open_by_handle_at.2, perf_event_open.2, poll.2, process_vm_readv.2, ptrace.2, select.2, select_tut.2, semop.2, sendmmsg.2, shmget.2, sigaction.2, spu_run.2, umask.2, wait4.2, nan.3, setlocale.3, feature_test_macros.7, glob.7, posixoptions.7, rtld-audit.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-19 10:56:40 +00:00
|
|
|
.EE
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2010-10-06 05:13:25 +00:00
|
|
|
The above program properly forwards most kinds of TCP connections
|
2007-04-12 22:42:49 +00:00
|
|
|
including OOB signal data transmitted by \fBtelnet\fP servers.
|
2009-01-26 02:04:19 +00:00
|
|
|
It handles the tricky problem of having data flow in both directions
|
2007-04-12 22:42:49 +00:00
|
|
|
simultaneously.
|
2007-05-12 09:06:04 +00:00
|
|
|
You might think it more efficient to use a
|
|
|
|
.BR fork (2)
|
2007-04-12 22:42:49 +00:00
|
|
|
call and devote a thread to each stream.
|
2009-01-26 02:04:19 +00:00
|
|
|
This becomes more tricky than you might suspect.
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
Another idea is to set nonblocking I/O using
|
2009-01-26 02:04:19 +00:00
|
|
|
.BR fcntl (2).
|
2008-04-18 07:40:33 +00:00
|
|
|
This also has its problems because you end up using
|
|
|
|
inefficient timeouts.
|
_syscall.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, copy_file_range.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, execveat.2, fallocate.2, flock.2, fork.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_mempolicy.2, get_robust_list.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpriority.2, getrandom.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl_fat.2, ioctl_ficlonerange.2, ioctl_fideduperange.2, ioctl_tty.2, ioctl_userfaultfd.2, ioperm.2, iopl.2, ioprio_set.2, kcmp.2, kexec_load.2, keyctl.2, kill.2, link.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, mbind.2, membarrier.2, memfd_create.2, migrate_pages.2, mincore.2, mkdir.2, mknod.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open_by_handle_at.2, outb.2, perf_event_open.2, perfmonctl.2, personality.2, pivot_root.2, pkey_alloc.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readv.2, reboot.2, recv.2, recvmmsg.2, remap_file_pages.2, rename.2, request_key.2, restart_syscall.2, rt_sigqueueinfo.2, s390_pci_mmio_write.2, s390_runtime_instr.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, seccomp.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, sendmmsg.2, set_mempolicy.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setns.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, spu_create.2, spu_run.2, stat.2, statfs.2, statx.2, subpage_prot.2, swapon.2, symlink.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysinfo.2, syslog.2, tee.2, time.2, timer_create.2, timer_getoverrun.2, timer_settime.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, unimplemented.2, unlink.2, unshare.2, uselib.2, userfaultfd.2, utime.2, utimensat.2, vfork.2, vmsplice.2, wait.2, wait4.2, write.2: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 07:30:51 +00:00
|
|
|
.PP
|
2004-11-03 13:51:07 +00:00
|
|
|
The program does not handle more than one simultaneous connection at a
|
|
|
|
time, although it could easily be extended to do this with a linked list
|
intro.1, fork.2, futex.2, open.2, rename.2, select_tut.2, semop.2, spu_create.2, stat.2, netlink.3, random.3, scanf.3, shm_open.3, strftime.3, console.4, console_codes.4, sk98lin.4, st.4, bootparam.7, cpuset.7, credentials.7, man-pages.7, path_resolution.7, uri.7: Global fix: remove spaces around em-dash
Normal English typographical convention is not to have
spaces around em dashes.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2011-10-03 06:47:35 +00:00
|
|
|
of buffers\(emone for each connection.
|
2007-04-12 22:42:49 +00:00
|
|
|
At the moment, new
|
2004-11-03 13:51:07 +00:00
|
|
|
connections cause the current connection to be dropped.
|
|
|
|
.SH SEE ALSO
|
|
|
|
.BR accept (2),
|
|
|
|
.BR connect (2),
|
|
|
|
.BR poll (2),
|
|
|
|
.BR read (2),
|
|
|
|
.BR recv (2),
|
|
|
|
.BR select (2),
|
|
|
|
.BR send (2),
|
|
|
|
.BR sigprocmask (2),
|
|
|
|
.BR write (2),
|
2006-05-13 05:03:43 +00:00
|
|
|
.BR epoll (7)
|
2006-05-13 06:04:35 +00:00
|
|
|
.\" .SH AUTHORS
|
|
|
|
.\" This man page was written by Paul Sheer.
|