2010-07-06 21:29:22 -04:00
|
|
|
/* Ignore ECONNRESET of FreeBSD */
|
2010-07-28 04:12:01 -04:00
|
|
|
#include "ruby/missing.h"
|
2010-07-06 21:29:22 -04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2010-08-07 06:05:37 -04:00
|
|
|
#undef getpeername
|
2010-07-06 21:29:22 -04:00
|
|
|
int
|
|
|
|
ruby_getpeername(int s, struct sockaddr * name,
|
|
|
|
socklen_t * namelen)
|
|
|
|
{
|
2010-07-13 00:15:30 -04:00
|
|
|
int err = errno;
|
2010-07-06 21:29:22 -04:00
|
|
|
errno = 0;
|
|
|
|
s = getpeername(s, name, namelen);
|
|
|
|
if (errno == ECONNRESET) {
|
|
|
|
errno = 0;
|
|
|
|
s = 0;
|
|
|
|
}
|
2010-07-13 00:15:30 -04:00
|
|
|
else if (errno == 0)
|
|
|
|
errno = err;
|
2010-07-06 21:29:22 -04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2010-08-07 06:05:37 -04:00
|
|
|
#undef getsockname
|
2010-07-06 21:29:22 -04:00
|
|
|
int
|
|
|
|
ruby_getsockname(int s, struct sockaddr * name,
|
|
|
|
socklen_t * namelen)
|
|
|
|
{
|
2010-07-13 00:15:30 -04:00
|
|
|
int err = errno;
|
2010-07-06 21:29:22 -04:00
|
|
|
errno = 0;
|
|
|
|
s = getsockname(s, name, namelen);
|
|
|
|
if (errno == ECONNRESET) {
|
|
|
|
errno = 0;
|
|
|
|
s = 0;
|
|
|
|
}
|
2010-07-13 00:15:30 -04:00
|
|
|
else if (errno == 0)
|
|
|
|
errno = err;
|
2010-07-06 21:29:22 -04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2010-08-07 06:05:37 -04:00
|
|
|
#undef shutdown
|
2010-07-06 21:29:22 -04:00
|
|
|
int
|
|
|
|
ruby_shutdown(int s, int how)
|
|
|
|
{
|
2010-07-13 00:15:30 -04:00
|
|
|
int err = errno;
|
2010-07-06 21:29:22 -04:00
|
|
|
errno = 0;
|
|
|
|
s = shutdown(s, how);
|
|
|
|
if (errno == ECONNRESET) {
|
|
|
|
errno = 0;
|
|
|
|
s = 0;
|
|
|
|
}
|
2010-07-13 00:15:30 -04:00
|
|
|
else if (errno == 0)
|
|
|
|
errno = err;
|
2010-07-06 21:29:22 -04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2010-08-07 06:05:37 -04:00
|
|
|
#undef close
|
2010-07-06 21:29:22 -04:00
|
|
|
int
|
|
|
|
ruby_close(int s)
|
|
|
|
{
|
2010-07-13 00:15:30 -04:00
|
|
|
int err = errno;
|
2010-07-06 21:29:22 -04:00
|
|
|
errno = 0;
|
|
|
|
s = close(s);
|
|
|
|
if (errno == ECONNRESET) {
|
|
|
|
errno = 0;
|
|
|
|
s = 0;
|
|
|
|
}
|
2010-07-13 00:15:30 -04:00
|
|
|
else if (errno == 0)
|
|
|
|
errno = err;
|
2010-07-06 21:29:22 -04:00
|
|
|
return s;
|
|
|
|
}
|