Class: DS9::Server

Inherits:
Session show all
Defined in:
ext/ds9/ds9.c

Instance Method Summary collapse

Methods inherited from Session

#initialize, #mem_receive, #mem_send, #outbound_queue_size, #receive, #resume_data, #send, #stream_local_closed?, #stream_remote_closed?, #submit_goaway, #submit_ping, #submit_settings, #terminate_session, #want_read?, #want_write?

Constructor Details

This class inherits a constructor from DS9::Session

Instance Method Details

#submit_push_promise(stream_id, headers) ⇒ Object



888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
# File 'ext/ds9/ds9.c', line 888

static VALUE server_submit_push_promise(VALUE self, VALUE stream_id, VALUE headers)
{
    nghttp2_session *session;
    nghttp2_nv *nva, *head;
    size_t niv, i;
    int rv;

    TypedData_Get_Struct(self, nghttp2_session, &ds9_session_type, session);
    CheckSelf(session);

    Check_Type(headers, T_ARRAY);
    niv = RARRAY_LEN(headers);
    nva = xcalloc(niv, sizeof(nghttp2_nv));
    head = nva;

    for(i = 0; i < niv; i++, head++) {
	VALUE tuple = rb_ary_entry(headers, (long)i);
	VALUE name = rb_ary_entry(tuple, 0);
	VALUE value = rb_ary_entry(tuple, 1);

	head->name = (uint8_t *)StringValuePtr(name);
	head->namelen = RSTRING_LEN(name);

	head->value = (uint8_t *)StringValuePtr(value);
	head->valuelen = RSTRING_LEN(value);
	head->flags = NGHTTP2_NV_FLAG_NONE;
    }

    rv = nghttp2_submit_push_promise(session, 0, NUM2INT(stream_id), nva, niv, NULL);

    xfree(nva);

    switch(rv) {
	case NGHTTP2_ERR_NOMEM:
	case NGHTTP2_ERR_PROTO:
	case NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE:
	case NGHTTP2_ERR_INVALID_ARGUMENT:
	    return explode(rv);
	    break;
	default:
	    return INT2NUM(rv);
    }
}

#submit_response(stream_id, headers) ⇒ Object



801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
# File 'ext/ds9/ds9.c', line 801

static VALUE server_submit_response(VALUE self, VALUE stream_id, VALUE headers)
{
    nghttp2_session *session;
    size_t niv;
    nghttp2_nv *nva, *head;
    nghttp2_data_provider provider;
    int rv;
    copy_header_func_t copy_func;

    TypedData_Get_Struct(self, nghttp2_session, &ds9_session_type, session);
    CheckSelf(session);

    switch(TYPE(headers))
    {
	case T_ARRAY:
	    niv = RARRAY_LEN(headers);
	    copy_func = copy_list_to_nv;
	    break;
	case T_HASH:
	    niv = RHASH_SIZE(headers);
	    copy_func = copy_hash_to_nv;
	    break;
	default:
	    Check_Type(headers, T_ARRAY);
    }

    nva = xcalloc(niv, sizeof(nghttp2_nv));

    copy_func(headers, nva, niv);

    provider.read_callback = rb_data_read_callback;

    rv = nghttp2_submit_response(session, NUM2INT(stream_id), nva, niv, &provider);

    xfree(nva);

    if (0 != rv) {
	explode(rv);
    }

    return self;
}

#submit_shutdownObject



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
# File 'ext/ds9/ds9.c', line 683

static VALUE session_submit_shutdown(VALUE self)
{
    int rv;
    nghttp2_session *session;

    TypedData_Get_Struct(self, nghttp2_session, &ds9_session_type, session);
    CheckSelf(session);

    rv = nghttp2_submit_shutdown_notice(session);

    if (rv == 0)
	return Qtrue;

    return explode(rv);
}

#submit_trailer(stream_id, trailers) ⇒ Object



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'ext/ds9/ds9.c', line 457

static VALUE session_submit_trailer(VALUE self, VALUE stream_id, VALUE trailers)
{
    size_t niv;
    nghttp2_nv *nva;
    nghttp2_session *session;
    int rv;
    int32_t s_id;
    copy_header_func_t copy_func;

    TypedData_Get_Struct(self, nghttp2_session, &ds9_session_type, session);
    CheckSelf(session);

    s_id = NUM2INT(stream_id);

    switch(TYPE(trailers))
    {
	case T_ARRAY:
	    niv = RARRAY_LEN(trailers);
	    copy_func = copy_list_to_nv;
	    break;
	case T_HASH:
	    niv = RHASH_SIZE(trailers);
	    copy_func = copy_hash_to_nv;
	    break;
	default:
	    Check_Type(trailers, T_ARRAY);
    }

    nva = xcalloc(niv, sizeof(nghttp2_nv));
    copy_func(trailers, nva, niv);

    rv = nghttp2_submit_trailer(session, s_id, nva, niv);

    xfree(nva);

    if (0 != rv) {
	explode(rv);
    }

    return self;
}