Commit 49e53bca authored by Tomoyuki Sahara's avatar Tomoyuki Sahara

Socket library for mruby.

parents
MRuby::Gem::Specification.new('mruby-socket') do |spec|
spec.license = 'MIT'
spec.authors = 'Internet Initiative Japan'
end
This diff is collapsed.
#ifdef AF_INET
define_const(AF_INET);
#endif
#ifdef PF_INET
define_const(PF_INET);
#endif
#ifdef AF_INET6
define_const(AF_INET6);
#endif
#ifdef PF_INET6
define_const(PF_INET6);
#endif
#ifdef AF_LINK
define_const(AF_LINK);
#endif
#ifdef PF_LINK
define_const(PF_LINK);
#endif
#ifdef AF_LOCAL
define_const(AF_LOCAL);
#endif
#ifdef PF_LOCAL
define_const(PF_LOCAL);
#endif
#ifdef AF_UNIX
define_const(AF_UNIX);
#endif
#ifdef PF_UNIX
define_const(PF_UNIX);
#endif
#ifdef AF_MAX
define_const(AF_MAX);
#endif
#ifdef AF_UNSPEC
define_const(AF_UNSPEC);
#endif
#ifdef PF_UNSPEC
define_const(PF_UNSPEC);
#endif
#ifdef AF_ROUTE
define_const(AF_ROUTE);
#endif
#ifdef PF_ROUTE
define_const(PF_ROUTE);
#endif
#ifdef AI_CANONNAME
define_const(AI_CANONNAME);
#endif
#ifdef AI_FQDN
define_const(AI_FQDN);
#endif
#ifdef AI_NUMERICHOST
define_const(AI_NUMERICHOST);
#endif
#ifdef AI_NUMERICSERV
define_const(AI_NUMERICSERV);
#endif
#ifdef AI_PASSIVE
define_const(AI_PASSIVE);
#endif
#ifdef IPPROTO_ICMP
define_const(IPPROTO_ICMP);
#endif
#ifdef IPPROTO_IP
define_const(IPPROTO_IP);
#endif
#ifdef IPPROTO_IPV6
define_const(IPPROTO_IPV6);
#endif
#ifdef IPPROTO_RAW
define_const(IPPROTO_RAW);
#endif
#ifdef IPPROTO_TCP
define_const(IPPROTO_TCP);
#endif
#ifdef IPPROTO_UDP
define_const(IPPROTO_UDP);
#endif
#ifdef MSG_BCAST
define_const(MSG_BCAST);
#endif
#ifdef MSG_CTRUNC
define_const(MSG_CTRUNC);
#endif
#ifdef MSG_DONTROUTE
define_const(MSG_DONTROUTE);
#endif
#ifdef MSG_DONTWAIT
define_const(MSG_DONTWAIT);
#endif
#ifdef MSG_EOR
define_const(MSG_EOR);
#endif
#ifdef MSG_MCAST
define_const(MSG_MCAST);
#endif
#ifdef MSG_NOSIGNAL
define_const(MSG_NOSIGNAL);
#endif
#ifdef MSG_OOB
define_const(MSG_OOB);
#endif
#ifdef MSG_PEEK
define_const(MSG_PEEK);
#endif
#ifdef MSG_TRUNC
define_const(MSG_TRUNC);
#endif
#ifdef MSG_WAITALL
define_const(MSG_WAITALL);
#endif
#ifdef NI_DGRAM
define_const(NI_DGRAM);
#endif
#ifdef NI_MAXHOST
define_const(NI_MAXHOST);
#endif
#ifdef NI_MAXSERV
define_const(NI_MAXSERV);
#endif
#ifdef NI_NAMEREQD
define_const(NI_NAMEREQD);
#endif
#ifdef NI_NOFQDN
define_const(NI_NOFQDN);
#endif
#ifdef NI_NUMERICHOST
define_const(NI_NUMERICHOST);
#endif
#ifdef NI_NUMERICSERV
define_const(NI_NUMERICSERV);
#endif
#ifdef SHUT_RD
define_const(SHUT_RD);
#endif
#ifdef SHUT_WR
define_const(SHUT_WR);
#endif
#ifdef SHUT_RDWR
define_const(SHUT_RDWR);
#endif
#ifdef SO_BINDANY
define_const(SO_BINDANY);
#endif
#ifdef SO_BROADCAST
define_const(SO_BROADCAST);
#endif
#ifdef SO_DEBUG
define_const(SO_DEBUG);
#endif
#ifdef SO_DONTROUTE
define_const(SO_DONTROUTE);
#endif
#ifdef SO_ERROR
define_const(SO_ERROR);
#endif
#ifdef SO_KEEPALIVE
define_const(SO_KEEPALIVE);
#endif
#ifdef SO_LINGER
define_const(SO_LINGER);
#endif
#ifdef SO_OOBINLINE
define_const(SO_OOBINLINE);
#endif
#ifdef SO_PEERCRED
define_const(SO_PEERCRED);
#endif
#ifdef SO_RCVBUF
define_const(SO_RCVBUF);
#endif
#ifdef SO_RCVLOWAT
define_const(SO_RCVLOWAT);
#endif
#ifdef SO_RCVTIMEO
define_const(SO_RCVTIMEO);
#endif
#ifdef SO_REUSEADDR
define_const(SO_REUSEADDR);
#endif
#ifdef SO_REUSEPORT
define_const(SO_REUSEPORT);
#endif
#ifdef SO_RTABLE
define_const(SO_RTABLE);
#endif
#ifdef SO_SNDBUF
define_const(SO_SNDBUF);
#endif
#ifdef SO_SNDLOWAT
define_const(SO_SNDLOWAT);
#endif
#ifdef SO_SNDTIMEO
define_const(SO_SNDTIMEO);
#endif
#ifdef SO_SPLICE
define_const(SO_SPLICE);
#endif
#ifdef SO_TIMESTAMP
define_const(SO_TIMESTAMP);
#endif
#ifdef SO_TYPE
define_const(SO_TYPE);
#endif
#ifdef SOCK_DGRAM
define_const(SOCK_DGRAM);
#endif
#ifdef SOCK_RAW
define_const(SOCK_RAW);
#endif
#ifdef SOCK_SEQPACKET
define_const(SOCK_SEQPACKET);
#endif
#ifdef SOCK_STREAM
define_const(SOCK_STREAM);
#endif
#ifdef SOL_SOCKET
define_const(SOL_SOCKET);
#endif
AF_INET
PF_INET
AF_INET6
PF_INET6
AF_LINK
PF_LINK
AF_LOCAL
PF_LOCAL
AF_UNIX
PF_UNIX
AF_MAX
AF_UNSPEC
PF_UNSPEC
AF_ROUTE
PF_ROUTE
AI_CANONNAME
AI_FQDN
AI_NUMERICHOST
AI_NUMERICSERV
AI_PASSIVE
IPPROTO_ICMP
IPPROTO_IP
IPPROTO_IPV6
IPPROTO_RAW
IPPROTO_TCP
IPPROTO_UDP
MSG_BCAST
MSG_CTRUNC
MSG_DONTROUTE
MSG_DONTWAIT
MSG_EOR
MSG_MCAST
MSG_NOSIGNAL
MSG_OOB
MSG_PEEK
MSG_TRUNC
MSG_WAITALL
NI_DGRAM
NI_MAXHOST
NI_MAXSERV
NI_NAMEREQD
NI_NOFQDN
NI_NUMERICHOST
NI_NUMERICSERV
SHUT_RD
SHUT_WR
SHUT_RDWR
SO_BINDANY
SO_BROADCAST
SO_DEBUG
SO_DONTROUTE
SO_ERROR
SO_KEEPALIVE
SO_LINGER
SO_OOBINLINE
SO_PEERCRED
SO_RCVBUF
SO_RCVLOWAT
SO_RCVTIMEO
SO_REUSEADDR
SO_REUSEPORT
SO_RTABLE
SO_SNDBUF
SO_SNDLOWAT
SO_SNDTIMEO
SO_SPLICE
SO_TIMESTAMP
SO_TYPE
SOCK_DGRAM
SOCK_RAW
SOCK_SEQPACKET
SOCK_STREAM
SOL_SOCKET
#!/usr/bin/env ruby
Dir.chdir(File.dirname($0))
f = File.open("const.cstub", "w")
IO.readlines("const.def").each { |name|
name.sub(/^#.*/, "")
name.strip!
next if name.empty?
f.write <<CODE
#ifdef #{name}
define_const(#{name});
#endif
CODE
}
This diff is collapsed.
assert('Addrinfo') do
assert_equal(Class, Addrinfo.class)
end
assert('super class of Addrinfo') do
assert_equal(Object, Addrinfo.superclass)
end
assert('Addrinfo.getadrinfo') do
ary = Addrinfo.getaddrinfo("localhost", "domain", Socket::AF_INET, Socket::SOCK_STREAM)
assert_equal(ary.size, 1)
ai = ary[0]
assert_equal(ai.afamily, Socket::AF_INET)
assert_equal(ai.pfamily, Socket::PF_INET)
assert_equal(ai.socktype, Socket::SOCK_STREAM)
assert_equal(ai.ip_address, '127.0.0.1')
assert_equal(ai.ip_port, 53)
end
assert('Addrinfo.foreach') do
# assume Addrinfo.getaddrinfo works well
b = []
a = Addrinfo.foreach("localhost", "domain") { |ai|
assert_include([Socket::AF_INET, Socket::AF_INET6], ai.afamily)
if ai.afamily == Socket::AF_INET
assert_equal(ai.ip_address, '127.0.0.1')
else
assert_equal(ai.ip_address, '::1')
end
assert_equal(ai.ip_port, 53)
assert_include([Socket::SOCK_STREAM, Socket::SOCK_DGRAM], ai.socktype)
b << ai
}
assert_equal(a.size, b.size)
end
assert('Addrinfo.ip') do
ai = Addrinfo.ip('127.0.0.1')
assert_equal('127.0.0.1', ai.ip_address)
assert_equal(Socket::AF_INET, ai.afamily)
assert_equal(0, ai.ip_port)
assert_equal(0, ai.socktype)
assert_equal(0, ai.protocol)
end
assert('Addrinfo.tcp') do
ai = Addrinfo.tcp('127.0.0.1', 'smtp')
assert_equal('127.0.0.1', ai.ip_address)
assert_equal(Socket::AF_INET, ai.afamily)
assert_equal(25, ai.ip_port)
assert_equal(Socket::SOCK_STREAM, ai.socktype)
assert_equal(Socket::IPPROTO_TCP, ai.protocol)
end
assert('Addrinfo.udp') do
ai = Addrinfo.udp('127.0.0.1', 'domain')
assert_equal('127.0.0.1', ai.ip_address)
assert_equal(Socket::AF_INET, ai.afamily)
assert_equal(53, ai.ip_port)
assert_equal(Socket::SOCK_DGRAM, ai.socktype)
assert_equal(Socket::IPPROTO_UDP, ai.protocol)
end
assert('Addrinfo.unix') do
a1 = Addrinfo.unix('/tmp/sock')
assert_true(a1.unix?)
assert_equal('/tmp/sock', a1.unix_path)
assert_equal(Socket::SOCK_STREAM, a1.socktype)
a2 = Addrinfo.unix('/tmp/sock', Socket::SOCK_DGRAM)
assert_equal(Socket::SOCK_DGRAM, a2.socktype)
end
assert('Addrinfo#afamily') do
ai4 = Addrinfo.new(Socket.sockaddr_in(1, '127.0.0.1'))
ai6 = Addrinfo.new(Socket.sockaddr_in(1, '::1'))
aiu = Addrinfo.new(Socket.sockaddr_un('/tmp/sock'))
assert_equal(Socket::AF_INET, ai4.afamily)
assert_equal(Socket::AF_INET6, ai6.afamily)
assert_equal(Socket::AF_UNIX, aiu.afamily)
end
# assert('Addrinfo#canonname') do
# #getnameinfo
# assert('Addrinfo#inspect') do
# assert('Addrinfo#inspect_socket') do
# assert('Addrinfo#ip?') do
# assert('Addrinfo#ip_address') do
# assert('Addrinfo#ip_port') do
# assert('Addrinfo#ip_unpack') do
# assert('Addrinfo#ipv4?') do
# assert('Addrinfo#ipv6?') do
# assert('Addrinfo#pfamily') do
# assert('Addrinfo#protocol') do
# assert('Addrinfo#socktype') do
# assert('Addrinfo#to_sockaddr') do
# assert('Addrinfo#unix?') do
# #unix_path
assert('BasicSocket') do
assert_equal(Class, BasicSocket.class)
end
assert('super class of BasicSocket') do
assert_equal(IO, BasicSocket.superclass)
end
assert('BasicSocket.do_not_reverse_lookup') do
assert_equal(BasicSocket.do_not_reverse_lookup, true)
end
assert('BasicSocket.do_not_reverse_lookup=') do
BasicSocket.do_not_reverse_lookup = false
assert_equal(BasicSocket.do_not_reverse_lookup, false)
BasicSocket.do_not_reverse_lookup = true
end
assert('UDPSocket.new') do
s = UDPSocket.new
assert_true(s.is_a? UDPSocket)
s.close
s = UDPSocket.new(Socket::AF_INET6)
assert_true(s.is_a? UDPSocket)
s.close
true
end
#assert('UDPSocket#connect') do
#assert('UDPSocket#send') do
#assert('UDPSocket#recv') do
#assert('UDPSocket#bind') do
#assert('UDPSocket#recvfrom_nonblock') do
#assert('TCPSocket.gethostbyname') do
#assert('TCPSocket.new') do
#assert('TCPSocket#close') do
#assert('TCPSocket#write') do
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment