Sha256: 8ef1225314f34830002132738bb990383112427fb93ab13fb7f0f39d6545f5ee

Contents?: true

Size: 1.74 KB

Versions: 43

Compression:

Stored size: 1.74 KB

Contents

/************************************************

  tcpsocket.c -

  created at: Thu Mar 31 12:21:29 JST 1994

  Copyright (C) 1993-2007 Yukihiro Matsumoto

************************************************/

#include "rubysocket.h"

/*
 * 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);
}

static VALUE
tcp_sockaddr(struct sockaddr *addr, size_t len)
{
    return rsock_make_ipaddr(addr);
}

/*
 * call-seq:
 *   TCPSocket.gethostbyname(hostname) => [official_hostname, alias_hostnames, address_family, *address_list]
 *
 * Lookups host information by _hostname_.
 *
 *   TCPSocket.gethostbyname("localhost")
 *   #=> ["localhost", ["hal"], 2, "127.0.0.1"]
 *
 */
static VALUE
tcp_s_gethostbyname(VALUE obj, VALUE host)
{
    rb_secure(3);
    return rsock_make_hostent(host, rsock_addrinfo(host, Qnil, SOCK_STREAM, AI_CANONNAME),
			tcp_sockaddr);
}

/*
 * Document-class: ::TCPSocket < IPSocket
 *
 * TCPSocket represents a TCP/IP client socket.
 */
void
rsock_init_tcpsocket(void)
{
    rb_cTCPSocket = rb_define_class("TCPSocket", rb_cIPSocket);
    rb_define_singleton_method(rb_cTCPSocket, "gethostbyname", tcp_s_gethostbyname, 1);
    rb_define_method(rb_cTCPSocket, "initialize", tcp_init, -1);
}

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
rhodes-5.5.18 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-5.5.17 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-5.5.15 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-5.5.0.22 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-5.5.2 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-5.5.0.7 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-5.5.0.3 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-5.5.0 platform/shared/ruby/ext/socket_192/tcpsocket.c
tauplatform-1.0.3 platform/shared/ruby/ext/socket_192/tcpsocket.c
tauplatform-1.0.2 platform/shared/ruby/ext/socket_192/tcpsocket.c
tauplatform-1.0.1 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-3.5.1.12 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-3.3.5 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-3.4.2 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-3.3.4 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-3.3.3 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-3.3.3.beta.4 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-3.3.3.beta.3 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-3.3.3.beta.2 platform/shared/ruby/ext/socket_192/tcpsocket.c
rhodes-3.3.3.beta.1 platform/shared/ruby/ext/socket_192/tcpsocket.c