Class: DS9::Server

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

Instance Method Summary collapse

Methods inherited from Session

#initialize, #last_proc_stream_id, #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_headers(stream_id, headers) ⇒ Object



881
882
883
884
885
886
887
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
# File 'ext/ds9/ds9.c', line 881

static VALUE server_submit_headers(VALUE self, VALUE stream_id, VALUE headers) {
    nghttp2_session *session;
    size_t niv;
    nghttp2_nv *nva;
    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);
      UNREACHABLE;
    }

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

    copy_func(headers, nva, niv);

    /* nghttp2_submit_headers is too low level API for ds9 */
    rv = nghttp2_submit_response(session, NUM2INT(stream_id), nva, niv, NULL);

    xfree(nva);

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

    return self;
}

#submit_push_promise(stream_id, headers) ⇒ Object



966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
# File 'ext/ds9/ds9.c', line 966

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



837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
# File 'ext/ds9/ds9.c', line 837

static VALUE server_submit_response(VALUE self, VALUE stream_id, VALUE headers)
{
    nghttp2_session *session;
    size_t niv;
    nghttp2_nv *nva;
    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);
      UNREACHABLE;
    }

    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



706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'ext/ds9/ds9.c', line 706

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



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
498
499
500
501
502
503
504
505
506
507
508
509
# File 'ext/ds9/ds9.c', line 468

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);
      UNREACHABLE;
    }

    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;
}