Skip to content

Commit

Permalink
Simplify t_get_sock_opt, fix whitespace and use SO_ERROR in test to m…
Browse files Browse the repository at this point in the history
…ake it pass on OSX
  • Loading branch information
tmm1 committed Aug 11, 2009
1 parent c4b4ed1 commit 2c6730c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions ext/rubymain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,15 @@ t_get_sock_opt

static VALUE t_get_sock_opt (VALUE self, VALUE signature, VALUE lev, VALUE optname)
{
int fd = evma_get_file_descriptor (NUM2ULONG (signature));
int level = NUM2INT(lev), option = NUM2INT(optname);
socklen_t len;
char *buf = ALLOCA_N(char, len);
int fd = evma_get_file_descriptor (NUM2ULONG (signature));
int level = NUM2INT(lev), option = NUM2INT(optname);
socklen_t len;
char buf[128];

if (getsockopt(fd, level, option, buf, &len) < 0)
rb_sys_fail("get_sock_opt");
if (getsockopt(fd, level, option, buf, &len) < 0)
rb_sys_fail("getsockopt");

return rb_str_new(buf, len);
return rb_str_new(buf, len);
}

/********************
Expand Down
4 changes: 2 additions & 2 deletions tests/test_get_sock_opt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def test_get_sock_opt
EM.run do
EM.connect 'google.com', 80, Module.new {
define_method :connection_completed do
val = get_sock_opt Socket::SOL_SOCKET, Socket::SO_REUSEADDR
test.assert_equal "\01\0\0\0", val
val = get_sock_opt Socket::SOL_SOCKET, Socket::SO_ERROR
test.assert_equal "\0\0\0\0", val
EM.stop
end
}
Expand Down

0 comments on commit 2c6730c

Please sign in to comment.