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 ... */ } }
int pkproto_test_format_pong(void) { char dest[1024]; char* expect = "b\r\nNOOP: 1\r\n\r\n"; size_t bytes = strlen(expect); assert(bytes == pk_format_pong(dest)); assert(0 == strncmp(expect, dest, bytes)); return 1; }