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.
|
||||||
|
|
104
win32/win32.c
104
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);
|
||||||
|
RUBY_CRITICAL({
|
||||||
retval = getsockopt(fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
|
retval = getsockopt(fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
|
||||||
if (retval == SOCKET_ERROR) {
|
if (retval == SOCKET_ERROR) {
|
||||||
int iRet;
|
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,7 +1748,8 @@ 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({
|
||||||
|
r = select(nfds, rd, wr, ex, timeout);
|
||||||
if (r == SOCKET_ERROR) {
|
if (r == SOCKET_ERROR) {
|
||||||
errno = WSAGetLastError();
|
errno = WSAGetLastError();
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
|
@ -1755,6 +1758,7 @@ rb_w32_select (int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
|
||||||
break;
|
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({
|
||||||
|
r = accept(TO_SOCKET(s), addr, addrlen);
|
||||||
if (r == INVALID_SOCKET)
|
if (r == INVALID_SOCKET)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = bind(TO_SOCKET(s), addr, addrlen);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = connect(TO_SOCKET(s), addr, addrlen);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = getpeername(TO_SOCKET(s), addr, addrlen);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = getsockname(TO_SOCKET(s), addr, addrlen);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = getsockopt(TO_SOCKET(s), level, optname, optval, optlen);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = ioctlsocket(TO_SOCKET(s), cmd, argp);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = listen(TO_SOCKET(s), backlog);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = recv(TO_SOCKET(s), buf, len, flags);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = recvfrom(TO_SOCKET(s), buf, len, flags, from, fromlen);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = send(TO_SOCKET(s), buf, len, flags);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = sendto(TO_SOCKET(s), buf, len, flags, to, tolen);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = setsockopt(TO_SOCKET(s), level, optname, optval, optlen);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = shutdown(TO_SOCKET(s), how);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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);
|
||||||
|
if (s == INVALID_SOCKET)
|
||||||
errno = WSAGetLastError();
|
errno = WSAGetLastError();
|
||||||
//fprintf(stderr, "socket fail (%d)", 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({
|
||||||
|
r = gethostbyaddr(addr, len, type);
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = gethostbyname(name);
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = gethostname(name, len);
|
||||||
if (r == SOCKET_ERROR)
|
if (r == SOCKET_ERROR)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = getprotobyname(name);
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = getprotobynumber(num);
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = getservbyname(name, proto);
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
errno = WSAGetLastError();
|
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({
|
||||||
|
r = getservbyport(port, proto);
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
errno = WSAGetLastError();
|
errno = WSAGetLastError();
|
||||||
|
});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue