2

As the Title already says im looking for a way, to get notified when a client closes his Session unnormal.

I'm using the freeBSD OS. The server is running with Xamount threads (depending on CPUcore amount). So I'm not forking, and there isn't a own process for each client.

That's why sending an deathpackage all time_t seconds, to recive a SIGPIPE isn't an option for me. But i need to remove left clients from the kqueue, because otherwise after too many accept()'s my code will obviously run into memory troubles.

Is there a way, I can check without high performance loose per client, they are connected or not?

Or any event-notification, that would trigger if this happens? Or maybe is there a way of letting a programm send any signal to a port, even in abnormal termination case, before the Client process will exite?

4

2 回答 2

1

编辑:那个答案错过了这个问题,因为它不是关于使用 kqueue。但是如果其他人通过标题找到问题,无论如何它可能会有所帮助......

我经常看到以下行为:如果客户端死了,并且服务器select()在客户端的套接字描述符上执行了 a 操作,则select()返回代码 > 0 并且FD_ISSET( fd )该描述符为 true。但是,当您现在尝试从套接字读取时,read()(或recv())返回 ERROR。

对于使用它来检测客户端死亡的“正常”连接对我们来说效果很好,但是当套接字连接被隧道化时似乎存在不同的行为,但我们还没有完全弄清楚这一点。

于 2013-08-09T11:29:17.317 回答
0

根据kqueue 手册页kevent()应该在套接字关闭时创建一个事件。从过滤器的描述EVFILT_READ

EVFILT_READ

将描述符作为标识符,并在有数据可供读取时返回。根据描述符类型,过滤器的行为略有不同。

插座

当传入连接挂起时,先前已传递给 listen() 的套接字将返回。data 包含监听积压的大小。

其他套接字描述符在有数据要读取时返回,取决于套接字缓冲区的 SO_RCVLOWAT 值。在添加过滤器时,可以通过在 fflags 中设置 NOTE_LOWAT 标志并在数据中指定新的低水位标记来覆盖每个过滤器的低水位标记。返回时,数据包含可供读取的协议数据的字节数。

如果套接字的读取方向已关闭,则过滤器还会在 flags 中设置 EV_EOF,并在 fflags 中返回套接字错误(如果有)。 当套接字缓冲区中仍有待处理的数据时,可能会返回 EOF(表示连接已消失)。

于 2013-08-09T14:46:11.950 回答