1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/missing/close.c
akr 2f2b6ace05 * missing/close.c: undef the macros "getpeername", "getsockname" and
"shutdown" to prevent infinite recursion.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-08-07 10:05:37 +00:00

72 lines
1.1 KiB
C

/* Ignore ECONNRESET of FreeBSD */
#include "ruby/missing.h"
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#undef getpeername
int
ruby_getpeername(int s, struct sockaddr * name,
socklen_t * namelen)
{
int err = errno;
errno = 0;
s = getpeername(s, name, namelen);
if (errno == ECONNRESET) {
errno = 0;
s = 0;
}
else if (errno == 0)
errno = err;
return s;
}
#undef getsockname
int
ruby_getsockname(int s, struct sockaddr * name,
socklen_t * namelen)
{
int err = errno;
errno = 0;
s = getsockname(s, name, namelen);
if (errno == ECONNRESET) {
errno = 0;
s = 0;
}
else if (errno == 0)
errno = err;
return s;
}
#undef shutdown
int
ruby_shutdown(int s, int how)
{
int err = errno;
errno = 0;
s = shutdown(s, how);
if (errno == ECONNRESET) {
errno = 0;
s = 0;
}
else if (errno == 0)
errno = err;
return s;
}
#undef close
int
ruby_close(int s)
{
int err = errno;
errno = 0;
s = close(s);
if (errno == ECONNRESET) {
errno = 0;
s = 0;
}
else if (errno == 0)
errno = err;
return s;
}