summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-16 07:24:21 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-16 07:24:21 +0000
commit074203d270bba2046f6d272f9d01385257be9fee (patch)
treee4ece206c3afe82313f3faa4a82468cdfb32d2f5 /win32
parent46620a87720943120cabe6ffe2e94a2c3506c4c2 (diff)
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c36
-rw-r--r--win32/win32.h7
2 files changed, 17 insertions, 26 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 74c18aa..9e2eb2f 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -1726,6 +1726,8 @@ my_open_osfhandle(long osfhandle, int flags)
return fh; /* return handle */
}
+#undef getsockopt
+
static int
is_socket(SOCKET fd)
{
@@ -1750,18 +1752,15 @@ is_socket(SOCKET fd)
return TRUE;
}
-FILE *
-myfdopen (int fd, const char *mode)
+int
+myfddup (int fd)
{
- if (is_socket((SOCKET)fd)) {
- int fh;
+ SOCKET s = TO_SOCKET(fd);
- fh = my_open_osfhandle((SOCKET)fd, O_RDWR|O_BINARY);
- return _fdopen(fh, mode); // return file pointer
- }
- else {
- return (_fdopen(fd, mode));
- }
+ if (s == -1)
+ return -1;
+
+ return my_open_osfhandle(s, O_RDWR|O_BINARY);
}
@@ -2056,14 +2055,13 @@ SOCKET
myaccept (SOCKET s, struct sockaddr *addr, int *addrlen)
{
SOCKET r;
- int trap_immediate = rb_trap_immediate;
if (!NtSocketsInitialized++) {
StartSockets();
}
if ((r = accept (TO_SOCKET(s), addr, addrlen)) == INVALID_SOCKET)
errno = WSAGetLastError();
- return r;
+ return my_open_osfhandle(r, O_RDWR|O_BINARY);
}
#undef bind
@@ -2076,7 +2074,7 @@ mybind (SOCKET s, struct sockaddr *addr, int addrlen)
if (!NtSocketsInitialized++) {
StartSockets();
}
- if ((r = bind (s, addr, addrlen)) == SOCKET_ERROR)
+ if ((r = bind (TO_SOCKET(s), addr, addrlen)) == SOCKET_ERROR)
errno = WSAGetLastError();
return r;
}
@@ -2090,7 +2088,7 @@ myconnect (SOCKET s, struct sockaddr *addr, int addrlen)
if (!NtSocketsInitialized++) {
StartSockets();
}
- if ((r = connect (s, addr, addrlen)) == SOCKET_ERROR)
+ if ((r = connect (TO_SOCKET(s), addr, addrlen)) == SOCKET_ERROR)
errno = WSAGetLastError();
return r;
}
@@ -2124,8 +2122,6 @@ mygetsockname (SOCKET s, struct sockaddr *addr, int *addrlen)
return r;
}
-#undef getsockopt
-
int
mygetsockopt (SOCKET s, int level, int optname, char *optval, int *optlen)
{
@@ -2133,7 +2129,7 @@ mygetsockopt (SOCKET s, int level, int optname, char *optval, int *optlen)
if (!NtSocketsInitialized++) {
StartSockets();
}
- if ((r = getsockopt (s, level, optname, optval, optlen)) == SOCKET_ERROR)
+ if ((r = getsockopt (TO_SOCKET(s), level, optname, optval, optlen)) == SOCKET_ERROR)
errno = WSAGetLastError();
return r;
}
@@ -2161,7 +2157,7 @@ mylisten (SOCKET s, int backlog)
if (!NtSocketsInitialized++) {
StartSockets();
}
- if ((r = listen (s, backlog)) == SOCKET_ERROR)
+ if ((r = listen (TO_SOCKET(s), backlog)) == SOCKET_ERROR)
errno = WSAGetLastError();
return r;
}
@@ -2233,7 +2229,7 @@ mysetsockopt (SOCKET s, int level, int optname, char *optval, int optlen)
if (!NtSocketsInitialized++) {
StartSockets();
}
- if ((r = setsockopt (s, level, optname, optval, optlen))
+ if ((r = setsockopt (TO_SOCKET(s), level, optname, optval, optlen))
== SOCKET_ERROR)
errno = WSAGetLastError();
return r;
@@ -2266,7 +2262,7 @@ mysocket (int af, int type, int protocol)
errno = WSAGetLastError();
//fprintf(stderr, "socket fail (%d)", WSAGetLastError());
}
- return s;
+ return my_open_osfhandle(s, O_RDWR|O_BINARY);
}
#undef gethostbyaddr
diff --git a/win32/win32.h b/win32/win32.h
index 2976781..ebffc5c 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -177,7 +177,7 @@ extern char *NtGetBin(void);
extern FILE *mypopen(char *, char *);
extern int mypclose(FILE *);
extern int flock(int fd, int oper);
-extern FILE * myfdopen(int, const char *);
+extern int myfddup(int);
extern void myfdclose(FILE *);
extern SOCKET myaccept(SOCKET, struct sockaddr *, int *);
extern int mybind(SOCKET, struct sockaddr *, int);
@@ -267,11 +267,6 @@ extern char *mystrerror(int);
/* #undef va_start */
/* #undef va_end */
-#ifdef fdopen
-#undef fdopen
-#endif
-#define fdopen myfdopen
-
#ifdef accept
#undef accept
#endif