Ruby: missing/close.c Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

close.c
1/* Ignore ECONNRESET of FreeBSD */
2#include "ruby/missing.h"
3#include <errno.h>
4#include <unistd.h>
5#include <sys/types.h>
6#include <sys/socket.h>
7
8#undef getpeername
9int
10ruby_getpeername(int s, struct sockaddr * name,
11 socklen_t * namelen)
12{
13 int err = errno;
14 errno = 0;
15 s = getpeername(s, name, namelen);
16 if (errno == ECONNRESET) {
17 errno = 0;
18 s = 0;
19 }
20 else if (errno == 0)
21 errno = err;
22 return s;
23}
24
25#undef getsockname
26int
27ruby_getsockname(int s, struct sockaddr * name,
28 socklen_t * namelen)
29{
30 int err = errno;
31 errno = 0;
32 s = getsockname(s, name, namelen);
33 if (errno == ECONNRESET) {
34 errno = 0;
35 s = 0;
36 }
37 else if (errno == 0)
38 errno = err;
39 return s;
40}
41
42#undef shutdown
43int
44ruby_shutdown(int s, int how)
45{
46 int err = errno;
47 errno = 0;
48 s = shutdown(s, how);
49 if (errno == ECONNRESET) {
50 errno = 0;
51 s = 0;
52 }
53 else if (errno == 0)
54 errno = err;
55 return s;
56}
57
58#undef close
59int
60ruby_close(int s)
61{
62 int err = errno;
63 errno = 0;
64 s = close(s);
65 if (errno == ECONNRESET) {
66 errno = 0;
67 s = 0;
68 }
69 else if (errno == 0)
70 errno = err;
71 return s;
72}