summaryrefslogtreecommitdiff
path: root/ext/socket/ancdata.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-04 20:50:08 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-04 20:50:08 +0000
commitc46754730133f3e12efd3a899fc00d14217ba866 (patch)
treec378a016ca9eeffdce7041e844fc04fea0de81ec /ext/socket/ancdata.c
parent99ee18afcb50e454f00ea1ea85c14a2387ed101c (diff)
ext/socket/ancdata.c (bsock_sendmsg_internal): use rb_scan_args
This should make the code more maintainable and make it easier to add keyword argument support for "exception: false" in the future. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/ancdata.c')
-rw-r--r--ext/socket/ancdata.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index ef6a870..277a1e8 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -1131,12 +1131,11 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
{
rb_io_t *fptr;
VALUE data, vflags, dest_sockaddr;
- int controls_num;
struct msghdr mh;
struct iovec iov;
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
+ VALUE controls = Qnil;
VALUE controls_str = 0;
- VALUE *controls_ptr = NULL;
int family;
#endif
int flags;
@@ -1151,20 +1150,20 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
if (argc == 0)
rb_raise(rb_eArgError, "mesg argument required");
- data = argv[0];
- if (1 < argc) vflags = argv[1];
- if (2 < argc) dest_sockaddr = argv[2];
- controls_num = 3 < argc ? argc - 3 : 0;
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
- if (3 < argc) { controls_ptr = &argv[3]; }
+ rb_scan_args(argc, argv, "12*", &data, &vflags, &dest_sockaddr, &controls);
+#else
+ rb_scan_args(argc, argv, "12", &data, &vflags, &dest_sockaddr);
#endif
StringValue(data);
- if (controls_num) {
+ if (!NIL_P(controls)) {
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
int i;
+ int controls_num = RARRAY_LENINT(controls);
size_t last_pad = 0;
+ const VALUE *controls_ptr = RARRAY_CONST_PTR(controls);
#if defined(__NetBSD__)
int last_level = 0;
int last_type = 0;
@@ -1239,6 +1238,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
rb_str_set_len(controls_str, RSTRING_LEN(controls_str)-last_pad);
#endif
}
+ RB_GC_GUARD(controls);
#else
rb_raise(rb_eNotImpError, "control message for sendmsg is unimplemented");
#endif