mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
3 changed files with 35 additions and 35 deletions
|
@ -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>
|
||||
|
||||
* ext/socket/socket.c (setup_domain_and_type): initialize ptr.
|
||||
|
|
|
@ -75,6 +75,24 @@ def each_names_with_len(pat)
|
|||
}
|
||||
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)
|
||||
static void
|
||||
init_constants(VALUE mConst)
|
||||
|
@ -100,21 +118,13 @@ init_constants(VALUE mConst)
|
|||
static int
|
||||
family_to_int(char *str, int len)
|
||||
{
|
||||
switch (len) {
|
||||
% 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;
|
||||
<%= gen_name_to_int("str", "len", /\A[AP]F_/) %>
|
||||
}
|
||||
|
||||
% }
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
static int
|
||||
socktype_to_int(char *str, int len)
|
||||
{
|
||||
<%= gen_name_to_int("str", "len", /\ASOCK_/) %>
|
||||
}
|
||||
|
||||
EOS
|
||||
|
|
|
@ -2281,6 +2281,7 @@ unix_peeraddr(VALUE sock)
|
|||
#endif
|
||||
|
||||
static int family_to_int(char *str, int len);
|
||||
static int socktype_to_int(char *str, int len);
|
||||
|
||||
static void
|
||||
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);
|
||||
if (!NIL_P(tmp)) {
|
||||
int socktype;
|
||||
type = tmp;
|
||||
rb_check_safe_obj(type);
|
||||
ptr = RSTRING_PTR(type);
|
||||
if (strcmp(ptr, "SOCK_STREAM") == 0)
|
||||
*tv = SOCK_STREAM;
|
||||
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
|
||||
socktype = socktype_to_int(ptr, RSTRING_LEN(type));
|
||||
if (socktype == -1)
|
||||
rb_raise(rb_eSocket, "unknown socket type %s", ptr);
|
||||
*tv = socktype;
|
||||
}
|
||||
else {
|
||||
*tv = NUM2INT(type);
|
||||
|
|
Loading…
Add table
Reference in a new issue