lua nginx 模块中提到的 TCP 套接字是什么?

What is TCP socket referred in lua nginx module?

在 Lua Nginx 模块文档中关于 ngx.socket.tcp() (Link),它说:

Creates and returns a TCP or stream-oriented Unix domain socket object (also known as one type of the "cosocket" objects)

此 TCP 套接字可用于连接到远程主机,但在有关 unix 域套接字的 wiki (Link):

A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing on the same host operating system

这让我想到了一些问题:

  1. 这个TCP套接字是不是另一种Unix域套接字?这个 TCP 套接字到底是什么?
  2. 文档中提到的 cosocket 是什么?我无法使用 google
  3. 找到它
  4. TCP/IP模型的传输层也使用了TCP协议,这样API可以绕过应用层,直接在传输层编程吗?
  1. Is this TCP socket another type of Unix domain socket? What is this TCP socket really be?

TCP和unix域套接字都是流套接字。您可以使用 ngx.socket.tcp() API 创建这两种类型的套接字。 OS socket 的类型由 connect 方法定义,有两种不同的语法:

如果您使用 tcpsock:connect(host, port, options_table?) 语法连接,套接字将是 TCP 套接字。

如果您通过 tcpsock:connect("unix:/path/to/unix-domain.socket", options_table?) 语法连接,套接字将是 unix 域套接字。显然你不能使用 unix 域套接字进行网络通信。

  1. What is cosocket referred in the docs? I can't find it using google

Cosocket 是 OpenResty 生态系统的术语。如果您使用 ngx.socket.tcp() API 创建一个对象 - 您将创建一个 cosocket 对象。

  1. TCP protocol is also used in the transport layer of the TCP/IP model, is this API allow to program directly in the transport layer, bypassing the application layer?

完全正确。