method
marshal_load
Ruby latest stable (v2_5_5)
-
0 notes -
Class: Addrinfo
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180 (0)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
marshal_load(p1)
public
Hide source
static VALUE addrinfo_mload(VALUE self, VALUE ary) { VALUE v; VALUE canonname, inspectname; int afamily, pfamily, socktype, protocol; union_sockaddr ss; socklen_t len; rb_addrinfo_t *rai; if (check_addrinfo(self)) rb_raise(rb_eTypeError, "already initialized socket address"); ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary"); v = rb_ary_entry(ary, 0); StringValue(v); if (rsock_family_to_int(RSTRING_PTR(v), RSTRING_LEN(v), &afamily) == -1) rb_raise(rb_eTypeError, "unexpected address family"); v = rb_ary_entry(ary, 2); StringValue(v); if (rsock_family_to_int(RSTRING_PTR(v), RSTRING_LEN(v), &pfamily) == -1) rb_raise(rb_eTypeError, "unexpected protocol family"); v = rb_ary_entry(ary, 3); if (v == INT2FIX(0)) socktype = 0; else { StringValue(v); if (rsock_socktype_to_int(RSTRING_PTR(v), RSTRING_LEN(v), &socktype) == -1) rb_raise(rb_eTypeError, "unexpected socktype"); } v = rb_ary_entry(ary, 4); if (v == INT2FIX(0)) protocol = 0; else { StringValue(v); if (IS_IP_FAMILY(afamily)) { if (rsock_ipproto_to_int(RSTRING_PTR(v), RSTRING_LEN(v), &protocol) == -1) rb_raise(rb_eTypeError, "unexpected protocol"); } else { rb_raise(rb_eTypeError, "unexpected protocol"); } } v = rb_ary_entry(ary, 5); if (NIL_P(v)) canonname = Qnil; else { StringValue(v); canonname = v; } v = rb_ary_entry(ary, 6); if (NIL_P(v)) inspectname = Qnil; else { StringValue(v); inspectname = v; } v = rb_ary_entry(ary, 1); switch(afamily) { #ifdef HAVE_SYS_UN_H case AF_UNIX: { struct sockaddr_un uaddr; INIT_SOCKADDR_UN(&uaddr, sizeof(struct sockaddr_un)); StringValue(v); if (sizeof(uaddr.sun_path) < (size_t)RSTRING_LEN(v)) rb_raise(rb_eSocket, "too long AF_UNIX path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)", (size_t)RSTRING_LEN(v), sizeof(uaddr.sun_path)); memcpy(uaddr.sun_path, RSTRING_PTR(v), RSTRING_LEN(v)); len = (socklen_t)sizeof(uaddr); memcpy(&ss, &uaddr, len); break; } #endif default: { VALUE pair = rb_convert_type(v, T_ARRAY, "Array", "to_ary"); struct rb_addrinfo *res; int flags = AI_NUMERICHOST; #ifdef AI_NUMERICSERV flags |= AI_NUMERICSERV; #endif res = call_getaddrinfo(rb_ary_entry(pair, 0), rb_ary_entry(pair, 1), INT2NUM(pfamily), INT2NUM(socktype), INT2NUM(protocol), INT2NUM(flags), 1); len = res->ai->ai_addrlen; memcpy(&ss, res->ai->ai_addr, res->ai->ai_addrlen); rb_freeaddrinfo(res); break; } } DATA_PTR(self) = rai = alloc_addrinfo(); init_addrinfo(rai, &ss.addr, len, pfamily, socktype, protocol, canonname, inspectname); return self; }