コード例 #1
0
ファイル: httpkite.c プロジェクト: andrecurvello/libpagekite
void handle_request(void* data, struct pk_chunk *chunk) {
  char buffer[4096];
  char *hi = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nHello World\n";
  struct pk_conn* pkc = data;
  int bytes;

  pk_log_chunk(chunk);
  if (chunk->ping) {
    bytes = pk_format_pong(buffer);
    pkc_write(pkc, buffer, bytes);
  }
  else if (chunk->sid) {
    if (chunk->eof) {
      /* Ignored, for now */
    }
    else if (!chunk->noop) {

      /* Send a reply, and close this channel right away */
      bytes = pk_format_reply(buffer, chunk->sid, strlen(hi), hi);
      pkc_write(pkc, buffer, bytes);

      bytes = pk_format_eof(buffer, chunk->sid, PK_EOF);
      pkc_write(pkc, buffer, bytes);
    }
  }
  else {
    /* Weirdness ... */
  }
}
コード例 #2
0
ファイル: pkproto_test.c プロジェクト: karlp/libpagekite
int pkproto_test_format_reply(void)
{
  char dest[1024];
  char* expect = "19\r\nSID: 12345\r\n\r\nHello World";
  size_t bytes = strlen(expect);
  assert(bytes == 11+pk_reply_overhead("12345", 11));
  assert(bytes == pk_format_reply(dest, "12345", 11, "Hello World"));
  assert(0 == strncmp(expect, dest, bytes));
  return 1;
}