なかだです。

At Wed, 15 Nov 2000 16:21:55 +0900
"Nobuyoshi.Nakada" <nobu.nakada / nifty.ne.jp> wrote:
>   てことは、myfdopen(), myfdclose() からして不要ということになりますが、
> ext/socket/socket.c を見るとどうも close() と closesocket() とで分けてる
> らしいので、#undef getsockopt を is_socket() の前に持ってきて、こうすれ
> ばいいのかもしれません。

  どうにも HANDLE と descritor が錯綜しててややこしいんですが、descritor 
だけ dup して HANDLE はしない、という方がよさそうな。


diff -pruPX ./.excludes current/ext/socket/socket.c devel/ext/socket/socket.c --- current/ext/socket/socket.c Wed Nov 8 14:29:35 2000 +++ devel/ext/socket/socket.c Wed Nov 15 18:41:13 2000 @@ -182,6 +182,7 @@ sock_new(class, fd) fp->f = rb_fdopen(fd, "r"); #ifdef NT fp->finalize = sock_finalize; + fd = myfddup(fd); #else fd = dup(fd); #endif diff -pruPX ./.excludes current/win32/win32.c devel/win32/win32.c --- current/win32/win32.c Tue Nov 14 16:10:31 2000 +++ devel/win32/win32.c Wed Nov 15 19:04:21 2000 @@ -1726,6 +1726,8 @@ my_open_osfhandle(long osfhandle, int fl 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, 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 *ad 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 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 o 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 o 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 -pruPX ./.excludes current/win32/win32.h devel/win32/win32.h --- current/win32/win32.h Tue Nov 14 16:10:31 2000 +++ devel/win32/win32.h Wed Nov 15 18:42:39 2000 @@ -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); @@ -266,11 +266,6 @@ extern char *mystrerror(int); /* #undef va_start */ /* #undef va_end */ - -#ifdef fdopen -#undef fdopen -#endif -#define fdopen myfdopen #ifdef accept #undef accept
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