[#6728] Ruby 1.3.3-990507 — matz <matz@...>

Ruby 1.3.3-990507 is out, check out:

34 messages 1999/05/07
[#6731] Re: Ruby 1.3.3-990507 — Katsuyuki Komatsu <komatsu@...> 1999/05/07

小松です。

[#6779] Re: private inner class (Re: Re: class def in class def) — Koji Oda <oda@...1.qnes.nec.co.jp>

小田@QNES です。

13 messages 1999/05/13

[#6789] Ruby 1.3.3-990513 — Yukihiro Matsumoto <matz@...>

Ruby 1.3.3-990513 is out, check out:

59 messages 1999/05/13
[#6811] Re: Ruby 1.3.3-990513 — Koji Oda <oda@...1.qnes.nec.co.jp> 1999/05/14

小田@QNES です。

[#6814] Re: Ruby 1.3.3-990513 — matz@... (Yukihiro Matsumoto) 1999/05/15

まつもと ゆきひろです

[#6821] Re: Ruby 1.3.3-990513 — Koji Oda <oda@...1.qnes.nec.co.jp> 1999/05/16

小田@QNES です。

[#6790] Re: Ruby 1.3.3-990513 — Katsuyuki Komatsu <komatsu@...> 1999/05/13

小松です。

[#6891] Ruby 1.3.3-990518 — Yukihiro Matsumoto <matz@...>

Ruby 1.3.3-990518 is out, check out:

19 messages 1999/05/18

[#6919] ext/socket/getaddrinfo.c tiny fix — Jun-ichiro itojun Hagino <itojun@...>

ext/socket/getaddrinfo.cに以下のpatchをおねがいします。

22 messages 1999/05/20
[#6921] Re: ext/socket/getaddrinfo.c tiny fix — Jun-ichiro itojun Hagino <itojun@...> 1999/05/20

[#7034] Ruby 1.3.4-990531 — Yukihiro Matsumoto <matz@...>

Ruby 1.3.4-990531 is out, check out:

25 messages 1999/05/31

[ruby-dev:7011] Re: socket for rubymw

From: Koji Oda <oda@...1.qnes.nec.co.jp>
Date: 1999-05-28 04:21:40 UTC
List: ruby-dev #7011
小田@QNES です。

やっとruby-1.3.3-990518用のパッチ出来ました。
参考パッチありがとうございました。> 助田さん

以下のパッチで、rubymw でsocketが、とりあえず動くようになりました。
ftplib は動くのを確認しました。

socket.dll を作って動作確認をしましたが、win32/Makefile
では、socket.lib がmakeされません。
何が問題なのかを調べるにはどうしたら良いですか?

--- rubysig.h.org Tue May 25 17:53:12 1999
+++ rubysig.h     Tue Apr 20 17:41:55 1999
@@ -10,7 +10,7 @@
 #ifndef SIG_H
 #define SIG_H

-EXTERN int rb_trap_immediate;
+extern int rb_trap_immediate;
 #define TRAP_BEG (rb_trap_immediate=1)
 #define TRAP_END (rb_trap_immediate=0)
--- win32/ruby.def.org  Tue Apr 20 17:41:57 1999
+++ win32/ruby.def      Fri May 28 12:03:00 1999
@@ -35,6 +35,7 @@
 	ruby_unsetenv
 ;io.c:
 	rb_cIO
+	rb_io_check_closed
 ;numeric.c:
 	rb_cNumeric
 	rb_cFloat
@@ -52,6 +53,8 @@
 	rb_cFalseClass
 ;re.c:
 	rb_cRegexp
+;signal.c
+	rb_trap_immediate
 ;string.c:
 	rb_cString
 	rb_cStruct
@@ -60,6 +63,7 @@
 ;missing/nt.c
 	NtInitialize
 	myfdopen
+	myfdclose
 	myaccept
 	mybind
 	myconnect
@@ -82,10 +86,11 @@
 	mygetprotobynumber
 	mygetservbyname
 	mygetservbyport
+	myget_osfhandle
 ;array.c
 	rb_ary_freeze
-	rb_ary_new2
 	rb_ary_new
+	rb_ary_new2
 	rb_ary_new3
 	rb_ary_new4
 	rb_assoc_new
@@ -118,6 +123,7 @@
 	rb_uint2inum
 	rb_int2inum
 	rb_str2inum
+	rb_str2cstr
 	rb_big2str
 	rb_big2ulong
 	rb_big2long
@@ -236,6 +242,7 @@
 	rb_thread_scope_shared_p
 	rb_thread_interrupt
 	rb_thread_trap_eval
+	rb_thread_fd_close
 	rb_catch
 	rb_throw
 	rb_yield
@@ -293,6 +300,7 @@
 	rb_obj_is_instance_of
 	rb_obj_is_kind_of
 	rb_obj_alloc
+	rb_obj_taint
 	rb_to_id
 	rb_class_of
 	rb_type
@@ -334,6 +342,8 @@
 	rb_get_kcode
 	rb_set_kcode
 ; ruby.c
+	rb_argv
+	rb_progname
 	ruby_require_modules
 	rb_load_file
 	ruby_script
--- win32/win32.h.org   Thu May 06 11:50:57 1999
+++ win32/win32.h       Tue May 25 11:43:51 1999
@@ -85,6 +85,11 @@
 #undef except
 #undef finally
 #undef leave
+
+#if defined(__cplusplus)
+}
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -94,6 +99,12 @@
 #include <math.h>
 #include <sys/types.h>
 #include <sys/utime.h>
+#include <io.h>
+#include <malloc.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif

 #define UIDTYPE int
 #define GIDTYPE int
@@ -150,16 +161,17 @@
 #define pclose     _pclose
 #define strcasecmp _stricmp
 #define strncasecmp _strnicmp
-
 /* these are defined in nt.c */

 extern int NtMakeCmdVector(char *, char ***, int);
-/* extern void NtInitialize(int *, char ***); */
+extern void NtInitialize(int *, char ***);
 extern char *NtGetLib(void);
 extern char *NtGetBin(void);
 extern FILE *mypopen(char *, char *);
+extern int   mypclose(FILE *);
 extern int  flock(int fd, int oper);
-extern FILE *  myfdopen(int, char*);
+extern FILE *  myfdopen(int, const char *);
+extern void  myfdclose(FILE *);
 extern SOCKET  myaccept(SOCKET, struct sockaddr *, int *);
 extern int  mybind(SOCKET, struct sockaddr *, int);
 extern int  myconnect(SOCKET, struct sockaddr *, int);
@@ -175,6 +187,7 @@
 extern int  mysetsockopt(SOCKET, int, int, char *, int);
 extern int  myshutdown(SOCKET, int);
 extern SOCKET  mysocket(int, int, int);
+extern SOCKET  myget_osfhandle(int);
 extern struct hostent *  mygethostbyaddr(char *, int, int);
 extern struct hostent *  mygethostbyname(char *);
 extern int  mygethostname(char *, int);
@@ -183,6 +196,16 @@
 extern struct servent *  mygetservbyname(char *, char *);
 extern struct servent * mygetservbyport(int, char *);

+extern int chown(const char *, int, int);
+extern int link(char *, char *);
+extern int gettimeofday(struct timeval *, struct timezone *);
+extern pid_t waitpid (pid_t, int *, int);
+extern int do_spawn(char *);
+extern int kill(int, int);
+extern int isinf(double);
+extern int isnan(double);
+
+
 //
 // define this so we can do inplace editing
 //
@@ -345,4 +368,9 @@
 #undef getservbyport
 #endif
 #define getservbyport mygetservbyport
+
+#ifdef get_osfhandle
+#undef get_osfhandle
+#endif
+#define get_osfhandle myget_osfhandle
 #endif
--- win32/win32.c.org	Tue Apr 20 17:41:57 1999
+++ win32/win32.c	Thu May 27 17:16:29 1999
@@ -33,6 +33,8 @@
 #define bool int
 #endif
 
+#define TO_SOCKET(x)	_get_osfhandle(x)
+
 bool NtSyncProcess = TRUE;
 #if 0  // declared in header file
 extern char **environ;
@@ -302,6 +304,14 @@
 }
 
 
+SOCKET
+myget_osfhandle(int fh)
+{
+    return _get_osfhandle(fh);
+
+}
+
+
 FILE *
 mypopen (char *cmd, char *mode) 
 {
@@ -1582,17 +1592,79 @@
 // if we can prevent perl from trying to do stdio on sockets.
 //
 
+EXTERN_C int __cdecl _alloc_osfhnd(void);
+EXTERN_C int __cdecl _set_osfhnd(int fh, long value);
+EXTERN_C void __cdecl _lock_fhandle(int);
+EXTERN_C void __cdecl _unlock_fhandle(int);
+EXTERN_C void __cdecl _unlock(int);
+
+typedef struct	{
+    long osfhnd;    /* underlying OS file HANDLE */
+    char osfile;    /* attributes of file (e.g., open in text mode?) */
+    char pipech;    /* one char buffer for handles opened on pipes */
+#if defined (_MT) && !defined (DLL_FOR_WIN32S)
+    int lockinitflag;
+    CRITICAL_SECTION lock;
+#endif  /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
+}	ioinfo;
+
+EXTERN_C ioinfo * __pioinfo[];
+
+#define IOINFO_L2E			5
+#define IOINFO_ARRAY_ELTS	(1 << IOINFO_L2E)
+#define _pioinfo(i)	(__pioinfo[i >> IOINFO_L2E] + (i & (IOINFO_ARRAY_ELTS - 1)))
+#define _osfile(i)	(_pioinfo(i)->osfile)
+
+#define FOPEN			0x01	/* file handle open */
+#define FAPPEND			0x20	/* file handle opened O_APPEND */
+#define FDEV			0x40	/* file handle refers to device */
+#define FTEXT			0x80	/* file handle is in text mode */
+
+static int
+my_open_osfhandle(long osfhandle, int flags)
+{
+    int fh;
+    char fileflags;		/* _osfile flags */
+
+    /* copy relevant flags from second parameter */
+    fileflags = FDEV;
+
+    if (flags & O_APPEND)
+	fileflags |= FAPPEND;
+
+    if (flags & O_TEXT)
+	fileflags |= FTEXT;
+
+    /* attempt to allocate a C Runtime file handle */
+    if ((fh = _alloc_osfhnd()) == -1) {
+	errno = EMFILE;		/* too many open files */
+	_doserrno = 0L;		/* not an OS error */
+	return -1;		/* return error to caller */
+    }
+
+    /* the file is open. now, set the info in _osfhnd array */
+    _set_osfhnd(fh, osfhandle);
+
+    fileflags |= FOPEN;		/* mark as open */
+
+    _osfile(fh) = fileflags;	/* set osfile entry */
+//    _unlock_fhandle(fh);
+
+    return fh;			/* return handle */
+}
+
 FILE *
 myfdopen (int fd, const char *mode)
 {
-    FILE *fp;
     char sockbuf[80];
     int optlen;
     int retval;
+    int fh;
     extern int errno;
 
     //fprintf(stderr, "myfdopen()\n");
 
+	optlen = sizeof(sockbuf);
     retval = getsockopt((SOCKET)fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
     if (retval == SOCKET_ERROR) {
 	int iRet;
@@ -1605,17 +1677,16 @@
     //
     // If we get here, then fd is actually a socket.
     //
-    fp = xcalloc(sizeof(FILE), 1);
-#if _MSC_VER < 800
-    fileno(fp) = fd;
-#else
-    fp->_file = fd;
-#endif
-    if (*mode == 'r')
-	fp->_flag = _IOREAD;
-    else
-	fp->_flag = _IOWRT;
-    return fp;
+
+	fh = my_open_osfhandle((SOCKET)fd, O_RDWR|O_BINARY);
+    return _fdopen(fh, mode);		// return file pointer
+}
+
+
+void
+myfdclose(FILE *fp)
+{
+	fclose(fp);
 }
 
 
@@ -1737,6 +1808,7 @@
     WORD version;
     WSADATA retdata;
     int ret;
+	int iSockOpt;
     
     //
     // initalize the winsock interface and insure that it\'s
@@ -1752,6 +1824,13 @@
         rb_fatal("could not find version 1 of winsock dll\n");
 
     atexit((void (*)(void)) WSACleanup);
+
+	iSockOpt = SO_SYNCHRONOUS_NONALERT;
+    /*
+     * Enable the use of sockets as filehandles
+     */
+    setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
+		(char *)&iSockOpt, sizeof(iSockOpt));
 }
 
 #undef accept
@@ -1764,7 +1843,7 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = accept (s, addr, addrlen)) == INVALID_SOCKET)
+    if ((r = accept (TO_SOCKET(s), addr, addrlen)) == INVALID_SOCKET)
 	errno = WSAGetLastError();
     return r;
 }
@@ -1808,7 +1887,7 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = getpeername (s, addr, addrlen)) == SOCKET_ERROR)
+    if ((r = getpeername (TO_SOCKET(s), addr, addrlen)) == SOCKET_ERROR)
 	errno = WSAGetLastError();
     return r;
 }
@@ -1822,7 +1901,7 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = getsockname (s, addr, addrlen)) == SOCKET_ERROR)
+    if ((r = getsockname (TO_SOCKET(s), addr, addrlen)) == SOCKET_ERROR)
 	errno = WSAGetLastError();
     return r;
 }
@@ -1850,7 +1929,7 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = ioctlsocket (s, cmd, argp)) == SOCKET_ERROR)
+    if ((r = ioctlsocket (TO_SOCKET(s), cmd, argp)) == SOCKET_ERROR)
 	errno = WSAGetLastError();
     return r;
 }
