6 #include <sys/select.h>
9 #define sint64_t int64_t
11 #include "v3_user_keyed_stream.h"
15 fprintf(stderr,"v3_user_keyed_stream_example /dev/v3-vm0 user:mystreamtype:mystream busywait|select\n");
19 int do_work(struct palacios_user_keyed_stream_op *req,
20 struct palacios_user_keyed_stream_op **resp)
26 // Process request here
28 // req->len : total structure length
29 // req->type : request type (currently open/close key and read/write key
31 // req->user_key : the opaque key previously provided by you by an open key
32 // req->buf_len : length of data
33 // req->buf : buffer (contains key name (open key) or value (write key))
36 // now built a response
37 *resp = malloc(sizeof(struct palacios_user_keyed_stream_op) + datasize);
39 fprintf(stderr, "ERROR: could not allocate space for response\n");
43 (*resp)->len = sizeof(struct palacios_user_keyed_stream_op) + datasize;
44 (*resp)->buf_len = datasize;
45 (*resp)->type = req->type;
46 (*resp)->user_key = req->user_key;
51 // resp->len : total structure length
52 // resp->type : response type - must match the request
53 // resp->xfer : contains the size of data read or written (in read key or write key)
54 // resp->user_key : unused
55 // resp->buf_len : length of data following
56 // resp->buf : buffer (contains the data (read key))
62 int main(int argc, char *argv[])
75 mode = argv[3][0]=='s';
77 // The URL should begin with user:
78 // the remainder can be used to demultiplex internally
79 // for example user:file:foo might refer to a user-side file-based implementation
82 if (strncmp(url,"user:",5)) {
83 fprintf(stderr, "URL %s is not a user: url\n");
87 fprintf(stderr,"Attempting to attach to vm %s as url %s\n", vm, url);
89 if ((devfd = v3_user_keyed_stream_attach(vm,url))<0) {
90 perror("failed to attach");
94 fprintf(stderr,"Attachment succeeded, I will now operate in %s mode\n", mode==0 ? "busywait" : "select");
99 struct palacios_user_keyed_stream_op *req;
100 struct palacios_user_keyed_stream_op *resp;
104 while (!(v3_user_keyed_stream_have_request(devfd))) {
106 v3_user_keyed_stream_pull_request(devfd, &req);
110 v3_user_keyed_stream_push_response(devfd, resp);
117 struct palacios_user_keyed_stream_op *req;
118 struct palacios_user_keyed_stream_op *resp;
123 // select-based operation so that you can wait for multiple things
127 FD_SET(devfd,&readset);
129 rc = select(devfd+1, &readset, 0, 0, 0); // pick whatever you want to select on, just include devfd
132 if (FD_ISSET(devfd,&readset)) {
133 // a request is read for us!
134 v3_user_keyed_stream_pull_request(devfd, &req);
138 v3_user_keyed_stream_push_response(devfd, resp);
147 v3_user_keyed_stream_detatch(devfd);