反叛自我对象
几周前我问了这个关于端口的问题 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
监听端口是一个端口!值,而不是对象!价值。一个港口!可以看作是object的派生!数据类型并具有专门用途。第一个行为(与所有其他操作!值一样)是多态的。
为了对象!值,它返回在该对象上下文中定义的单词列表(加上特殊的自引用单词“self”):
对于端口!值,FIRST 将根据端口有两种不同的行为! type :
client port : 它将 PICK 操作发送到端口内部处理程序(第一个端口 == pick port 1)。
服务器端口:它将调用底层 C 套接字的 ACCEPT 操作来检索新的连接端口!值,允许与客户端通信。
所以:
当事件发生时返回监听端口值。
返回一个新端口!连接到“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) :
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 :
returns the listen-port value when an event happens.
returns a new port! value connected to the client referenced by 'http-port.