@@ -1878,7 +1957,7 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = recv (s, buf, len, flags)) == SOCKET_ERROR)
+    if ((r = recv (TO_SOCKET(s), buf, len, flags)) == SOCKET_ERROR)
 	errno = WSAGetLastError();
     return r;
 }
@@ -1893,7 +1972,7 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = recvfrom (s, buf, len, flags, from, fromlen)) == SOCKET_ERROR)
+    if ((r = recvfrom (TO_SOCKET(s), buf, len, flags, from, fromlen)) == SOCKET_ERROR)
 	errno =  WSAGetLastError();
     return r;
 }
@@ -1907,7 +1986,7 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = send (s, buf, len, flags)) == SOCKET_ERROR)
+    if ((r = send (TO_SOCKET(s), buf, len, flags)) == SOCKET_ERROR)
 	errno = WSAGetLastError();
     return r;
 }
@@ -1922,7 +2001,7 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = sendto (s, buf, len, flags, to, tolen)) == SOCKET_ERROR)
+    if ((r = sendto (TO_SOCKET(s), buf, len, flags, to, tolen)) == SOCKET_ERROR)
 	errno = WSAGetLastError();
     return r;
 }
@@ -1936,7 +2015,8 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = setsockopt (s, level, optname, optval, optlen)) == SOCKET_ERROR)
+    if ((r = setsockopt (s, level, optname, optval, optlen))
+    		 == SOCKET_ERROR)
 	errno = WSAGetLastError();
     return r;
 }
@@ -1950,7 +2030,7 @@
     if (!NtSocketsInitialized++) {
 	StartSockets();
     }
-    if ((r = shutdown (s, how)) == SOCKET_ERROR)
+    if ((r = shutdown (TO_SOCKET(s), how)) == SOCKET_ERROR)
 	errno = WSAGetLastError();
     return r;
 }
@@ -2120,7 +2200,7 @@
 
 #include <sys/timeb.h>
 
-void _cdecl
+int _cdecl
 gettimeofday(struct timeval *tv, struct timezone *tz)
 {                                
     struct timeb tb;
@@ -2128,6 +2208,8 @@
     ftime(&tb);
     tv->tv_sec = tb.time;
     tv->tv_usec = tb.millitm * 1000;
+
+	return 0;
 }
 
 char *
@@ -2170,16 +2252,17 @@
 }
 
 int
-chown(char *path, int owner, int group)
+chown(const char *path, int owner, int group)
 {
 	return 0;
 }
 
+#include <signal.h>
 int
 kill(int pid, int sig)
 {
 #if 1
-	if (pid == GetCurrentProcessId())
+	if ((unsigned int)pid == GetCurrentProcessId())
 		return raise(sig);
 
 	if (sig == 2 && pid > 0)
--- ext/socket/addrinfo.h.org	Sat May 15 09:55:46 1999
+++ ext/socket/addrinfo.h	Thu May 27 14:25:39 1999
@@ -124,6 +124,11 @@
 #define	NI_NAMEREQD	0x00000004
 #define	NI_NUMERICSERV	0x00000008
 #define	NI_DGRAM	0x00000010
+
+#ifdef NT
+#define IN_EXPERIMENTAL(x) 0
+#define IN_LOOPBACKNET 0
+#endif
 
 struct addrinfo {
 	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME */
--- ext/socket/getaddrinfo.c.org	Sat May 08 00:34:36 1999
+++ ext/socket/getaddrinfo.c	Thu May 27 14:24:39 1999
@@ -39,22 +39,28 @@
  */
 
 #include <sys/types.h>
+#ifndef NT
 #include <sys/param.h>
+#endif
 #ifdef HAVE_SYSCTL_H
 #include <sys/sysctl.h>
 #endif
+#ifndef NT
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 #include <netdb.h>
 #include <resolv.h>
+#include <unistd.h>
+#else
+#include <winsock2.h>
+#endif
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
 #include <ctype.h>
-#include <unistd.h>
 
 #include "config.h"
 #include "addrinfo.h"
@@ -352,7 +358,7 @@
 				pai->ai_socktype = SOCK_DGRAM;
 				pai->ai_protocol = IPPROTO_UDP;
 			}
-			port = htons(atoi(servname));
+			port = htons((unsigned short)atoi(servname));
 		} else {
 			struct servent *sp;
 			char *proto;
@@ -548,8 +554,10 @@
 	int i, error = 0, h_error;
 	char *ap;
 #ifndef INET6
+#ifndef NT
 	extern int h_errno;
 #endif
+#endif
 
 	top = NULL;
 	sentinel.ai_next = NULL;
--- ext/socket/getnameinfo.c.org	Fri May 14 18:17:45 1999
+++ ext/socket/getnameinfo.c	Thu May 27 14:20:28 1999
@@ -35,12 +35,20 @@
  */
 
 #include <sys/types.h>
+#ifndef NT
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 #include <netdb.h>
 #include <resolv.h>
+#endif
+#ifdef NT
+#include <winsock2.h>
+#include <stdio.h>
+#define snprintf _snprintf
+#endif
+
 #include <string.h>
 #include <stddef.h>
 
@@ -125,7 +133,9 @@
 	int h_error;
 	char numserv[512];
 	char numaddr[512];
+#ifndef NT
 	extern int h_errno;
+#endif
 
 	if (sa == NULL)
 		return ENI_NOSOCKET;
--- ext/socket/socket.c.org	Tue May 11 10:34:33 1999
+++ ext/socket/socket.c	Fri May 28 11:54:54 1999
@@ -78,12 +78,16 @@
     OpenFile *fptr;
 {
     SOCKET s;
+	extern int errno;
 
     if (!fptr->f) return;
-    s = fileno(fptr->f);
-    free(fptr->f);
-    if (fptr->f2) free(fptr->f2);
+
+	myfdclose(fptr->f);
+	if(fptr->f2)  myfdclose(fptr->f);
+/*
+	s = get_osfhandle(fileno(fptr->f));
     closesocket(s);
+*/
 }
 #endif
 

In This Thread