* win32/win32.c (rb_w32_fclose, rb_w32_close): use closesocket()
for socket. [ruby-win32:382] * win32/win32.c (StartSockets): set NtSocketsInitialized. * win32/win32.h: prototypes; rb_w32_fclose, rb_w32_close git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
539428b0f4
commit
31ab445fea
@ -1,3 +1,12 @@
|
|||||||
|
Fri Oct 11 06:05:30 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* win32/win32.c (rb_w32_fclose, rb_w32_close): use closesocket()
|
||||||
|
for socket. [ruby-win32:382]
|
||||||
|
|
||||||
|
* win32/win32.c (StartSockets): set NtSocketsInitialized.
|
||||||
|
|
||||||
|
* win32/win32.h: prototypes; rb_w32_fclose, rb_w32_close
|
||||||
|
|
||||||
Fri Oct 11 00:24:57 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Fri Oct 11 00:24:57 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* gc.c (ruby_xmalloc, ruby_xrealloc): restrict total allocation
|
* gc.c (ruby_xmalloc, ruby_xrealloc): restrict total allocation
|
||||||
|
@ -33,7 +33,11 @@
|
|||||||
#define index(x, y) strchr((x), (y))
|
#define index(x, y) strchr((x), (y))
|
||||||
#endif
|
#endif
|
||||||
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
||||||
|
|
||||||
#undef stat
|
#undef stat
|
||||||
|
#undef fclose
|
||||||
|
#undef close
|
||||||
|
#undef setsockopt
|
||||||
|
|
||||||
#ifndef bool
|
#ifndef bool
|
||||||
#define bool int
|
#define bool int
|
||||||
@ -1673,7 +1677,7 @@ rb_w32_select (int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
|
|||||||
#endif /* USE_INTERRUPT_WINSOCK */
|
#endif /* USE_INTERRUPT_WINSOCK */
|
||||||
int file_nfds;
|
int file_nfds;
|
||||||
|
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
r = 0;
|
r = 0;
|
||||||
@ -1727,7 +1731,7 @@ StartSockets ()
|
|||||||
WORD version;
|
WORD version;
|
||||||
WSADATA retdata;
|
WSADATA retdata;
|
||||||
int ret;
|
int ret;
|
||||||
int iSockOpt;
|
int iSockOpt;
|
||||||
|
|
||||||
//
|
//
|
||||||
// initalize the winsock interface and insure that it's
|
// initalize the winsock interface and insure that it's
|
||||||
@ -1765,6 +1769,7 @@ StartSockets ()
|
|||||||
interrupted_event = CreateSignal();
|
interrupted_event = CreateSignal();
|
||||||
if (!interrupted_event)
|
if (!interrupted_event)
|
||||||
rb_fatal("Unable to create interrupt event!\n");
|
rb_fatal("Unable to create interrupt event!\n");
|
||||||
|
NtSocketsInitialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef accept
|
#undef accept
|
||||||
@ -1774,7 +1779,7 @@ rb_w32_accept(int s, struct sockaddr *addr, int *addrlen)
|
|||||||
{
|
{
|
||||||
SOCKET r;
|
SOCKET r;
|
||||||
|
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1797,7 +1802,7 @@ rb_w32_bind(int s, struct sockaddr *addr, int addrlen)
|
|||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1814,7 +1819,7 @@ int
|
|||||||
rb_w32_connect(int s, struct sockaddr *addr, int addrlen)
|
rb_w32_connect(int s, struct sockaddr *addr, int addrlen)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1832,7 +1837,7 @@ int
|
|||||||
rb_w32_getpeername(int s, struct sockaddr *addr, int *addrlen)
|
rb_w32_getpeername(int s, struct sockaddr *addr, int *addrlen)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1849,7 +1854,7 @@ int
|
|||||||
rb_w32_getsockname(int s, struct sockaddr *addr, int *addrlen)
|
rb_w32_getsockname(int s, struct sockaddr *addr, int *addrlen)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1864,7 +1869,7 @@ int
|
|||||||
rb_w32_getsockopt(int s, int level, int optname, char *optval, int *optlen)
|
rb_w32_getsockopt(int s, int level, int optname, char *optval, int *optlen)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1881,7 +1886,7 @@ int
|
|||||||
rb_w32_ioctlsocket(int s, long cmd, u_long *argp)
|
rb_w32_ioctlsocket(int s, long cmd, u_long *argp)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1898,7 +1903,7 @@ int
|
|||||||
rb_w32_listen(int s, int backlog)
|
rb_w32_listen(int s, int backlog)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1915,7 +1920,7 @@ int
|
|||||||
rb_w32_recv(int s, char *buf, int len, int flags)
|
rb_w32_recv(int s, char *buf, int len, int flags)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1933,7 +1938,7 @@ rb_w32_recvfrom(int s, char *buf, int len, int flags,
|
|||||||
struct sockaddr *from, int *fromlen)
|
struct sockaddr *from, int *fromlen)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1950,7 +1955,7 @@ int
|
|||||||
rb_w32_send(int s, char *buf, int len, int flags)
|
rb_w32_send(int s, char *buf, int len, int flags)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1968,7 +1973,7 @@ rb_w32_sendto(int s, char *buf, int len, int flags,
|
|||||||
struct sockaddr *to, int tolen)
|
struct sockaddr *to, int tolen)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -1985,7 +1990,7 @@ int
|
|||||||
rb_w32_setsockopt(int s, int level, int optname, char *optval, int optlen)
|
rb_w32_setsockopt(int s, int level, int optname, char *optval, int optlen)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2002,7 +2007,7 @@ int
|
|||||||
rb_w32_shutdown(int s, int how)
|
rb_w32_shutdown(int s, int how)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2021,7 +2026,7 @@ rb_w32_socket(int af, int type, int protocol)
|
|||||||
SOCKET s;
|
SOCKET s;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2043,7 +2048,7 @@ struct hostent *
|
|||||||
rb_w32_gethostbyaddr (char *addr, int len, int type)
|
rb_w32_gethostbyaddr (char *addr, int len, int type)
|
||||||
{
|
{
|
||||||
struct hostent *r;
|
struct hostent *r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2060,7 +2065,7 @@ struct hostent *
|
|||||||
rb_w32_gethostbyname (char *name)
|
rb_w32_gethostbyname (char *name)
|
||||||
{
|
{
|
||||||
struct hostent *r;
|
struct hostent *r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2077,7 +2082,7 @@ int
|
|||||||
rb_w32_gethostname (char *name, int len)
|
rb_w32_gethostname (char *name, int len)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2094,7 +2099,7 @@ struct protoent *
|
|||||||
rb_w32_getprotobyname (char *name)
|
rb_w32_getprotobyname (char *name)
|
||||||
{
|
{
|
||||||
struct protoent *r;
|
struct protoent *r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2111,7 +2116,7 @@ struct protoent *
|
|||||||
rb_w32_getprotobynumber (int num)
|
rb_w32_getprotobynumber (int num)
|
||||||
{
|
{
|
||||||
struct protoent *r;
|
struct protoent *r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2128,7 +2133,7 @@ struct servent *
|
|||||||
rb_w32_getservbyname (char *name, char *proto)
|
rb_w32_getservbyname (char *name, char *proto)
|
||||||
{
|
{
|
||||||
struct servent *r;
|
struct servent *r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2145,7 +2150,7 @@ struct servent *
|
|||||||
rb_w32_getservbyport (int port, char *proto)
|
rb_w32_getservbyport (int port, char *proto)
|
||||||
{
|
{
|
||||||
struct servent *r;
|
struct servent *r;
|
||||||
if (!NtSocketsInitialized++) {
|
if (!NtSocketsInitialized) {
|
||||||
StartSockets();
|
StartSockets();
|
||||||
}
|
}
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
@ -2947,3 +2952,37 @@ pid_t rb_w32_getpid(void)
|
|||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rb_w32_fclose(FILE *fp)
|
||||||
|
{
|
||||||
|
int fd = fileno(fp);
|
||||||
|
SOCKET sock = TO_SOCKET(fd);
|
||||||
|
|
||||||
|
if (fflush(fp)) return -1;
|
||||||
|
if (!is_socket(sock)) {
|
||||||
|
return fclose(fp);
|
||||||
|
}
|
||||||
|
_set_osfhnd(fd, (SOCKET)INVALID_HANDLE_VALUE);
|
||||||
|
fclose(fp);
|
||||||
|
if (closesocket(sock) == SOCKET_ERROR) {
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rb_w32_close(int fd)
|
||||||
|
{
|
||||||
|
SOCKET sock = TO_SOCKET(fd);
|
||||||
|
|
||||||
|
if (!is_socket(sock)) {
|
||||||
|
return _close(fd);
|
||||||
|
}
|
||||||
|
if (closesocket(sock) == SOCKET_ERROR) {
|
||||||
|
errno = WSAGetLastError();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef EXT_NT_H
|
#ifndef RUBY_WIN32_H
|
||||||
#define EXT_NT_H
|
#define RUBY_WIN32_H
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1993, Intergraph Corporation
|
* Copyright (c) 1993, Intergraph Corporation
|
||||||
@ -87,8 +87,8 @@ extern "C++" {
|
|||||||
#define fputc(_c, _stream) putc(_c, _stream)
|
#define fputc(_c, _stream) putc(_c, _stream)
|
||||||
#define getchar() rb_w32_getc(stdin)
|
#define getchar() rb_w32_getc(stdin)
|
||||||
#define putchar(_c) rb_w32_putc(_c, stdout)
|
#define putchar(_c) rb_w32_putc(_c, stdout)
|
||||||
#define fgetchar(_stream) getchar()
|
#define fgetchar() getchar()
|
||||||
#define fputchar(_c, _stream) putchar(_c)
|
#define fputchar(_c) putchar(_c)
|
||||||
|
|
||||||
#ifndef __BORLANDC__
|
#ifndef __BORLANDC__
|
||||||
|
|
||||||
@ -128,7 +128,8 @@ extern "C++" {
|
|||||||
#define _open _sopen
|
#define _open _sopen
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define close _close
|
#define close rb_w32_close
|
||||||
|
#define fclose rb_w32_fclose
|
||||||
#define creat _creat
|
#define creat _creat
|
||||||
#define eof _eof
|
#define eof _eof
|
||||||
#define filelength _filelength
|
#define filelength _filelength
|
||||||
@ -476,6 +477,8 @@ void rb_w32_enter_critical(void);
|
|||||||
void rb_w32_leave_critical(void);
|
void rb_w32_leave_critical(void);
|
||||||
int rb_w32_putc(int, FILE*);
|
int rb_w32_putc(int, FILE*);
|
||||||
int rb_w32_getc(FILE*);
|
int rb_w32_getc(FILE*);
|
||||||
|
int rb_w32_close(int);
|
||||||
|
int rb_w32_fclose(FILE*);
|
||||||
#define Sleep(msec) (void)rb_w32_sleep(msec)
|
#define Sleep(msec) (void)rb_w32_sleep(msec)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user