Andrew Chang
Andrew Chang

Reputation: 1319

Can I determine which socket is closed when SIGPIPE risen?

I am working on a Mac OS application and using BSD Socket. I have several TCP sockets during run-time.

When SIGPIPE comes, what I know is that one or some socket(s) is/are closed by remote server. Is it possible to determine which socket(s) goes/go wrong when I catch the SIGPIPE signal?

Upvotes: 0

Views: 242

Answers (1)

Zan Lynx
Zan Lynx

Reputation: 54325

If your program is single threaded it is the last file descriptor that you wrote to. If multithreaded then you are out of luck.

I recommend that in both cases you just set SIGPIPE to SIGIGN and use the return value of write to determine a closed file descriptor.

Upvotes: 1

Related Questions