Ruby  2.0.0p451(2014-02-24revision45167)
Data Structures | Macros | Enumerations | Functions | Variables
rubysocket.h File Reference
#include "ruby/ruby.h"
#include "ruby/io.h"
#include "ruby/thread.h"
#include "ruby/util.h"
#include "internal.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include "addrinfo.h"
#include "sockport.h"
#include "constdefs.h"
Include dependency graph for rubysocket.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sockaddr_storage
 
struct  rsock_send_arg
 

Macros

#define EWOULDBLOCK   EAGAIN
 
#define pseudo_AF_FTIP   pseudo_AF_RTIP
 
#define IS_IP_FAMILY(af)   ((af) == AF_INET)
 
#define IN6_IS_ADDR_UNIQUE_LOCAL(a)   (((a)->s6_addr[0] == 0xfc) || ((a)->s6_addr[0] == 0xfd))
 
#define _SS_MAXSIZE   128
 
#define _SS_ALIGNSIZE   (sizeof(double))
 
#define _SS_PAD1SIZE   (_SS_ALIGNSIZE - sizeof(unsigned char) * 2)
 
#define _SS_PAD2SIZE
 
#define INET_CLIENT   0
 
#define INET_SERVER   1
 
#define INET_SOCKS   2
 
#define FMODE_NOREVLOOKUP   0x100
 
#define BLOCKING_REGION(func, arg)   (long)rb_thread_blocking_region((func), (arg), RUBY_UBF_IO, 0)
 
#define BLOCKING_REGION_FD(func, arg)   (long)rb_thread_io_blocking_region((func), (arg), (arg)->fd)
 
#define SockAddrStringValue(v)   rsock_sockaddr_string_value(&(v))
 
#define SockAddrStringValuePtr(v)   rsock_sockaddr_string_value_ptr(&(v))
 
#define rsock_bsock_sendmsg   rb_f_notimplement
 
#define rsock_bsock_sendmsg_nonblock   rb_f_notimplement
 
#define rsock_bsock_recvmsg   rb_f_notimplement
 
#define rsock_bsock_recvmsg_nonblock   rb_f_notimplement
 

Enumerations

enum  sock_recv_type { RECV_RECV, RECV_IP, RECV_UNIX, RECV_SOCKET }
 

Functions

VALUE rsock_sockaddr_string_value (volatile VALUE *)
 
char * rsock_sockaddr_string_value_ptr (volatile VALUE *)
 
VALUE rb_check_sockaddr_string_type (VALUE)
 
 NORETURN (void rsock_raise_socket_error(const char *, int))
 
int rsock_family_arg (VALUE domain)
 
int rsock_socktype_arg (VALUE type)
 
int rsock_level_arg (int family, VALUE level)
 
int rsock_optname_arg (int family, int level, VALUE optname)
 
int rsock_cmsg_type_arg (int family, int level, VALUE type)
 
int rsock_shutdown_how_arg (VALUE how)
 
int rsock_getfamily (int sockfd)
 
