反叛自我对象

发布于 2024-08-05 13:22:59 字数 476 浏览 1 评论 0原文

几周前我问了这个关于端口的问题 Rebol 世界上最小的 Http 服务器:为什么首先等待listen-port?

listen-port是一个对象,

第一个listen-port是self,所以仍然不明白为什么self不等于listen-port,这就是为什么我们需要

http-port: first wait listen-port

等待返回listen-port并且第一个listen port与self或listen-port相同,那么上面的代码与

http-port: wait listen-port

I asked this question a few weeks ago about port
Rebol Smallest Http Server in the World: why first wait listen-port?

listen-port is an object

first listen-port is self so still don't understand why self doesn't equal listen-port that is why do we need

http-port: first wait listen-port

if wait returns listen-port and first listen port is the same as self or listen-port then the above code is not the same as

http-port: wait listen-port

?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2024-08-12 13:22:59

监听端口是一个端口!值,而不是对象!价值。一个港口!可以看作是object的派生!数据类型并具有专门用途。第一个行为(与所有其他操作!值一样)是多态的。

为了对象!值,它返回在该对象上下文中定义的单词列表(加上特殊的自引用单词“self”):

foo: make object! [bar: 3]
first foo
== [self bar]

对于端口!值,FIRST 将根据端口有两种不同的行为! type :

  • client port : 它将 PICK 操作发送到端口内部处理程序(第一个端口 == pick port 1)。

  • 服务器端口:它将调用底层 C 套接字的 ACCEPT 操作来检索新的连接端口!值,允许与客户端通信。

所以:

wait listen-port

当事件发生时返回监听端口值。

http-port: first wait listen-port

返回一个新端口!连接到“http-port”引用的客户端的值。

listen-port is a port! value, not an object! value. A port! can be seen as a derivation from object! datatype and having a specialized purpose. FIRST behaviour (as all other action! values) is polymorphic.

For object! values, it returns the list of words defined in that object context (plus the special self-referencing word 'self) :

foo: make object! [bar: 3]
first foo
== [self bar]

For port! values, FIRST will have two different behaviours depending on the port! type :

  • client port : it sends the PICK action to the port internal handler (first port == pick port 1).

  • server port : it will call the ACCEPT action to the underlying C socket to retrieve a new connection port! value, allowing communication with the client.

So :

wait listen-port

returns the listen-port value when an event happens.

http-port: first wait listen-port

returns a new port! value connected to the client referenced by 'http-port.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文