* ext/socket/mkconstants.rb: generate socktype_to_int.
* ext/socket/socket.c (setup_domain_and_type): use socktype_to_int. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
009ad25fdd
commit
9787d4faae
@ -1,3 +1,9 @@
|
|||||||
|
Thu Jan 1 17:37:12 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/socket/mkconstants.rb: generate socktype_to_int.
|
||||||
|
|
||||||
|
* ext/socket/socket.c (setup_domain_and_type): use socktype_to_int.
|
||||||
|
|
||||||
Thu Jan 1 17:26:47 2009 Tanaka Akira <akr@fsij.org>
|
Thu Jan 1 17:26:47 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/socket/socket.c (setup_domain_and_type): initialize ptr.
|
* ext/socket/socket.c (setup_domain_and_type): initialize ptr.
|
||||||
|
@ -75,6 +75,24 @@ def each_names_with_len(pat)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int(str_var, len_var, pat)")
|
||||||
|
switch (<%=len_var%>) {
|
||||||
|
% each_names_with_len(pat) {|names, len|
|
||||||
|
case <%=len%>:
|
||||||
|
% names.each {|name|
|
||||||
|
#ifdef <%=name%>
|
||||||
|
% size = name.bytesize
|
||||||
|
if (memcmp(<%=str_var%>, <%=c_str name%>, <%=size%>) == 0) return <%=name%>;
|
||||||
|
#endif
|
||||||
|
% }
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
% }
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
EOS
|
||||||
|
|
||||||
result << ERB.new(<<'EOS', nil, '%').result(binding)
|
result << ERB.new(<<'EOS', nil, '%').result(binding)
|
||||||
static void
|
static void
|
||||||
init_constants(VALUE mConst)
|
init_constants(VALUE mConst)
|
||||||
@ -100,21 +118,13 @@ init_constants(VALUE mConst)
|
|||||||
static int
|
static int
|
||||||
family_to_int(char *str, int len)
|
family_to_int(char *str, int len)
|
||||||
{
|
{
|
||||||
switch (len) {
|
<%= gen_name_to_int("str", "len", /\A[AP]F_/) %>
|
||||||
% each_names_with_len(/\A[AP]F_/) {|names, len|
|
}
|
||||||
case <%=len%>:
|
|
||||||
% names.each {|name|
|
|
||||||
#ifdef <%=name%>
|
|
||||||
% size = name.bytesize
|
|
||||||
if (memcmp(str, <%=c_str name%>, <%=size%>) == 0) return <%=name%>;
|
|
||||||
#endif
|
|
||||||
% }
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
% }
|
static int
|
||||||
default:
|
socktype_to_int(char *str, int len)
|
||||||
return -1;
|
{
|
||||||
}
|
<%= gen_name_to_int("str", "len", /\ASOCK_/) %>
|
||||||
}
|
}
|
||||||
|
|
||||||
EOS
|
EOS
|
||||||
|
@ -2281,6 +2281,7 @@ unix_peeraddr(VALUE sock)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int family_to_int(char *str, int len);
|
static int family_to_int(char *str, int len);
|
||||||
|
static int socktype_to_int(char *str, int len);
|
||||||
|
|
||||||
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)
|
||||||
@ -2304,31 +2305,14 @@ setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
|
|||||||
}
|
}
|
||||||
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);
|
||||||
if (strcmp(ptr, "SOCK_STREAM") == 0)
|
socktype = socktype_to_int(ptr, RSTRING_LEN(type));
|
||||||
*tv = SOCK_STREAM;
|
if (socktype == -1)
|
||||||
else if (strcmp(ptr, "SOCK_DGRAM") == 0)
|
|
||||||
*tv = SOCK_DGRAM;
|
|
||||||
#ifdef SOCK_RAW
|
|
||||||
else if (strcmp(ptr, "SOCK_RAW") == 0)
|
|
||||||
*tv = SOCK_RAW;
|
|
||||||
#endif
|
|
||||||
#ifdef SOCK_SEQPACKET
|
|
||||||
else if (strcmp(ptr, "SOCK_SEQPACKET") == 0)
|
|
||||||
*tv = SOCK_SEQPACKET;
|
|
||||||
#endif
|
|
||||||
#ifdef SOCK_RDM
|
|
||||||
else if (strcmp(ptr, "SOCK_RDM") == 0)
|
|
||||||
*tv = SOCK_RDM;
|
|
||||||
#endif
|
|
||||||
#ifdef SOCK_PACKET
|
|
||||||
else if (strcmp(ptr, "SOCK_PACKET") == 0)
|
|
||||||
*tv = SOCK_PACKET;
|
|
||||||
#endif
|
|
||||||
else
|
|
||||||
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