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);
38 (*resp)->len = sizeof(struct palacios_user_keyed_stream_op) + datasize;
39 (*resp)->buf_len = datasize;
40 (*resp)->type = req->type;
41 (*resp)->user_key = req->user_key;
46 // resp->len : total structure length
47 // resp->type : response type - must match the request
48 // resp->xfer : contains the size of data read or written (in read key or write key)
49 // resp->user_key : unused
50 // resp->buf_len : length of data following
51 // resp->buf : buffer (contains the data (read key))
57 int main(int argc, char *argv[])
70 mode = argv[3][0]=='s';
72 // The URL should begin with user:
73 // the remainder can be used to demultiplex internally
74 // for example user:file:foo might refer to a user-side file-based implementation
77 if (strncmp(url,"user:",5)) {
78 fprintf(stderr, "URL %s is not a user: url\n");
82 fprintf(stderr,"Attempting to attach to vm %s as url %s\n", vm, url);
84 if ((devfd = v3_user_keyed_stream_attach(vm,url))<0) {
85 perror("failed to attach");
89 fprintf(stderr,"Attachment succeeded, I will now operate in %s mode\n", mode==0 ? "busywait" : "select");
94 struct palacios_user_keyed_stream_op *req;
95 struct palacios_user_keyed_stream_op *resp;
99 while (!(v3_user_keyed_stream_have_request(devfd))) {
101 v3_user_keyed_stream_pull_request(devfd, &req);
105 v3_user_keyed_stream_push_response(devfd, resp);
112 struct palacios_user_keyed_stream_op *req;
113 struct palacios_user_keyed_stream_op *resp;
118 // select-based operation so that you can wait for multiple things
122 FD_SET(devfd,&readset);
124 rc = select(devfd+1, &readset, 0, 0, 0); // pick whatever you want to select on, just include devfd
127 if (FD_ISSET(devfd,&readset)) {
128 // a request is read for us!
129 v3_user_keyed_stream_pull_request(devfd, &req);
133 v3_user_keyed_stream_push_response(devfd, resp);
142 v3_user_keyed_stream_detatch(devfd);