• Main Page
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

ext/socket/rubysocket.h

Go to the documentation of this file.
00001 #ifndef RUBY_SOCKET_H
00002 #define RUBY_SOCKET_H 1
00003 
00004 #include "ruby/ruby.h"
00005 #include "ruby/io.h"
00006 #include "ruby/util.h"
00007 #include <stdio.h>
00008 #include <sys/types.h>
00009 #include <sys/stat.h>
00010 
00011 #ifdef HAVE_UNISTD_H
00012 #include <unistd.h>
00013 #endif
00014 
00015 #ifdef HAVE_SYS_UIO_H
00016 #include <sys/uio.h>
00017 #endif
00018 
00019 #ifdef HAVE_XTI_H
00020 #include <xti.h>
00021 #endif
00022 
00023 #ifndef _WIN32
00024 #if defined(__BEOS__) && !defined(__HAIKU__) && !defined(BONE)
00025 # include <net/socket.h>
00026 #else
00027 # include <sys/socket.h>
00028 #endif
00029 #include <netinet/in.h>
00030 #ifdef HAVE_NETINET_IN_SYSTM_H
00031 # include <netinet/in_systm.h>
00032 #endif
00033 #ifdef HAVE_NETINET_TCP_H
00034 # include <netinet/tcp.h>
00035 #endif
00036 #ifdef HAVE_NETINET_UDP_H
00037 # include <netinet/udp.h>
00038 #endif
00039 #ifdef HAVE_ARPA_INET_H
00040 # include <arpa/inet.h>
00041 #endif
00042 #include <netdb.h>
00043 #endif
00044 #include <errno.h>
00045 #ifdef HAVE_SYS_UN_H
00046 #include <sys/un.h>
00047 #endif
00048 
00049 #if defined(HAVE_FCNTL)
00050 #ifdef HAVE_SYS_SELECT_H
00051 #include <sys/select.h>
00052 #endif
00053 #ifdef HAVE_SYS_TYPES_H
00054 #include <sys/types.h>
00055 #endif
00056 #ifdef HAVE_SYS_TIME_H
00057 #include <sys/time.h>
00058 #endif
00059 #ifdef HAVE_FCNTL_H
00060 #include <fcntl.h>
00061 #endif
00062 #endif
00063 
00064 #ifdef HAVE_IFADDRS_H
00065 #include <ifaddrs.h>
00066 #endif
00067 #ifdef HAVE_SYS_IOCTL_H
00068 #include <sys/ioctl.h>
00069 #endif
00070 #ifdef HAVE_SYS_SOCKIO_H
00071 #include <sys/sockio.h>
00072 #endif
00073 #ifdef HAVE_NET_IF_H
00074 #include <net/if.h>
00075 #endif
00076 
00077 #ifdef HAVE_SYS_PARAM_H
00078 #include <sys/param.h>
00079 #endif
00080 #ifdef HAVE_SYS_UCRED_H
00081 #include <sys/ucred.h>
00082 #endif
00083 #ifdef HAVE_UCRED_H
00084 #include <ucred.h>
00085 #endif
00086 
00087 #ifndef EWOULDBLOCK
00088 #define EWOULDBLOCK EAGAIN
00089 #endif
00090 
00091 /*
00092  * workaround for NetBSD, OpenBSD and etc.
00093  * The problem is since 4.4BSD-Lite.
00094  * FreeBSD fix the problem at FreeBSD 2.2.0.
00095  * NetBSD fix the problem at NetBSD 3.0 by kern/29624.
00096  * OpenBSD fix the problem at OpenBSD 3.8.
00097  */
00098 #define pseudo_AF_FTIP pseudo_AF_RTIP
00099 
00100 #ifndef HAVE_GETADDRINFO
00101 #include "addrinfo.h"
00102 #endif
00103 #include "sockport.h"
00104 
00105 #ifndef NI_MAXHOST
00106 # define NI_MAXHOST 1025
00107 #endif
00108 #ifndef NI_MAXSERV
00109 # define NI_MAXSERV 32
00110 #endif
00111 
00112 #ifdef AF_INET6
00113 # define IS_IP_FAMILY(af) ((af) == AF_INET || (af) == AF_INET6)
00114 #else
00115 # define IS_IP_FAMILY(af) ((af) == AF_INET)
00116 #endif
00117 
00118 #ifndef HAVE_SOCKADDR_STORAGE
00119 /*
00120  * RFC 2553: protocol-independent placeholder for socket addresses
00121  */
00122 #define _SS_MAXSIZE     128
00123 #define _SS_ALIGNSIZE   (sizeof(double))
00124 #define _SS_PAD1SIZE    (_SS_ALIGNSIZE - sizeof(unsigned char) * 2)
00125 #define _SS_PAD2SIZE    (_SS_MAXSIZE - sizeof(unsigned char) * 2 - \
00126                                 _SS_PAD1SIZE - _SS_ALIGNSIZE)
00127 
00128 struct sockaddr_storage {
00129 #ifdef HAVE_SA_LEN
00130         unsigned char ss_len;           /* address length */
00131         unsigned char ss_family;        /* address family */
00132 #else
00133         unsigned short ss_family;
00134 #endif
00135         char    __ss_pad1[_SS_PAD1SIZE];
00136         double  __ss_align;     /* force desired structure storage alignment */
00137         char    __ss_pad2[_SS_PAD2SIZE];
00138 };
00139 #endif
00140 
00141 #if defined(_AIX)
00142 #ifndef CMSG_SPACE
00143 # define CMSG_SPACE(len) (_CMSG_ALIGN(sizeof(struct cmsghdr)) + _CMSG_ALIGN(len))
00144 #endif
00145 #ifndef CMSG_LEN
00146 # define CMSG_LEN(len) (_CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
00147 #endif
00148 #endif
00149 
00150 #ifdef __BEOS__
00151 #undef close
00152 #define close closesocket
00153 #endif
00154 
00155 #define INET_CLIENT 0
00156 #define INET_SERVER 1
00157 #define INET_SOCKS  2
00158 
00159 extern int rsock_do_not_reverse_lookup;
00160 #define FMODE_NOREVLOOKUP 0x100
00161 
00162 extern VALUE rb_cBasicSocket;
00163 extern VALUE rb_cIPSocket;
00164 extern VALUE rb_cTCPSocket;
00165 extern VALUE rb_cTCPServer;
00166 extern VALUE rb_cUDPSocket;
00167 #ifdef HAVE_SYS_UN_H
00168 extern VALUE rb_cUNIXSocket;
00169 extern VALUE rb_cUNIXServer;
00170 #endif
00171 extern VALUE rb_cSocket;
00172 extern VALUE rb_cAddrinfo;
00173 extern VALUE rb_cSockOpt;
00174 
00175 extern VALUE rb_eSocket;
00176 
00177 #ifdef SOCKS
00178 extern VALUE rb_cSOCKSSocket;
00179 #ifdef SOCKS5
00180 #include <socks.h>
00181 #else
00182 void SOCKSinit();
00183 int Rconnect();
00184 #endif
00185 #endif
00186 
00187 #include "constdefs.h"
00188 
00189 #define BLOCKING_REGION(func, arg) (long)rb_thread_blocking_region((func), (arg), RUBY_UBF_IO, 0)
00190 
00191 #define SockAddrStringValue(v) rsock_sockaddr_string_value(&(v))
00192 #define SockAddrStringValuePtr(v) rsock_sockaddr_string_value_ptr(&(v))
00193 VALUE rsock_sockaddr_string_value(volatile VALUE *);
00194 char *rsock_sockaddr_string_value_ptr(volatile VALUE *);
00195 VALUE rb_check_sockaddr_string_type(VALUE);
00196 
00197 NORETURN(void rsock_raise_socket_error(const char *, int));
00198 
00199 int rsock_family_arg(VALUE domain);
00200 int rsock_socktype_arg(VALUE type);
00201 int rsock_level_arg(int family, VALUE level);
00202 int rsock_optname_arg(int family, int level, VALUE optname);
00203 int rsock_cmsg_type_arg(int family, int level, VALUE type);
00204 int rsock_shutdown_how_arg(VALUE how);
00205 
00206 int rsock_getfamily(int sockfd);
00207 
00208 int rb_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
00209 int rb_getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
00210 struct addrinfo *rsock_addrinfo(VALUE host, VALUE port, int socktype, int flags);
00211 struct addrinfo *rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_hack);
00212 VALUE rsock_fd_socket_addrinfo(int fd, struct sockaddr *addr, socklen_t len);
00213 VALUE rsock_io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len);
00214 
00215 VALUE rsock_addrinfo_new(struct sockaddr *addr, socklen_t len, int family, int socktype, int protocol, VALUE canonname, VALUE inspectname);
00216 
00217 VALUE rsock_make_ipaddr(struct sockaddr *addr);
00218 VALUE rsock_ipaddr(struct sockaddr *sockaddr, int norevlookup);
00219 VALUE rsock_make_hostent(VALUE host, struct addrinfo *addr, VALUE (*ipaddr)(struct sockaddr *, size_t));
00220 
00221 int rsock_revlookup_flag(VALUE revlookup, int *norevlookup);
00222 
00223 #ifdef HAVE_SYS_UN_H
00224 const char* rsock_unixpath(struct sockaddr_un *sockaddr, socklen_t len);
00225 VALUE rsock_unixaddr(struct sockaddr_un *sockaddr, socklen_t len);
00226 #endif
00227 
00228 int rsock_socket(int domain, int type, int proto);
00229 VALUE rsock_init_sock(VALUE sock, int fd);
00230 VALUE rsock_sock_s_socketpair(int argc, VALUE *argv, VALUE klass);
00231 VALUE rsock_init_inetsock(VALUE sock, VALUE remote_host, VALUE remote_serv, VALUE local_host, VALUE local_serv, int type);
00232 VALUE rsock_init_unixsock(VALUE sock, VALUE path, int server);
00233 
00234 struct rsock_send_arg {
00235     int fd, flags;
00236     VALUE mesg;
00237     struct sockaddr *to;
00238     socklen_t tolen;
00239 };
00240 
00241 VALUE rsock_sendto_blocking(void *data);
00242 VALUE rsock_send_blocking(void *data);
00243 VALUE rsock_bsock_send(int argc, VALUE *argv, VALUE sock);
00244 
00245 enum sock_recv_type {
00246     RECV_RECV,                  /* BasicSocket#recv(no from) */
00247     RECV_IP,                    /* IPSocket#recvfrom */
00248     RECV_UNIX,                  /* UNIXSocket#recvfrom */
00249     RECV_SOCKET                 /* Socket#recvfrom */
00250 };
00251 
00252 VALUE rsock_s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from);
00253 VALUE rsock_s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from);
00254 
00255 int rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks);
00256 
00257 VALUE rsock_s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len);
00258 VALUE rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len);
00259 VALUE rsock_sock_listen(VALUE sock, VALUE log);
00260 
00261 VALUE rsock_sockopt_new(int family, int level, int optname, VALUE data);
00262 
00263 #if defined(HAVE_SENDMSG)
00264 VALUE rsock_bsock_sendmsg(int argc, VALUE *argv, VALUE sock);
00265 VALUE rsock_bsock_sendmsg_nonblock(int argc, VALUE *argv, VALUE sock);
00266 #else
00267 #define rsock_bsock_sendmsg rb_f_notimplement
00268 #define rsock_bsock_sendmsg_nonblock rb_f_notimplement
00269 #endif
00270 #if defined(HAVE_RECVMSG)
00271 VALUE rsock_bsock_recvmsg(int argc, VALUE *argv, VALUE sock);
00272 VALUE rsock_bsock_recvmsg_nonblock(int argc, VALUE *argv, VALUE sock);
00273 #else
00274 #define rsock_bsock_recvmsg rb_f_notimplement
00275 #define rsock_bsock_recvmsg_nonblock rb_f_notimplement
00276 #endif
00277 
00278 #ifdef HAVE_ST_MSG_CONTROL
00279 void rsock_discard_cmsg_resource(struct msghdr *mh);
00280 #endif
00281 
00282 void rsock_init_basicsocket(void);
00283 void rsock_init_ipsocket(void);
00284 void rsock_init_tcpsocket(void);
00285 void rsock_init_tcpserver(void);
00286 void rsock_init_sockssocket(void);
00287 void rsock_init_udpsocket(void);
00288 void rsock_init_unixsocket(void);
00289 void rsock_init_unixserver(void);
00290 void rsock_init_socket_constants(void);
00291 void rsock_init_ancdata(void);
00292 void rsock_init_addrinfo(void);
00293 void rsock_init_sockopt(void);
00294 void rsock_init_socket_init(void);
00295 
00296 #endif
00297 

Generated on Wed Sep 8 2010 09:55:35 for Ruby by  doxygen 1.7.1