1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ruby.c (proc_options): removed "-*-" support for #! line.

* io.c (rb_io_s_sysopen): new method to get a raw file
  descriptor. [new]

* ext/socket/socket.c (tcp_sysaccept): new method to return an
  accepted socket fd (integer). [new]

* ext/socket/socket.c (unix_sysaccept,sock_sysaccept): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-05-23 05:35:32 +00:00
parent 730d8f1d32
commit 6e87a54aec
7 changed files with 109 additions and 16 deletions

View file

@ -1,3 +1,15 @@
Thu May 23 09:13:56 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* ruby.c (proc_options): removed "-*-" support for #! line.
* io.c (rb_io_s_sysopen): new method to get a raw file
descriptor. [new]
* ext/socket/socket.c (tcp_sysaccept): new method to return an
accepted socket fd (integer). [new]
* ext/socket/socket.c (unix_sysaccept,sock_sysaccept): ditto.
Wed May 22 21:26:47 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* ruby.c (proc_options): -T consumes digits only.

View file

@ -1,3 +1,11 @@
: IO::sysopen
a new method to get a raw file descriptor.
: TCPServer#accept, UNIXServer#accept, Socket#accept
new methods to return an accepted socket fd.
: Date and DateTime
lib/date.rb now provides both Date and DateTime.

View file

@ -1134,6 +1134,7 @@ s_accept(klass, fd, sockaddr, len)
}
rb_sys_fail(0);
}
if (!klass) return INT2NUM(fd2);
return init_sock(rb_obj_alloc(klass), fd2);
}
@ -1151,6 +1152,19 @@ tcp_accept(sock)
(struct sockaddr*)&from, &fromlen);
}
static VALUE
tcp_sysaccept(sock)
VALUE sock;
{
OpenFile *fptr;
struct sockaddr_storage from;
socklen_t fromlen;
GetOpenFile(sock, fptr);
fromlen = sizeof(from);
return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
}
#ifdef HAVE_SYS_UN_H
static VALUE
init_unixsock(sock, path, server)
@ -1574,6 +1588,19 @@ unix_accept(sock)
(struct sockaddr*)&from, &fromlen);
}
static VALUE
unix_sysaccept(sock)
VALUE sock;
{
OpenFile *fptr;
struct sockaddr_un from;
socklen_t fromlen;
GetOpenFile(sock, fptr);
fromlen = sizeof(struct sockaddr_un);
return s_accept(0, fileno(fptr->f), (struct sockaddr*)&from, &fromlen);
}
static VALUE
unixaddr(sockaddr)
struct sockaddr_un *sockaddr;
@ -1836,6 +1863,21 @@ sock_accept(sock)
return rb_assoc_new(sock2, rb_tainted_str_new(buf, len));
}
static VALUE
sock_sysaccept(sock)
VALUE sock;
{
OpenFile *fptr;
VALUE sock2;
char buf[1024];
socklen_t len = sizeof buf;
GetOpenFile(sock, fptr);
sock2 = s_accept(0,fileno(fptr->f),(struct sockaddr*)buf,&len);
return rb_assoc_new(sock2, rb_tainted_str_new(buf, len));
}
#ifdef HAVE_GETHOSTNAME
static VALUE
sock_gethostname(obj)
@ -2322,6 +2364,7 @@ Init_socket()
rb_cTCPServer = rb_define_class("TCPServer", rb_cTCPSocket);
rb_define_global_const("TCPserver", rb_cTCPServer);
rb_define_method(rb_cTCPServer, "accept", tcp_accept, 0);
rb_define_method(rb_cTCPServer, "sysaccept", tcp_sysaccept, 0);
rb_define_method(rb_cTCPServer, "initialize", tcp_svr_init, -1);
rb_define_method(rb_cTCPServer, "listen", sock_listen, 1);
@ -2349,6 +2392,7 @@ Init_socket()
rb_define_global_const("UNIXserver", rb_cUNIXServer);
rb_define_method(rb_cUNIXServer, "initialize", unix_svr_init, 1);
rb_define_method(rb_cUNIXServer, "accept", unix_accept, 0);
rb_define_method(rb_cUNIXServer, "sysaccept", unix_sysaccept, 0);
rb_define_method(rb_cUNIXServer, "listen", sock_listen, 1);
#endif
@ -2359,6 +2403,7 @@ Init_socket()
rb_define_method(rb_cSocket, "bind", sock_bind, 1);
rb_define_method(rb_cSocket, "listen", sock_listen, 1);
rb_define_method(rb_cSocket, "accept", sock_accept, 0);
rb_define_method(rb_cSocket, "sysaccept", sock_sysaccept, 0);
rb_define_method(rb_cSocket, "recvfrom", sock_recvfrom, -1);

30
io.c
View file

