6

I am working on a small library for creating a pair of connected pts. I use an epoll fd, in which I register the master fd for two pseudo-terminals for EPOLLIN events. When my example client program starts, the event loop is idle and so it is when two clients (microcom in my case) open each slave. But when any of the clients closes it's slave end, the epoll_wait continuously reports EPOLLHUP events for the slave's master.

In order to prevent this, I keep a file descriptor opened with O_WRONLY on each slave, it works (no more EPOLLHUP), but I think this is more a hack than a real solution... Socat seems to use a busy wait with a small sleep in this situation.

I have tried to :

  • use the Edge Triggered behavior
  • EPOLL_CTL_DEL then re-add the master producing HUP's

None of these attempt has shown any result.

Is there way to clean up the "HUP state" and put back the master file descriptors to their state prior to their slave's opening, after an EPOLLHUP occurs ?

ncarrier
  • 433
  • 3
  • 14
  • 1
    Sounds like you want to re-establish the connection between master and slave after the slave has closed. That's not possible as I understand it, but you may be able to workaround it as per the openpty solution in the comments for https://unix.stackexchange.com/questions/290847/is-it-possible-to-reuse-the-slave-end-of-a-pty-after-closing-it – Peter Brittain May 28 '19 at 17:04
  • @PeterBrittain What I understood of the link you provided, is that an fd is kept to avoid the issue, wich is the workaround I mentionned. Or did I miss something? – ncarrier Jun 06 '19 at 13:35
  • Yeah - it's the same principle, but allows you to do it from the master process instead. That's why I didn't post as an answer. – Peter Brittain Jun 06 '19 at 15:37

0 Answers0