summaryrefslogtreecommitdiff
path: root/ext/socket/socket.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-06 15:31:26 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-06 15:31:26 +0000
commitaa92750f27e519c225d9bb50e59ed063857e0c04 (patch)
treeb52c2b9114e9af08bd0805ef2ff52988fe2976bf /ext/socket/socket.c
parent2cefbe9fb2297147c034086ff3b1b2dd9a9f5545 (diff)
* process.c (proc_setgroups): [ruby-dev:25081]
* re.c (rb_reg_eqq): document fix. [ruby-talk:122541] * io.c (io_fread): take VALUE argument. * ext/socket/socket.c (sock_connect): use rb_str_new4(). [ruby-dev:25052] * eval.c (rb_yield_0): [ruby-dev:25051] * io.c (io_write): remove rb_str_locktmp(). [ruby-dev:25050] * io.c (io_fwrite): takes VALUE string as an argument. [ruby-dev:25050] * ext/socket/socket.c (sock_connect): remove rb_str_locktmp(). [ruby-dev:25050] * ext/socket/socket.c (udp_connect): [ruby-dev:25045] * ext/socket/socket.c (udp_bind): ditto. * ext/socket/socket.c (udp_send): ditto. * ext/socket/socket.c (bsock_send): ditto. * ext/socket/socket.c (s_recvfrom): ditto. * hash.c (rb_hash_hash): should provide "hash" method where "eql?" is redefined. [ruby-talk:122482] * ext/socket/socket.c (bsock_setsockopt): [ruby-dev:25039] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r--ext/socket/socket.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index de49c7398c6..9f8e7478417 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -285,7 +285,6 @@ bsock_setsockopt(sock, lev, optname, val)
rb_secure(2);
level = NUM2INT(lev);
option = NUM2INT(optname);
- GetOpenFile(sock, fptr);
switch (TYPE(val)) {
case T_FIXNUM:
@@ -306,6 +305,7 @@ bsock_setsockopt(sock, lev, optname, val)
break;
}
+ GetOpenFile(sock, fptr);
if (setsockopt(fptr->fd, level, option, v, vlen) < 0)
rb_sys_fail(fptr->path);
@@ -379,13 +379,13 @@ bsock_send(argc, argv, sock)
rb_secure(4);
rb_scan_args(argc, argv, "21", &mesg, &flags, &to);
+ StringValue(mesg);
+ if (!NIL_P(to)) StringValue(to);
GetOpenFile(sock, fptr);
fd = fptr->fd;
rb_thread_fd_writable(fd);
- StringValue(mesg);
retry:
if (!NIL_P(to)) {
- StringValue(to);
n = sendto(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
(struct sockaddr*)RSTRING(to)->ptr, RSTRING(to)->len);
}
@@ -461,6 +461,7 @@ s_recvfrom(sock, argc, argv, from)
if (flg == Qnil) flags = 0;
else flags = NUM2INT(flg);
+ buflen = NUM2INT(len);
GetOpenFile(sock, fptr);
if (rb_io_read_pending(fptr)) {
@@ -468,16 +469,17 @@ s_recvfrom(sock, argc, argv, from)
}
fd = fptr->fd;
- buflen = NUM2INT(len);
str = rb_tainted_str_new(0, buflen);
retry:
- rb_str_locktmp(str);
rb_thread_wait_fd(fd);
+ rb_io_check_closed(fptr);
+ if (RSTRING(str)->len != buflen) {
+ rb_raise(rb_eRuntimeError, "buffer string modified");
+ }
TRAP_BEG;
slen = recvfrom(fd, RSTRING(str)->ptr, buflen, flags, (struct sockaddr*)buf, &alen);
TRAP_END;
- rb_str_unlocktmp(str);
if (slen < 0) {
if (rb_io_wait_readable(fd)) {
@@ -1459,8 +1461,8 @@ udp_connect(sock, host, port)
VALUE ret;
rb_secure(3);
- GetOpenFile(sock, fptr);
arg.res = sock_addrinfo(host, port, SOCK_DGRAM, 0);
+ GetOpenFile(sock, fptr);
arg.fd = fptr->fd;
ret = rb_ensure(udp_connect_internal, (VALUE)&arg,
RUBY_METHOD_FUNC(freeaddrinfo), (VALUE)arg.res);
@@ -1476,8 +1478,8 @@ udp_bind(sock, host, port)
struct addrinfo *res0, *res;
rb_secure(3);
- GetOpenFile(sock, fptr);
res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0);
+ GetOpenFile(sock, fptr);
for (res = res0; res; res = res->ai_next) {
if (bind(fptr->fd, res->ai_addr, res->ai_addrlen) < 0) {
continue;
@@ -1507,9 +1509,9 @@ udp_send(argc, argv, sock)
rb_secure(4);
rb_scan_args(argc, argv, "4", &mesg, &flags, &host, &port);
- GetOpenFile(sock, fptr);
- res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0);
StringValue(mesg);
+ res0 = sock_addrinfo(host, port, SOCK_DGRAM, 0);
+ GetOpenFile(sock, fptr);
for (res = res0; res; res = res->ai_next) {
retry:
n = sendto(fptr->fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
@@ -1979,13 +1981,13 @@ sock_connect(sock, addr)
{
OpenFile *fptr;
int fd, n;
+ volatile VALUE tmpaddr;
StringValue(addr);
+ addr = rb_str_new4(addr);
GetOpenFile(sock, fptr);
fd = fptr->fd;
- rb_str_locktmp(addr);
n = ruby_connect(fd, (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len, 0);
- rb_str_unlocktmp(addr);
if (n < 0) {
rb_sys_fail("connect(2)");
}