Sockets D语言套接字。接收()

Sockets D语言套接字。接收(),sockets,d,Sockets,D,我在Windows上使用D编写了一个套接字服务器,现在我想在Linux上移植它。以下是代码摘要: /* * this.rawsocks - SocketSet * this.server - Socket * this.clients - array of custom client worker class */ char[1] buff; string input; int nbuff = 0; while (this.isrun) { this.rawsocks.add

我在Windows上使用D编写了一个套接字服务器,现在我想在Linux上移植它。以下是代码摘要:

/*
 * this.rawsocks - SocketSet
 * this.server - Socket
 * this.clients - array of custom client worker class
 */

char[1] buff;
string input;
int nbuff = 0;

while (this.isrun) {
    this.rawsocks.add(this.server);

    if (Socket.select(this.rawsocks, null, null)) {
        if (this.rawsocks.isSet(this.server)) {
            // accepting a new connection
        }

        foreach (ref key, item; this.clients) {
            // works for all connections
            writeln("test1");

            // mystically interrupts foreach loop
            nbuff = item.connection.receive(buff);

            // works only for the first connection.
            // when the first connection is closed, it works for the next
            writeln("test2");
        }
    }

    this.rawsocks.reset();

    foreach (key, value; this.clients)
        this.rawsocks.add(value.connection);
}
item.connection.receive(buff)
在Windows上运行良好,但在Linux上会中断foreach循环。没有任何异常,当第一个客户端断开连接时,将触发下一个客户端的
test2


Linux中的
.receive()
方法是否有一些特殊的行为,或者在我的实现中有一些问题?

这个问题的解决方案和问题本身一样奇怪:)


你所说的“中断foreach循环”是什么意思?@vines提示为下一个客户端调用
.receive()
会破坏
foreach
循环它看起来像是编译器中的一个严重错误。。。顺便问一下,您使用的是哪一个?@vines我使用dmd 2Random猜测:如果您尝试在没有活动的套接字上调用receive,可能会向您的进程发送posix信号。但这会扼杀整个过程,而不仅仅是foreach循环。。。
foreach (ref key, item; this.clients) {
     /*
      * The solution
      * Check of client's socket activity in SocketSet queue may not be necessary in Windows, but it is necessary in Linux
      * Thanks to my friend's research of this problem
      */
     if (!this.rawsocks.isSet(item.connection)) continue;

     // works for all connections
     writeln("test1");

     // after modifying not interrupts foreach loop
     nbuff = item.connection.receive(buff);

     // after modifying also works for all connections
     writeln("test2");
}