Check for EWOULDBLOCK as well as EAGAIN on write.

On some systems, notably HP PA-RISC systems running Linux or HP-UX,
EWOULDBLOCK and EAGAIN are not the same value.  POSIX (and these OSes) allow
EWOULDBLOCK to occur on write(2) (and send(2), etc.), so check explicitly
for this case as well as EAGAIN by defining and using a macro GIT_ISBLOCKED
that considers both.

The macro is necessary because MSYS does not provide EWOULDBLOCK and
compilation fails if an attempt is made to use it unconditionally.  On most
systems, where the two values are the same, the compiler will simply
optimize this check out and it will have no effect.
This commit is contained in:
brian m. carlson 2014-02-15 23:09:01 +00:00
parent dbd2ca356b
commit 0197d4107a
No known key found for this signature in database
GPG Key ID: BF535D811F52F68B
2 changed files with 10 additions and 1 deletions

View File

@ -189,7 +189,7 @@ int p_write(git_file fd, const void *buf, size_t cnt)
r = write(fd, b, cnt); r = write(fd, b, cnt);
#endif #endif
if (r < 0) { if (r < 0) {
if (errno == EINTR || errno == EAGAIN) if (errno == EINTR || GIT_ISBLOCKED(errno))
continue; continue;
return -1; return -1;
} }

View File

@ -29,6 +29,15 @@
#define O_CLOEXEC 0 #define O_CLOEXEC 0
#endif #endif
/* Determine whether an errno value indicates that a read or write failed
* because the descriptor is blocked.
*/
#if defined(EWOULDBLOCK)
#define GIT_ISBLOCKED(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)
#else
#define GIT_ISBLOCKED(e) ((e) == EAGAIN)
#endif
typedef int git_file; typedef int git_file;
/** /**