Background: This is the next question in this thread about handling EINTR for system calls in C ++ (Linux / GCC). Regardless of whether I intend to profile my application, it seems that I should handle system calls with installation errnoon EINTRas a special case. There are many , many , many opinions on use goto.
My question is: is this a system call errnoto the EINTRcase when gotoit is considered nominal? If not, how would you suggest converting the following code for processing EINTR?
if ( ( sock_fd = ::socket( domain, type, protocol ) ) < 0 ) {
throw SocketException( "Socket::Socket() -> ::socket()", errno );
}
Thanks in advance! Cheers,
Chris
UPDATE: Based on the answers below, I ended up writing the following macro:
while ( (call) < 0 ) { \
switch ( errno ) { \
case EINTR: \
continue; \
default: \
throw SocketException( (error), errno ); \
} \
} \
What is used to convert my source fragment to this example:
SOCK_SYSCALL_TRY( sock_fd = ::socket( domain, type, protocol ), "Socket::Socket() -> ::socket()" )
Hope this helps someone else!
source
share