0

几周前我问了这个关于端口 Rebol Smallest Http Server in the World 的问题:为什么要先等待监听端口?

监听端口是一个对象

第一个监听端口是自我所以仍然不明白为什么自我不等于监听端口这就是我们需要的原因

http-port: first wait listen-port

如果wait返回listen-port并且第一个监听端口与self或listen-port相同,那么上面的代码与

http-port: wait listen-port

?

4

1 回答 1

1

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.

于 2009-09-22T17:57:01.627 回答