Why is sigprocmask called when the recv system call is called?

I have code that periodically calls recv() (with the MSG_DONTWAIT flag). I'm curious because profiling my code in vtune, I see the sigprocmask() call associated with recv() , and it takes most of the total time to execute. I am curious why recv() calls sigprocmask() .

+6
source share
2 answers

When working with a TCP socket under Linux, you will get SIGPIPE if the other side is unexpectedly closed.

Since you can mask this signal (most of the time you will process the return value of 0 yourself, you do not need this signal), I think that the system library checks the signal status, and if masked, use a faster code path.

If not, he cannot optimize.

By the way, do you know about pselect () correctly?

+1
source

It is possible that recv can determine if appropriate signals are generated that would otherwise not have been visible if the signals had been blocked. EAGAIN / EWOULDBLOCK come to mind as errno values, which are sometimes generated using signals that can be blocked. Have you viewed the sigprocmask man page?

0
source

Source: https://habr.com/ru/post/915448/


All Articles