-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstreaming.c
38 lines (32 loc) · 904 Bytes
/
streaming.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "../kvm_api.h"
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
static const char data[] = "Hello Varnish World!";
static const size_t datalen = sizeof(data)-1;
static struct streaming_content
stream(void *arg, size_t max, size_t written, size_t total)
{
const char *d = (const char *)arg;
/* Write one byte at a time for maximum efficiency and performance. */
return (struct streaming_content){&d[written], 1};
}
static void
on_get(const char *url, const char *arg)
{
(void)url;
set_cacheable(false, 0.01, 0.0, 0.0);
static const char *ctype = "text/plain";
begin_streaming_response(200, ctype, strlen(ctype), datalen, stream, data);
}
int main(int argc, char **argv)
{
if (strcmp(argv[0], "vmod_kvm"))
{
puts("Hello Linux World!");
return 0;
}
set_backend_get(on_get);
wait_for_requests();
}