Пример #1
0
/*
 * Performs the network I/O.
 */
static void exec_io(struct Connection *connection)
{
  int rv;
  rv = spdylay_session_recv(connection->session);
  if(rv != 0) {
    diec("spdylay_session_recv", rv);
  }
  rv = spdylay_session_send(connection->session);
  if(rv != 0) {
    diec("spdylay_session_send", rv);
  }
}
Пример #2
0
/*
 * Performs the network I/O.
 */
int
spdy_exec_io(struct SPDY_Connection *connection)
{
  int rv;

  rv = spdylay_session_recv(connection->session);
  if(rv != 0)
  {
    PRINT_INFO2("spdylay_session_recv %i", rv);
    return rv;
  }
  rv = spdylay_session_send(connection->session);
  if(rv != 0)
    PRINT_INFO2("spdylay_session_send %i", rv);

  return rv;
}
Пример #3
0
static void run_spdylay_session_recv(void)
{
  spdylay_session *session;
  spdylay_session_callbacks callbacks;
  spdylay_zlib deflater;
  spdylay_frame frame;
  uint8_t *buf = NULL, *nvbuf = NULL;
  size_t buflen = 0, nvbuflen = 0;
  ssize_t framelen;
  const char *nv[] = { ":host", "example.org",
                       ":scheme", "https",
                       NULL };
  spdylay_settings_entry iv[2];
  spdylay_mem_chunk proof;
  spdylay_mem_chunk *certs;
  size_t ncerts;
  my_user_data ud;
  data_feed df;
  int rv;

  memset(&callbacks, 0, sizeof(spdylay_session_callbacks));
  callbacks.recv_callback = data_feed_recv_callback;
  ud.df = &df;

  spdylay_failmalloc_pause();
  spdylay_zlib_deflate_hd_init(&deflater, SPDYLAY_PROTO_SPDY3);
  spdylay_session_server_new(&session, SPDYLAY_PROTO_SPDY3, &callbacks, &ud);
  spdylay_failmalloc_unpause();

  /* SYN_STREAM */
  spdylay_failmalloc_pause();
  spdylay_frame_syn_stream_init(&frame.syn_stream, SPDYLAY_PROTO_SPDY3,
                                SPDYLAY_CTRL_FLAG_FIN, 1, 0, 2,
                                spdylay_frame_nv_copy(nv));
  framelen = spdylay_frame_pack_syn_stream(&buf, &buflen,
                                           &nvbuf, &nvbuflen,
                                           &frame.syn_stream, &deflater);
  spdylay_frame_syn_stream_free(&frame.syn_stream);
  data_feed_init(&df, buf, framelen);
  spdylay_failmalloc_unpause();

  rv = spdylay_session_recv(session);
  if(rv != 0) {
    goto fail;
  }

  /* PING */
  spdylay_failmalloc_pause();
  spdylay_frame_ping_init(&frame.ping, SPDYLAY_PROTO_SPDY3, 1);
  framelen = spdylay_frame_pack_ping(&buf, &buflen, &frame.ping);
  spdylay_frame_ping_free(&frame.ping);
  data_feed_init(&df, buf, framelen);
  spdylay_failmalloc_unpause();

  rv = spdylay_session_recv(session);
  if(rv != 0) {
    goto fail;
  }

  /* RST_STREAM */
  spdylay_failmalloc_pause();
  spdylay_frame_rst_stream_init(&frame.rst_stream, SPDYLAY_PROTO_SPDY3, 1,
                                SPDYLAY_PROTOCOL_ERROR);
  framelen = spdylay_frame_pack_rst_stream(&buf, &buflen, &frame.rst_stream);
  spdylay_frame_rst_stream_free(&frame.rst_stream);
  spdylay_failmalloc_unpause();

  rv = spdylay_session_recv(session);
  if(rv != 0) {
    goto fail;
  }

  /* SETTINGS */
  spdylay_failmalloc_pause();
  iv[0].settings_id = SPDYLAY_SETTINGS_UPLOAD_BANDWIDTH;
  iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_PERSIST_VALUE;
  iv[0].value = 256;
  iv[1].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS;
  iv[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE;
  iv[1].value = 100;
  spdylay_frame_settings_init(&frame.settings, SPDYLAY_PROTO_SPDY3,
                              SPDYLAY_FLAG_SETTINGS_CLEAR_SETTINGS,
                              spdylay_frame_iv_copy(iv, 2), 2);
  framelen = spdylay_frame_pack_settings(&buf, &buflen, &frame.settings);
  spdylay_frame_settings_free(&frame.settings);
  spdylay_failmalloc_unpause();

  rv = spdylay_session_recv(session);
  if(rv != 0) {
    goto fail;
  }

  /* CREDENTIAL */
  spdylay_failmalloc_pause();
  proof.data = (uint8_t*)strcopy("PROOF");
  proof.length = strlen("PROOF");
  ncerts = 2;
  certs = malloc(sizeof(spdylay_mem_chunk)*ncerts);
  certs[0].data = (uint8_t*)strcopy("CERT0");
  certs[0].length = strlen("CERT0");
  certs[1].data = (uint8_t*)strcopy("CERT1");
  certs[1].length = strlen("CERT1");
  spdylay_frame_credential_init(&frame.credential, SPDYLAY_PROTO_SPDY3,
                                1, &proof, certs, ncerts);
  framelen = spdylay_frame_pack_credential(&buf, &buflen, &frame.credential);
  spdylay_frame_credential_free(&frame.credential);
  spdylay_failmalloc_unpause();

  rv = spdylay_session_recv(session);
  if(rv != 0) {
    goto fail;
  }

 fail:
  free(buf);
  free(nvbuf);
  spdylay_session_del(session);
  spdylay_zlib_deflate_free(&deflater);
}