Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is sigprocmask called when calling the recv system call?

Tags:

c++

linux

I've got some code that calls recv() periodically (with a MSG_DONTWAIT flag). I'm curious because profiling my code in vtune, I see a sigprocmask() call associated with the recv(), and it's taking a large portion of the total time to execute. I'm curious why recv() is calling sigprocmask().

like image 878
gct Avatar asked May 10 '12 22:05

gct


1 Answers

When working with TCP socket under linux, you'll receive SIGPIPE if the other side is closed unexpectedly.

Since you can mask this signal (most of the time, you'll handle the return value of 0 yourself, you don't care about this signal), I guess the system library checks for the signal state, and if masked, use a faster code path.

If not, it can't optimize.

BTW, you know about pselect() right ?

like image 169
xryl669 Avatar answered Nov 14 '22 23:11

xryl669