int rb_getaddrinfo (const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
 
int rb_getnameinfo (const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
 
struct addrinforsock_addrinfo (VALUE host, VALUE port, int socktype, int flags)
 
struct addrinforsock_getaddrinfo (VALUE host, VALUE port, struct addrinfo *hints, int socktype_hack)
 
VALUE rsock_fd_socket_addrinfo (int fd, struct sockaddr *addr, socklen_t len)
 
VALUE rsock_io_socket_addrinfo (VALUE io, struct sockaddr *addr, socklen_t len)
 
VALUE rsock_addrinfo_new (struct sockaddr *addr, socklen_t len, int family, int socktype, int protocol, VALUE canonname, VALUE inspectname)
 
VALUE rsock_make_ipaddr (struct sockaddr *addr)
 
VALUE rsock_ipaddr (struct sockaddr *sockaddr, int norevlookup)
 
VALUE rsock_make_hostent (VALUE host, struct addrinfo *addr, VALUE(*ipaddr)(struct sockaddr *, size_t))
 
int rsock_revlookup_flag (VALUE revlookup, int *norevlookup)
 
int rsock_socket (int domain, int type, int proto)
 
VALUE rsock_init_sock (VALUE sock, int fd)
 
VALUE rsock_sock_s_socketpair (int argc, VALUE *argv, VALUE klass)
 
VALUE rsock_init_inetsock (VALUE sock, VALUE remote_host, VALUE remote_serv, VALUE local_host, VALUE local_serv, int type)
 
VALUE rsock_init_unixsock (VALUE sock, VALUE path, int server)
 
VALUE rsock_sendto_blocking (void *data)
 
VALUE rsock_send_blocking (void *data)
 
VALUE rsock_bsock_send (int argc, VALUE *argv, VALUE sock)
 
VALUE rsock_s_recvfrom_nonblock (VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
 
VALUE rsock_s_recvfrom (VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
 
int rsock_connect (int fd, const struct sockaddr *sockaddr, int len, int socks)
 
VALUE rsock_s_accept (VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
 
VALUE rsock_s_accept_nonblock (VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
 
VALUE rsock_sock_listen (VALUE sock, VALUE log)
 
VALUE rsock_sockopt_new (int family, int level, int optname, VALUE data)
 
void rsock_init_basicsocket (void)
 
void rsock_init_ipsocket (void)
 
void rsock_init_tcpsocket (void)
 
void rsock_init_tcpserver (void)
 
void rsock_init_sockssocket (void)
 
void rsock_init_udpsocket (void)
 
void rsock_init_unixsocket (void)
 
void rsock_init_unixserver (void)
 
void rsock_init_socket_constants (void)
 
void rsock_init_ancdata (void)
 
void rsock_init_addrinfo (void)
 
void rsock_init_sockopt (void)
 
void rsock_init_socket_init (void)
 

Variables

int rsock_do_not_reverse_lookup
 
VALUE rb_cBasicSocket
 
VALUE rb_cIPSocket
 
VALUE rb_cTCPSocket
 
VALUE rb_cTCPServer
 
VALUE rb_cUDPSocket
 
VALUE rb_cSocket
 
VALUE rb_cAddrinfo
 
VALUE rb_cSockOpt
 
VALUE rb_eSocket
 

Macro Definition Documentation

#define _SS_ALIGNSIZE   (sizeof(double))

Definition at line 129 of file rubysocket.h.

#define _SS_MAXSIZE   128

Definition at line 128 of file rubysocket.h.

#define _SS_PAD1SIZE   (_SS_ALIGNSIZE - sizeof(unsigned char) * 2)

Definition at line 130 of file rubysocket.h.

#define _SS_PAD2SIZE
Value:
(_SS_MAXSIZE - sizeof(unsigned char) * 2 - \
#define _SS_ALIGNSIZE
Definition: rubysocket.h:129
#define _SS_MAXSIZE
Definition: rubysocket.h:128
#define _SS_PAD1SIZE
Definition: rubysocket.h:130

Definition at line 131 of file rubysocket.h.

#define BLOCKING_REGION (   func,
  arg 
)    (long)rb_thread_blocking_region((func), (arg), RUBY_UBF_IO, 0)

Definition at line 205 of file rubysocket.h.

#define BLOCKING_REGION_FD (   func,
  arg 
)    (long)rb_thread_io_blocking_region((func), (arg), (arg)->fd)
#define EWOULDBLOCK   EAGAIN
#define FMODE_NOREVLOOKUP   0x100
#define IN6_IS_ADDR_UNIQUE_LOCAL (   a)    (((a)->s6_addr[0] == 0xfc) || ((a)->s6_addr[0] == 0xfd))

Definition at line 121 of file rubysocket.h.

#define INET_CLIENT   0

Definition at line 171 of file rubysocket.h.

Referenced by tcp_init().

#define INET_SERVER   1

Definition at line 172 of file rubysocket.h.

Referenced by init_inetsock_internal(), and tcp_svr_init().

#define INET_SOCKS   2

Definition at line 173 of file rubysocket.h.

Referenced by init_inetsock_internal().

#define IS_IP_FAMILY (   af)    ((af) == AF_INET)
#define pseudo_AF_FTIP   pseudo_AF_RTIP

Definition at line 100 of file rubysocket.h.

#define rsock_bsock_recvmsg   rb_f_notimplement

Definition at line 293 of file rubysocket.h.

Referenced by rsock_init_basicsocket().

#define rsock_bsock_recvmsg_nonblock   rb_f_notimplement

Definition at line 294 of file rubysocket.h.

Referenced by rsock_init_basicsocket().

#define rsock_bsock_sendmsg   rb_f_notimplement

Definition at line 285 of file rubysocket.h.

Referenced by rsock_init_basicsocket().

#define rsock_bsock_sendmsg_nonblock   rb_f_notimplement

Definition at line 286 of file rubysocket.h.

Referenced by rsock_init_basicsocket().

#define SockAddrStringValue (   v)    rsock_sockaddr_string_value(&(v))

Definition at line 208 of file rubysocket.h.

Referenced by rsock_bsock_send(), sock_bind(), sock_connect(), and sock_connect_nonblock().

#define SockAddrStringValuePtr (   v)    rsock_sockaddr_string_value_ptr(&(v))

Definition at line 209 of file rubysocket.h.

Referenced by sock_s_unpack_sockaddr_in().

Enumeration Type Documentation

Enumerator
RECV_RECV 
RECV_IP 
RECV_UNIX 
RECV_SOCKET 

Definition at line 263 of file rubysocket.h.

Function Documentation

NORETURN ( void   rsock_raise_socket_errorconst char *, int)
VALUE rb_check_sockaddr_string_type ( VALUE  )

Definition at line 2156 of file raddrinfo.c.

References addrinfo_to_sockaddr(), IS_ADDRINFO, and rb_check_string_type().

Referenced by sock_s_getnameinfo().

int rb_getaddrinfo ( const char *  node,
const char *  service,
const struct addrinfo hints,
struct addrinfo **  res 
)
int rb_getnameinfo ( const struct sockaddr *  sa,
socklen_t  salen,
char *  host,
size_t  hostlen,
char *  serv,
size_t  servlen,
int  flags 
)
struct addrinfo* rsock_addrinfo ( VALUE  host,
VALUE  port,
int  socktype,
int  flags 
)
VALUE rsock_addrinfo_new ( struct sockaddr *  addr,
socklen_t  len,
int  family,
int  socktype,
int  protocol,
VALUE  canonname,
VALUE  inspectname 
)
VALUE rsock_bsock_send ( int  argc,
VALUE argv,
VALUE  sock 
)
int rsock_cmsg_type_arg ( int  family,
int  level,
VALUE  type 
)

Definition at line 100 of file constants.c.

References constant_arg(), IS_IP_FAMILY, and NUM2INT.

int rsock_connect ( int  fd,
const struct sockaddr *  sockaddr,
int  len,
int  socks 
)
int rsock_family_arg ( VALUE  domain)
VALUE rsock_fd_socket_addrinfo ( int  fd,
struct sockaddr *  addr,
socklen_t  len 
)
struct addrinfo* rsock_getaddrinfo ( VALUE  host,
VALUE  port,
struct addrinfo hints,
int  socktype_hack 
)
int rsock_getfamily ( int  sockfd)

Definition at line 596 of file init.c.

References AF_UNSPEC, and sockaddr_storage::ss_family.

Referenced by bsock_getsockopt(), and bsock_setsockopt().

void rsock_init_addrinfo ( void  )
void rsock_init_ancdata ( void  )
void rsock_init_basicsocket ( void  )
VALUE rsock_init_inetsock ( VALUE  sock,
VALUE  remote_host,
VALUE  remote_serv,
VALUE  local_host,
VALUE  local_serv,
int  type 
)
void rsock_init_ipsocket ( void  )
VALUE rsock_init_sock ( VALUE  sock,
int  fd 
)
void rsock_init_socket_constants ( void  )

Definition at line 141 of file constants.c.

Referenced by rsock_init_socket_init().

void rsock_init_socket_init ( void  )
void rsock_init_sockopt ( void  )
void rsock_init_sockssocket ( void  )

Definition at line 55 of file sockssocket.c.

References rb_cTCPSocket, rb_define_class(), and rb_define_method().

Referenced by rsock_init_socket_init().

void rsock_init_tcpserver ( void  )
void rsock_init_tcpsocket ( void  )
void rsock_init_udpsocket ( void  )
void rsock_init_unixserver ( void  )

Definition at line 139 of file unixserver.c.

References rb_define_class(), rb_define_method(), and rsock_sock_listen().

Referenced by rsock_init_socket_init().

VALUE rsock_init_unixsock ( VALUE  sock,
VALUE  path,
int  server 
)
void rsock_init_unixsocket ( void  )
VALUE rsock_io_socket_addrinfo ( VALUE  io,
struct sockaddr *  addr,
socklen_t  len 
)
VALUE rsock_ipaddr ( struct sockaddr *  sockaddr,
int  norevlookup 
)
int rsock_level_arg ( int  family,
VALUE  level 
)
VALUE rsock_make_hostent ( VALUE  host,
struct addrinfo addr,
VALUE(*)(struct sockaddr *, size_t)  ipaddr 
)
VALUE rsock_make_ipaddr ( struct sockaddr *  addr)

Definition at line 251 of file raddrinfo.c.

References make_ipaddr0(), and rb_str_new2.

Referenced by ip_s_getaddress(), sock_s_unpack_sockaddr_in(), and tcp_sockaddr().

int rsock_optname_arg ( int  family,
int  level,
VALUE  optname 
)
int rsock_revlookup_flag ( VALUE  revlookup,
int *  norevlookup 
)
VALUE rsock_s_accept ( VALUE  klass,
int  fd,
struct sockaddr *  sockaddr,
socklen_t *  len 
)
VALUE rsock_s_accept_nonblock ( VALUE  klass,
rb_io_t fptr,
struct sockaddr *  sockaddr,
socklen_t *  len 
)
VALUE rsock_s_recvfrom ( VALUE  sock,
int  argc,
VALUE argv,
enum sock_recv_type  from 
)
VALUE rsock_s_recvfrom_nonblock ( VALUE  sock,
int  argc,
VALUE argv,
enum sock_recv_type  from 
)
VALUE rsock_send_blocking ( void *  data)

Definition at line 82 of file init.c.

References arg, rsock_send_arg::fd, rsock_send_arg::flags, rsock_send_arg::mesg, RSTRING_LEN, and RSTRING_PTR.

Referenced by rsock_bsock_send().

VALUE rsock_sendto_blocking ( void *  data)
int rsock_shutdown_how_arg ( VALUE  how)

Definition at line 131 of file constants.c.

References constant_arg().

Referenced by bsock_shutdown().

VALUE rsock_sock_listen ( VALUE  sock,
VALUE  log 
)
VALUE rsock_sock_s_socketpair ( int  argc,
VALUE argv,
VALUE  klass 
)
VALUE rsock_sockaddr_string_value ( volatile VALUE )

Definition at line 2138 of file raddrinfo.c.

References addrinfo_to_sockaddr(), IS_ADDRINFO, StringValue, v, and val.

Referenced by rsock_sockaddr_string_value_ptr().

char* rsock_sockaddr_string_value_ptr ( volatile VALUE )

Definition at line 2149 of file raddrinfo.c.

References rsock_sockaddr_string_value(), and RSTRING_PTR.

int rsock_socket ( int  domain,
int  type,
int  proto 
)

Definition at line 276 of file init.c.

References errno, rb_gc(), rb_update_max_fd(), and rsock_socket0().

Referenced by init_inetsock_internal(), sock_initialize(), and udp_init().

VALUE rsock_sockopt_new ( int  family,
int  level,
int  optname,
VALUE  data 
)
int rsock_socktype_arg ( VALUE  type)

Variable Documentation

VALUE rb_cAddrinfo

Definition at line 23 of file init.c.

Referenced by rsock_addrinfo_new(), and rsock_init_addrinfo().

VALUE rb_cBasicSocket
VALUE rb_cIPSocket

Definition at line 14 of file init.c.

Referenced by rsock_init_ipsocket(), rsock_init_tcpsocket(), and rsock_init_udpsocket().

VALUE rb_cSocket
VALUE rb_cSockOpt

Definition at line 3 of file option.c.

Referenced by rsock_init_sockopt(), and rsock_sockopt_new().

VALUE rb_cTCPServer

Definition at line 16 of file init.c.

Referenced by rsock_init_tcpserver().

VALUE rb_cTCPSocket
VALUE rb_cUDPSocket

Definition at line 17 of file init.c.

Referenced by rsock_init_udpsocket().

VALUE rb_eSocket
int rsock_do_not_reverse_lookup