调试并避免周期性的REBOL2错误,试试[]没有(?)捕获?

fst*_*eff 6 rebol rebol2

使用Rebol/Core(278-3-1)制作一种服务于静态文本的Web服务器时,显然无法捕获错误,其中包含指向新服务位置的重定向链接.

错误的具体位置似乎是在Carl Sassenrath他自己编写的示例代码中,早在2006年,所以我有点困惑,这些年后可能会有一个未检测到的错误.

我有三个这样的脚本同时运行,监视三个单独的端口.本质上,脚本可以正常工作......当同时使用多个浏览器重复访问时(在所有并行脚本上),它看起来非常稳定......但是一个接一个地它们会失败.有时在2分钟后,有时在20分钟后 - 有时甚至在60分钟后添加打印语句 - 但最终它们会像这样失败:

**脚本错误:超出范围或过去结束
**其中:永远
**近:不是空的?请求:第一个http端口

我尝试在try [] [exception]中包装程序循环的每个部分,但错误仍然发生.不幸的是,我的搜索功能在一年中的这个时候似乎很弱,因为我没有找到任何可以解释问题的东西.

该代码是Carl Sassenrath的Tiny Web Server的缩减版本,稍加修改以绑定到特定的IP,并发出HTML而不是加载文件:

REBOL [title: "TestMovedServer"]
AppName: "Test"
NewSite: "http://test.myserver.org"

listen-port: open/lines tcp://:81   browse http://10.100.44.6?
buffer: make string! 1024  ; will auto-expand if needed

forever [
    http-port: first wait listen-port
    clear buffer

    while [not empty? request: first http-port][
        print request
        repend buffer [request newline]
        print "----------"
    ]
    repend buffer ["Address: " http-port/host newline] 
    print buffer
    Location: ""
    mime: "text/html"
    parse buffer ["get" ["http" | "/ " | copy Location to " "]]

    data: rejoin [{
        <HTML><HEAD><TITLE>Site Relocated</TITLE></HEAD>
        <BODY><CENTER><BR><BR><BR><BR><BR><BR>
        <H1>} AppName { have moved to <A HREF="} NewSite {">} NewSite {</A></H1>
        <BR><BR><BR>Please update the link you came from.
        <BR><BR><BR><BR><BR><A HREF="} NewSite Location {">(Continue directly to the requested page)</A>
        </CENTER></BODY></HTML>
    }]  
    insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"]
    write-io http-port data length? data
    close http-port
    print "============"
]
Run Code Online (Sandbox Code Playgroud)

我很期待看到你们为此做出的贡献!

sql*_*lab 3

尝试从关闭的连接读取数据时出现错误。这似乎有效。

n: 0
forever [
   http-port: first wait listen-port
   clear buffer
   if attempt [all [request: first http-port  not empty? request]] [
      until [
        print request
        repend buffer [request newline]
        print "----------"
        any [not request: first http-port empty? request]
      ]
      repend buffer ["Address: " http-port/host newline] 
      print buffer
      Location: ""
      mime: "text/html"
      parse buffer ["get" ["http" | "/ " | copy Location to " "]]

      data: rejoin [{
        <HTML><HEAD><TITLE>Site Relocated</TITLE></HEAD>
        <BODY><CENTER><BR><BR><BR><BR><BR><BR>
        <H1>} AppName n: n + 1 { has moved to <A HREF="} NewSite {">} NewSite {</A></H1>
        <BR><BR><BR>Please update the link you came from.
        <BR><BR><BR><BR><BR><A HREF="} NewSite Location {">(Continue directly to the requested page)</A>
        </CENTER></BODY></HTML>
      }]  
      insert data rejoin ["HTTP/1.0 200 OK^/Content-type: " mime "^/^/"]
      write-io http-port data length? data
  ]
  attempt [close http-port]
  print "============"
]
Run Code Online (Sandbox Code Playgroud)