summaryrefslogtreecommitdiff
path: root/ext/socket/basicsocket.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-02 01:53:02 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-02 01:53:02 +0000
commitef9206bbea3b8cb1af66966e74fe8527edab2418 (patch)
tree6150f80801b0de3e46bf2e673e04bb05815850f6 /ext/socket/basicsocket.c
parenta2d8643e9313590e339933d296ff13d8d85f6b45 (diff)
* ext/socket/rubysocket.h (rb_cSockOpt): declared.
(sockopt_new): ditto. (Init_sockopt): ditto. * ext/socket/init.c (Init_socket_init): call Init_sockopt. * ext/socket/depend: add dependency for option.o * ext/socket/mkconstants.rb: generate intern_level, intern_so_optname, intern_ip_optname, intern_ipv6_optname, intern_tcp_optname, intern_udp_optname and intern_scm_optname. * ext/socket/extconf.rb: add option.o. * ext/socket/basicsocket.c (bsock_setsockopt): accept Socket::Option object. (bsock_getsockopt): return Socket::Option object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/basicsocket.c')
-rw-r--r--ext/socket/basicsocket.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index 4b8e946..a5c310a 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -192,14 +192,24 @@ bsock_close_write(VALUE sock)
*
*/
static VALUE
-bsock_setsockopt(VALUE sock, VALUE lev, VALUE optname, VALUE val)
+bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
{
+ VALUE lev, optname, val;
int level, option;
rb_io_t *fptr;
int i;
char *v;
int vlen;
+ if (argc == 1) {
+ lev = rb_funcall(argv[0], rb_intern("level"), 0);
+ optname = rb_funcall(argv[0], rb_intern("optname"), 0);
+ val = rb_funcall(argv[0], rb_intern("data"), 0);
+ }
+ else {
+ rb_scan_args(argc, argv, "30", &lev, &optname, &val);
+ }
+
rb_secure(2);
level = level_arg(lev);
option = optname_arg(level, optname);
@@ -290,7 +300,7 @@ bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
if (getsockopt(fptr->fd, level, option, buf, &len) < 0)
rb_sys_fail_path(fptr->pathv);
- return rb_str_new(buf, len);
+ return sockopt_new(level, option, rb_str_new(buf, len));
#else
rb_notimplement();
#endif
@@ -626,7 +636,7 @@ Init_basicsocket(void)
rb_define_method(rb_cBasicSocket, "close_read", bsock_close_read, 0);
rb_define_method(rb_cBasicSocket, "close_write", bsock_close_write, 0);
rb_define_method(rb_cBasicSocket, "shutdown", bsock_shutdown, -1);
- rb_define_method(rb_cBasicSocket, "setsockopt", bsock_setsockopt, 3);
+ rb_define_method(rb_cBasicSocket, "setsockopt", bsock_setsockopt, -1);
rb_define_method(rb_cBasicSocket, "getsockopt", bsock_getsockopt, 2);
rb_define_method(rb_cBasicSocket, "getsockname", bsock_getsockname, 0);
rb_define_method(rb_cBasicSocket, "getpeername", bsock_getpeername, 0);