@JRubyModule(name="Socket::Constants")
public static class Constants {}
static void createSocket(Ruby runtime) {
RubyClass rb_cSocket = runtime.defineClass("Socket", runtime.fastGetClass("BasicSocket"), SOCKET_ALLOCATOR);
RubyModule rb_mConstants = rb_cSocket.defineModuleUnder("Constants");
// we don't have to define any that we don't support; see socket.c
rb_mConstants.fastSetConstant("SOCK_STREAM", runtime.newFixnum(SOCK_STREAM));
rb_mConstants.fastSetConstant("SOCK_DGRAM", runtime.newFixnum(SOCK_DGRAM));
rb_mConstants.fastSetConstant("SOCK_RAW", runtime.newFixnum(SOCK_RAW));
rb_mConstants.fastSetConstant("SOCK_RDM", runtime.newFixnum(SOCK_RDM));
rb_mConstants.fastSetConstant("SOCK_SEQPACKET", runtime.newFixnum(SOCK_SEQPACKET));
rb_mConstants.fastSetConstant("PF_UNSPEC", runtime.newFixnum(PF_UNSPEC));
rb_mConstants.fastSetConstant("AF_UNSPEC", runtime.newFixnum(AF_UNSPEC));
rb_mConstants.fastSetConstant("PF_INET", runtime.newFixnum(PF_INET));
rb_mConstants.fastSetConstant("AF_INET", runtime.newFixnum(AF_INET));
rb_mConstants.fastSetConstant("PF_INET6", runtime.newFixnum(AF_INET6));
rb_mConstants.fastSetConstant("AF_INET6", runtime.newFixnum(AF_INET6));
rb_mConstants.fastSetConstant("PF_UNIX", runtime.newFixnum(PF_UNIX));
rb_mConstants.fastSetConstant("AF_UNIX", runtime.newFixnum(AF_UNIX));
rb_mConstants.fastSetConstant("PF_IPX", runtime.newFixnum(PF_IPX));
rb_mConstants.fastSetConstant("AF_IPX", runtime.newFixnum(AF_IPX));
// mandatory constants we haven't implemented
rb_mConstants.fastSetConstant("MSG_OOB", runtime.newFixnum(MSG_OOB));
rb_mConstants.fastSetConstant("MSG_PEEK", runtime.newFixnum(MSG_PEEK));
rb_mConstants.fastSetConstant("MSG_DONTROUTE", runtime.newFixnum(MSG_DONTROUTE));
rb_mConstants.fastSetConstant("SOL_SOCKET", runtime.newFixnum(SOL_SOCKET));
rb_mConstants.fastSetConstant("SOL_IP", runtime.newFixnum(SOL_IP));
rb_mConstants.fastSetConstant("SOL_TCP", runtime.newFixnum(SOL_TCP));
rb_mConstants.fastSetConstant("SOL_UDP", runtime.newFixnum(SOL_UDP));
rb_mConstants.fastSetConstant("IPPROTO_IP", runtime.newFixnum(0));
rb_mConstants.fastSetConstant("IPPROTO_ICMP", runtime.newFixnum(1));
rb_mConstants.fastSetConstant("IPPROTO_TCP", runtime.newFixnum(6));
rb_mConstants.fastSetConstant("IPPROTO_UDP", runtime.newFixnum(17));
// IPPROTO_RAW = 255
rb_mConstants.fastSetConstant("INADDR_ANY", runtime.newFixnum(0x00000000));
rb_mConstants.fastSetConstant("INADDR_BROADCAST", runtime.newFixnum(0xffffffff));
rb_mConstants.fastSetConstant("INADDR_LOOPBACK", runtime.newFixnum(0x7f000001));
rb_mConstants.fastSetConstant("INADDR_UNSPEC_GROUP", runtime.newFixnum(0xe0000000));
rb_mConstants.fastSetConstant("INADDR_ALLHOSTS_GROUP", runtime.newFixnum(0xe0000001));
rb_mConstants.fastSetConstant("INADDR_MAX_LOCAL_GROUP", runtime.newFixnum(0xe00000ff));
rb_mConstants.fastSetConstant("INADDR_NONE", runtime.newFixnum(0xffffffff));
rb_mConstants.fastSetConstant("SHUT_RD", runtime.newFixnum(0));
rb_mConstants.fastSetConstant("SHUT_WR", runtime.newFixnum(1));
rb_mConstants.fastSetConstant("SHUT_RDWR", runtime.newFixnum(2));
// constants webrick crashes without
rb_mConstants.fastSetConstant("AI_PASSIVE", runtime.newFixnum(1));
// constants from MacOS X 10.4
rb_mConstants.fastSetConstant("SO_BROADCAST", runtime.newFixnum(SO_BROADCAST));
rb_mConstants.fastSetConstant("SO_DEBUG", runtime.newFixnum(SO_DEBUG));
rb_mConstants.fastSetConstant("SO_DONTROUTE", runtime.newFixnum(SO_DONTROUTE));
rb_mConstants.fastSetConstant("SO_ERROR", runtime.newFixnum(SO_ERROR));
rb_mConstants.fastSetConstant("SO_KEEPALIVE", runtime.newFixnum(SO_KEEPALIVE));
rb_mConstants.fastSetConstant("SO_LINGER", runtime.newFixnum(SO_LINGER));
rb_mConstants.fastSetConstant("SO_OOBINLINE", runtime.newFixnum(SO_OOBINLINE));
rb_mConstants.fastSetConstant("SO_RCVBUF", runtime.newFixnum(SO_RCVBUF));
rb_mConstants.fastSetConstant("SO_RCVLOWAT", runtime.newFixnum(SO_RCVLOWAT));
rb_mConstants.fastSetConstant("SO_RCVTIMEO", runtime.newFixnum(SO_RCVTIMEO));
rb_mConstants.fastSetConstant("SO_REUSEADDR", runtime.newFixnum(SO_REUSEADDR));
rb_mConstants.fastSetConstant("SO_SNDBUF", runtime.newFixnum(SO_SNDBUF));
rb_mConstants.fastSetConstant("SO_SNDLOWAT", runtime.newFixnum(SO_SNDLOWAT));
rb_mConstants.fastSetConstant("SO_SNDTIMEO", runtime.newFixnum(SO_SNDTIMEO));
rb_mConstants.fastSetConstant("SO_TIMESTAMP", runtime.newFixnum(SO_TIMESTAMP));
rb_mConstants.fastSetConstant("SO_TYPE", runtime.newFixnum(SO_TYPE));
// drb needs defined
rb_mConstants.fastSetConstant("TCP_NODELAY", runtime.newFixnum(1));
rb_mConstants.fastSetConstant("TCP_MAXSEG", runtime.newFixnum(2));
// flags/limits used by Net::SSH
rb_mConstants.fastSetConstant("NI_DGRAM", runtime.newFixnum(NI_DGRAM));
rb_mConstants.fastSetConstant("NI_MAXHOST", runtime.newFixnum(NI_MAXHOST));
rb_mConstants.fastSetConstant("NI_MAXSERV", runtime.newFixnum(NI_MAXSERV));
rb_mConstants.fastSetConstant("NI_NAMEREQD", runtime.newFixnum(NI_NAMEREQD));
rb_mConstants.fastSetConstant("NI_NOFQDN", runtime.newFixnum(NI_NOFQDN));
rb_mConstants.fastSetConstant("NI_NUMERICHOST", runtime.newFixnum(NI_NUMERICHOST));
rb_mConstants.fastSetConstant("NI_NUMERICSERV", runtime.newFixnum(NI_NUMERICSERV));
// More constants needed by specs
rb_mConstants.fastSetConstant("IP_MULTICAST_TTL", runtime.newFixnum(10));
rb_mConstants.fastSetConstant("IP_MULTICAST_LOOP", runtime.newFixnum(11));
rb_mConstants.fastSetConstant("IP_ADD_MEMBERSHIP", runtime.newFixnum(12));
rb_mConstants.fastSetConstant("IP_MAX_MEMBERSHIPS", runtime.newFixnum(20));
rb_mConstants.fastSetConstant("IP_DEFAULT_MULTICAST_LOOP", runtime.newFixnum(1));
rb_mConstants.fastSetConstant("IP_DEFAULT_MULTICAST_TTL", runtime.newFixnum(1));
rb_cSocket.includeModule(rb_mConstants);
rb_cSocket.defineAnnotatedMethods(RubySocket.class);
}