@ -1966,7 +1966,7 @@ rb_open_file(argc, argv, io)
VALUE *argv;
VALUE io;
{
VALUE fname, vmode, file, perm;
VALUE fname, vmode, perm;
char *path, *mode;
int flags, fmode;
@ -1978,11 +1978,11 @@ rb_open_file(argc, argv, io)
flags = FIXNUM_P(vmode) ? NUM2INT(vmode) : rb_io_mode_modenum(StringValuePtr(vmode));
fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
file = rb_file_sysopen_internal(io, path, flags, fmode);
rb_file_sysopen_internal(io, path, flags, fmode);
}
else {
mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode);
file = rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
}
return io;
}
@ -2002,6 +2002,29 @@ rb_io_s_open(argc, argv, klass)
return io;
}
static VALUE
rb_io_s_sysopen(argc, argv)
int argc;
VALUE *argv;
{
VALUE fname, vmode, perm;
int flags, fmode, fd;
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
SafeStringValue(fname);
if (NIL_P(vmode)) flags = O_RDONLY;
else if (FIXNUM_P(vmode)) flags = NUM2INT(vmode);
else {
flags = rb_io_mode_modenum(StringValuePtr(vmode));
}
if (NIL_P(perm)) fmode = 0666;
else fmode = NUM2INT(perm);
fd = rb_sysopen(RSTRING(fname)->ptr, flags, fmode);
return INT2NUM(fd);
}
static VALUE
rb_f_open(argc, argv)
int argc;
@ -3706,6 +3729,7 @@ Init_IO()
rb_define_singleton_method(rb_cIO, "allocate", rb_io_s_alloc, 0);
rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1);
rb_define_singleton_method(rb_cIO, "open", rb_io_s_open, -1);
rb_define_singleton_method(rb_cIO, "sysopen", rb_io_s_sysopen, -1);
rb_define_singleton_method(rb_cIO, "for_fd", rb_class_new_instance, -1);
rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1);

View file

@ -781,9 +781,10 @@ An end of a defun is found by moving forward from the beginning of one."
'(lambda ()
(make-local-variable 'font-lock-defaults)
(make-local-variable 'font-lock-keywords)
(make-local-variable 'font-lock-syntactic-keywords)
(make-local-variable 'font-lock-syntax-table)
(setq font-lock-defaults '((ruby-font-lock-keywords) nil nil))
(setq font-lock-keywords ruby-font-lock-keywords)
(setq font-lock-syntax-table ruby-font-lock-syntax-table)
(setq font-lock-syntactic-keywords ruby-font-lock-syntactic-keywords)))))
(defun ruby-font-lock-docs (limit)
@ -812,6 +813,11 @@ An end of a defun is found by moving forward from the beginning of one."
t)
nil)))
(defvar ruby-font-lock-syntax-table
(let* ((tbl (copy-syntax-table ruby-mode-syntax-table)))
(modify-syntax-entry ?_ "w" tbl)
tbl))
(defvar ruby-font-lock-keywords
(list
(cons (concat
@ -855,10 +861,10 @@ An end of a defun is found by moving forward from the beginning of one."
"yield"
)
"\\|")
"\\)\\>\\([^_]\\|$\\)")
"\\)\\>")
2)
;; variables
'("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\b\\([^_]\\|$\\)"
'("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>"
2 font-lock-variable-name-face)
;; variables
'("\\(\\$\\([^a-zA-Z0-9 \n]\\|[0-9]\\)\\)\\W"

14
ruby.c
View file

@ -561,6 +561,7 @@ proc_options(argc, argv)
s += numlen;
}
rb_set_safe_level(v);
s += numlen;
}
goto reswitch;
@ -572,7 +573,7 @@ proc_options(argc, argv)
ruby_incpush(argv[1]);
argc--,argv++;
}
break;
goto reswitch;
case '0':
{
@ -624,11 +625,6 @@ proc_options(argc, argv)
}
break;
case '*':
case ' ':
if (s[1] == '-') s+=2;
break;
default:
fprintf(stderr, "%s: invalid option -%c (-h will show valid options)\n",
origargv[0], *s);
@ -657,10 +653,12 @@ proc_options(argc, argv)
}
else {
while (s && *s) {
while (ISSPACE(*s)) s++;
if (*s == '-') {
s++;
if (ISSPACE(*s)) continue;
if (ISSPACE(*s)) {
do {s++;} while (ISSPACE(*s));
continue;
}
}
if (!*s) break;
if (!strchr("IdvwrK", *s))

View file

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.2"
#define RUBY_RELEASE_DATE "2002-05-22"
#define RUBY_RELEASE_DATE "2002-05-23"
#define RUBY_VERSION_CODE 172
#define RUBY_RELEASE_CODE 20020522
#define RUBY_RELEASE_CODE 20020523