/* * call-seq: * TCPServer.new([hostname,] port) => tcpserver * * Creates a new server socket bound to _port_. * * If _hostname_ is given, the socket is bound to it. * * serv = TCPServer.new("127.0.0.1", 28561) * s = serv.accept * s.puts Time.now * s.close * * Internally, TCPServer.new calls getaddrinfo() function to * obtain addresses. * If getaddrinfo() returns multiple addresses, * TCPServer.new tries to create a server socket for each address * and returns first one that is successful. * */ static VALUE tcp_svr_init(int argc, VALUE *argv, VALUE sock) { VALUE hostname, port; rb_scan_args(argc, argv, "011", &hostname, &port); return rsock_init_inetsock(sock, hostname, port, Qnil, Qnil, INET_SERVER); }
/* * call-seq: * TCPSocket.new(remote_host, remote_port, local_host=nil, local_port=nil) * * Opens a TCP connection to +remote_host+ on +remote_port+. If +local_host+ * and +local_port+ are specified, then those parameters are used on the local * end to establish the connection. */ static VALUE tcp_init(int argc, VALUE *argv, VALUE sock) { VALUE remote_host, remote_serv; VALUE local_host, local_serv; rb_scan_args(argc, argv, "22", &remote_host, &remote_serv, &local_host, &local_serv); return rsock_init_inetsock(sock, remote_host, remote_serv, local_host, local_serv, INET_CLIENT); }
/* * call-seq: * SOCKSSocket.new(host, serv) => socket * * Opens a SOCKS connection to +host+ via the SOCKS server +serv+. * */ static VALUE socks_init(VALUE sock, VALUE host, VALUE serv) { static int init = 0; if (init == 0) { SOCKSinit("ruby"); init = 1; } return rsock_init_inetsock(sock, host, serv, Qnil, Qnil, INET_SOCKS); }