假设本地主机中没有应用程序侦听端口 12340。
下面的命令不应该打印“error”吗?
$ raku -e "IO::Socket::INET.new(:host('localhost'), :port(12340)) or die 'error'"
Could not connect socket: No connection could be made because the target machine actively refused it.
in block <unit> at -e line 1
Run Code Online (Sandbox Code Playgroud)
的当前实现nqp::connect(建立连接的底层逻辑)会引发异常X::AdHoc。如果无法连接,IO::Socket::INET.new则返回对我来说确实更有意义。Failure
我创建了一个拉取请求来创建此行为。
在此之前,您可以在本地使用相同的代码更改:
sub connect($host, $port) {
CATCH { return .Failure }
IO::Socket::INET.new(:$host, :$port)
}
connect('localhost', 12340) or die 'error';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
145 次 |
| 最近记录: |