Skip to content

Unix/Linux 网络编程

历史

  • 1983: select() was introduced in 4.2BSD Unix, released in August 1983.
  • 1997: poll() was introduced in SVR3 Unix, released 1987. In Linux, the poll() system call was introduced in 2.1.23 (January 1997) while the poll() library call was introduced in libc 5.4.28 (May 1997)
  • 2002: epoll(): only for linux kernel 2.5.44, 2002 (and therefore, not portable)

  • Using an event library like libevent, libev, or libuv will provide an abstraction layer and try to use the most performant method on your system, so you shouldn't have to worry about choosing between select, poll, epoll, or kqueue (for MacOS and the BSD's).

早期:pipe 的方式 The only way to read and write at the same time was to use two processes.

1983: This all changed in 1983 with the release of 4.2BSD. This revision introduced an early implementation of a TCP/IP stack and most importantly - the BSD Sockets API.

随着多用户分时的发展,普通的 Accept-and-fork 模式也 is not enough 了

Accept-and-fork, as you call it, makes it impossible for multiple clients to share state on the server. It's not just about networking either; one influence was the work with the Blit.

插播一条厉害的大佬恋情故事:Marshall Kirk McKusick - Wikipedia and Eric Allman - Wikipedia

编程语言的io

实际上各种语言底层还是需要使用操作系统的 io api, 但根据平台不同会进行不同 api 的选择。 They are all ultimately just wrappers over operating system facilities. Node.js 的 io 操作由 libuv 进行; JAVA NIO is Java's abstraction of non-blocking io. There will be different underlying implementations on different platforms. On Linux, it is implemented using epool. On other platforms, other technologies such as kqueue are used.

一些问题

linux - select vs poll vs epoll - Stack Overflow I am designing a new server which needs to support thousands of UDP connections (somewhere around 100,000 sessions). Can someone explain select vs poll vs epoll? It will help me know which one to use. A: Linux: epoll FreeBSD: kqueue Windows: IO Completion Port

c - Why use select(), when we have poll() and epoll() - Stack Overflow I looked at the differences between poll, epoll and select. What I don't understand is when should I use select. I don't see any advantage, given that poll and epoll have everything that select has, and more.

asynchronous - non-blocking IO vs async IO and implementation in Java - Stack Overflow

linux - What does the number in parentheses shown after Unix command names in manpages mean? - Stack Overflow It's the section that the man page for the command is assigned to. These are split as: 1.General commands 2.System calls 3.C library functions 4.Special files (usually devices, those found in /dev) and drivers 5.File formats and conventions 6.Games and screensavers 7.Miscellanea 8.System administration commands and daemons