* ext/socket/mkconstants.rb: add valp argument for family_to_int and
socktype_to_int. * ext/socket/socket.c (setup_domain_and_type): use valp argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
175561f8dd
commit
10bc6f8d49
@ -1,3 +1,10 @@
|
|||||||
|
Thu Jan 1 19:53:33 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/socket/mkconstants.rb: add valp argument for family_to_int and
|
||||||
|
socktype_to_int.
|
||||||
|
|
||||||
|
* ext/socket/socket.c (setup_domain_and_type): use valp argument.
|
||||||
|
|
||||||
Thu Jan 1 19:36:57 2009 Tanaka Akira <akr@fsij.org>
|
Thu Jan 1 19:36:57 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/socket/mkconstants.rb: generate family_to_str.
|
* ext/socket/mkconstants.rb: generate family_to_str.
|
||||||
|
@ -75,14 +75,14 @@ def each_names_with_len(pat)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int(str_var, len_var, pat)")
|
ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int(str_var, len_var, retp_var, pat)")
|
||||||
switch (<%=len_var%>) {
|
switch (<%=len_var%>) {
|
||||||
% each_names_with_len(pat) {|names, len|
|
% each_names_with_len(pat) {|names, len|
|
||||||
case <%=len%>:
|
case <%=len%>:
|
||||||
% names.each {|name|
|
% names.each {|name|
|
||||||
#ifdef <%=name%>
|
#ifdef <%=name%>
|
||||||
% size = name.bytesize
|
% size = name.bytesize
|
||||||
if (memcmp(<%=str_var%>, <%=c_str name%>, <%=size%>) == 0) return <%=name%>;
|
if (memcmp(<%=str_var%>, <%=c_str name%>, <%=size%>) == 0) { *<%=retp_var%> = <%=name%>; return 0; }
|
||||||
#endif
|
#endif
|
||||||
% }
|
% }
|
||||||
return -1;
|
return -1;
|
||||||
@ -153,15 +153,15 @@ init_constants(VALUE mConst)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
family_to_int(char *str, int len)
|
family_to_int(char *str, int len, int *valp)
|
||||||
{
|
{
|
||||||
<%= gen_name_to_int("str", "len", /\A[AP]F_/) %>
|
<%= gen_name_to_int("str", "len", "valp", /\A[AP]F_/) %>
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
socktype_to_int(char *str, int len)
|
socktype_to_int(char *str, int len, int *valp)
|
||||||
{
|
{
|
||||||
<%= gen_name_to_int("str", "len", /\ASOCK_/) %>
|
<%= gen_name_to_int("str", "len", "valp", /\ASOCK_/) %>
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
@ -2264,8 +2264,8 @@ unix_peeraddr(VALUE sock)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int family_to_int(char *str, int len);
|
static int family_to_int(char *str, int len, int *valp);
|
||||||
static int socktype_to_int(char *str, int len);
|
static int socktype_to_int(char *str, int len, int *valp);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
|
setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
|
||||||
@ -2275,28 +2275,22 @@ setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
|
|||||||
|
|
||||||
tmp = rb_check_string_type(domain);
|
tmp = rb_check_string_type(domain);
|
||||||
if (!NIL_P(tmp)) {
|
if (!NIL_P(tmp)) {
|
||||||
int family;
|
|
||||||
domain = tmp;
|
domain = tmp;
|
||||||
rb_check_safe_obj(domain);
|
rb_check_safe_obj(domain);
|
||||||
ptr = RSTRING_PTR(domain);
|
ptr = RSTRING_PTR(domain);
|
||||||
family = family_to_int(ptr, RSTRING_LEN(domain));
|
if (family_to_int(ptr, RSTRING_LEN(domain), dv) == -1)
|
||||||
if (family == -1)
|
|
||||||
rb_raise(rb_eSocket, "unknown socket domain %s", ptr);
|
rb_raise(rb_eSocket, "unknown socket domain %s", ptr);
|
||||||
*dv = family;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*dv = NUM2INT(domain);
|
*dv = NUM2INT(domain);
|
||||||
}
|
}
|
||||||
tmp = rb_check_string_type(type);
|
tmp = rb_check_string_type(type);
|
||||||
if (!NIL_P(tmp)) {
|
if (!NIL_P(tmp)) {
|
||||||
int socktype;
|
|
||||||
type = tmp;
|
type = tmp;
|
||||||
rb_check_safe_obj(type);
|
rb_check_safe_obj(type);
|
||||||
ptr = RSTRING_PTR(type);
|
ptr = RSTRING_PTR(type);
|
||||||
socktype = socktype_to_int(ptr, RSTRING_LEN(type));
|
if (socktype_to_int(ptr, RSTRING_LEN(type), tv) == -1)
|
||||||
if (socktype == -1)
|
|
||||||
rb_raise(rb_eSocket, "unknown socket type %s", ptr);
|
rb_raise(rb_eSocket, "unknown socket type %s", ptr);
|
||||||
*tv = socktype;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*tv = NUM2INT(type);
|
*tv = NUM2INT(type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user