mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* win32/win32.c (is_socket, rb_w32_select, rb_w32_accept, rb_w32_bind,
rb_w32_connect, rb_w32_getpeername, rb_w32_getsockname, rb_w32_getsockopt, rb_w32_ioctlsocket, rb_w32_listen, rb_w32_recv, rb_w32_recvfrom, rb_w32_send, rb_w32_sendto, rb_w32_setsockopt, rb_w32_shutdown, rb_w32_socket, rb_w32_gethostbyaddr, rb_w32_gethostbyname, rb_w32_gethostname, rb_w32_getprotobyname, rb_w32_getprotobynumber, rb_w32_getservbyname, rb_w32_getservbyport): need to protect WSAGetLastError() by RUBY_CRITICAL. [ruby-talk:51778] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f5ab4eb859
commit
62280094cd
2 changed files with 142 additions and 85 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Sun Sep 29 06:33:03 2002 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (is_socket, rb_w32_select, rb_w32_accept, rb_w32_bind,
|
||||||
|
rb_w32_connect, rb_w32_getpeername, rb_w32_getsockname,
|
||||||
|
rb_w32_getsockopt, rb_w32_ioctlsocket, rb_w32_listen, rb_w32_recv,
|
||||||
|
rb_w32_recvfrom, rb_w32_send, rb_w32_sendto, rb_w32_setsockopt,
|
||||||
|
rb_w32_shutdown, rb_w32_socket, rb_w32_gethostbyaddr,
|
||||||
|
rb_w32_gethostbyname, rb_w32_gethostname, rb_w32_getprotobyname,
|
||||||
|
rb_w32_getprotobynumber, rb_w32_getservbyname, rb_w32_getservbyport):
|
||||||
|
need to protect WSAGetLastError() by RUBY_CRITICAL. [ruby-talk:51778]
|
||||||
|
|
||||||
Sat Sep 28 20:06:36 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Sat Sep 28 20:06:36 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* keywords: add braces around initializers.
|
* keywords: add braces around initializers.
|
||||||
|
|
216
win32/win32.c
216
win32/win32.c
|
@ -1472,22 +1472,24 @@ is_socket(SOCKET fd)
|
||||||
char sockbuf[80];
|
char sockbuf[80];
|
||||||
int optlen;
|
int optlen;
|
||||||
int retval;
|
int retval;
|
||||||
|
int result = TRUE;
|
||||||
|
|
||||||
optlen = sizeof(sockbuf);
|
optlen = sizeof(sockbuf);
|
||||||
retval = getsockopt(fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
|
RUBY_CRITICAL({
|
||||||
if (retval == SOCKET_ERROR) {
|
retval = getsockopt(fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
|
||||||
int iRet;
|
if (retval == SOCKET_ERROR) {
|
||||||
|
int iRet;
|
||||||
iRet = WSAGetLastError();
|
iRet = WSAGetLastError();
|
||||||
if (iRet == WSAENOTSOCK || iRet == WSANOTINITIALISED)
|
if (iRet == WSAENOTSOCK || iRet == WSANOTINITIALISED)
|
||||||
return FALSE;
|
result = FALSE;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
// If we get here, then fd is actually a socket.
|
// If we get here, then fd is actually a socket.
|
||||||
//
|
//
|
||||||
|
|
||||||
return TRUE;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1746,15 +1748,17 @@ rb_w32_select (int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
|
||||||
ex = &trap;
|
ex = &trap;
|
||||||
#endif /* USE_INTERRUPT_WINSOCK */
|
#endif /* USE_INTERRUPT_WINSOCK */
|
||||||
|
|
||||||
RUBY_CRITICAL(r = select (nfds, rd, wr, ex, timeout));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR) {
|
r = select(nfds, rd, wr, ex, timeout);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR) {
|
||||||
switch (errno) {
|
errno = WSAGetLastError();
|
||||||
case WSAEINTR:
|
switch (errno) {
|
||||||
errno = EINTR;
|
case WSAEINTR:
|
||||||
break;
|
errno = EINTR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1814,9 +1818,11 @@ rb_w32_accept (SOCKET s, struct sockaddr *addr, int *addrlen)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = accept (TO_SOCKET(s), addr, addrlen));
|
RUBY_CRITICAL({
|
||||||
if (r == INVALID_SOCKET)
|
r = accept(TO_SOCKET(s), addr, addrlen);
|
||||||
errno = WSAGetLastError();
|
if (r == INVALID_SOCKET)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return rb_w32_open_osfhandle(r, O_RDWR|O_BINARY);
|
return rb_w32_open_osfhandle(r, O_RDWR|O_BINARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1830,9 +1836,11 @@ rb_w32_bind (SOCKET s, struct sockaddr *addr, int addrlen)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = bind (TO_SOCKET(s), addr, addrlen));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = bind(TO_SOCKET(s), addr, addrlen);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1845,9 +1853,11 @@ rb_w32_connect (SOCKET s, struct sockaddr *addr, int addrlen)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = connect (TO_SOCKET(s), addr, addrlen));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = connect(TO_SOCKET(s), addr, addrlen);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1861,9 +1871,11 @@ rb_w32_getpeername (SOCKET s, struct sockaddr *addr, int *addrlen)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = getpeername (TO_SOCKET(s), addr, addrlen));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = getpeername(TO_SOCKET(s), addr, addrlen);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1876,9 +1888,11 @@ rb_w32_getsockname (SOCKET s, struct sockaddr *addr, int *addrlen)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = getsockname (TO_SOCKET(s), addr, addrlen));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = getsockname(TO_SOCKET(s), addr, addrlen);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1889,9 +1903,11 @@ rb_w32_getsockopt (SOCKET s, int level, int optname, char *optval, int *optlen)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = getsockopt (TO_SOCKET(s), level, optname, optval, optlen));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = getsockopt(TO_SOCKET(s), level, optname, optval, optlen);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1904,9 +1920,11 @@ rb_w32_ioctlsocket (SOCKET s, long cmd, u_long *argp)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = ioctlsocket (TO_SOCKET(s), cmd, argp));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = ioctlsocket(TO_SOCKET(s), cmd, argp);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1919,9 +1937,11 @@ rb_w32_listen (SOCKET s, int backlog)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = listen (TO_SOCKET(s), backlog));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = listen(TO_SOCKET(s), backlog);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1934,9 +1954,11 @@ rb_w32_recv (SOCKET s, char *buf, int len, int flags)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = recv (TO_SOCKET(s), buf, len, flags));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = recv(TO_SOCKET(s), buf, len, flags);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1950,9 +1972,11 @@ rb_w32_recvfrom (SOCKET s, char *buf, int len, int flags,
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = recvfrom (TO_SOCKET(s), buf, len, flags, from, fromlen));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = recvfrom(TO_SOCKET(s), buf, len, flags, from, fromlen);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1965,9 +1989,11 @@ rb_w32_send (SOCKET s, char *buf, int len, int flags)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = send (TO_SOCKET(s), buf, len, flags));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = send(TO_SOCKET(s), buf, len, flags);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1981,9 +2007,11 @@ rb_w32_sendto (SOCKET s, char *buf, int len, int flags,
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = sendto (TO_SOCKET(s), buf, len, flags, to, tolen));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = sendto(TO_SOCKET(s), buf, len, flags, to, tolen);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1996,9 +2024,11 @@ rb_w32_setsockopt (SOCKET s, int level, int optname, char *optval, int optlen)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = setsockopt (TO_SOCKET(s), level, optname, optval, optlen));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = setsockopt(TO_SOCKET(s), level, optname, optval, optlen);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2011,9 +2041,11 @@ rb_w32_shutdown (SOCKET s, int how)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = shutdown (TO_SOCKET(s), how));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = shutdown(TO_SOCKET(s), how);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2026,11 +2058,11 @@ rb_w32_socket (int af, int type, int protocol)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(s = socket (af, type, protocol));
|
RUBY_CRITICAL({
|
||||||
if (s == INVALID_SOCKET) {
|
s = socket(af, type, protocol);
|
||||||
errno = WSAGetLastError();
|
if (s == INVALID_SOCKET)
|
||||||
//fprintf(stderr, "socket fail (%d)", WSAGetLastError());
|
errno = WSAGetLastError();
|
||||||
}
|
});
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
return _open_osfhandle(s, O_RDWR|O_BINARY);
|
return _open_osfhandle(s, O_RDWR|O_BINARY);
|
||||||
#else
|
#else
|
||||||
|
@ -2047,9 +2079,11 @@ rb_w32_gethostbyaddr (char *addr, int len, int type)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = gethostbyaddr (addr, len, type));
|
RUBY_CRITICAL({
|
||||||
if (r == NULL)
|
r = gethostbyaddr(addr, len, type);
|
||||||
errno = WSAGetLastError();
|
if (r == NULL)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2062,9 +2096,11 @@ rb_w32_gethostbyname (char *name)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = gethostbyname (name));
|
RUBY_CRITICAL({
|
||||||
if (r == NULL)
|
r = gethostbyname(name);
|
||||||
errno = WSAGetLastError();
|
if (r == NULL)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2077,9 +2113,11 @@ rb_w32_gethostname (char *name, int len)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = gethostname (name, len));
|
RUBY_CRITICAL({
|
||||||
if (r == SOCKET_ERROR)
|
r = gethostname(name, len);
|
||||||
errno = WSAGetLastError();
|
if (r == SOCKET_ERROR)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2092,9 +2130,11 @@ rb_w32_getprotobyname (char *name)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = getprotobyname (name));
|
RUBY_CRITICAL({
|
||||||
if (r == NULL)
|
r = getprotobyname(name);
|
||||||
errno = WSAGetLastError();
|
if (r == NULL)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2107,9 +2147,11 @@ rb_w32_getprotobynumber (int num)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = getprotobynumber (num));
|
RUBY_CRITICAL({
|
||||||
if (r == NULL)
|
r = getprotobynumber(num);
|
||||||
errno = WSAGetLastError();
|
if (r == NULL)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2122,9 +2164,11 @@ rb_w32_getservbyname (char *name, char *proto)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = getservbyname (name, proto));
|
RUBY_CRITICAL({
|
||||||
if (r == NULL)
|
r = getservbyname(name, proto);
|
||||||
errno = WSAGetLastError();
|
if (r == NULL)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2137,9 +2181,11 @@ rb_w32_getservbyport (int port, char *proto)
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized++) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL(r = getservbyport (port, proto));
|
RUBY_CRITICAL({
|
||||||
if (r == NULL)
|
r = getservbyport(port, proto);
|
||||||
errno = WSAGetLastError();
|
if (r == NULL)
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue