Guest User

Untitled

a guest
Dec 16th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. struct bsd_pollfd {
  2. int fd;
  3. short events;
  4. short revents;
  5. };
  6.  
  7. #define BSD_POLLIN 0x0001
  8.  
  9. int bsd_poll(struct bsd_pollfd *fds, int nfds, int timeout) {
  10. result_t r;
  11.  
  12. int32_t raw[] = {nfds, timeout};
  13.  
  14. ipc_buffer_t fds_in = {
  15. .addr = fds,
  16. .size = sizeof(struct bsd_pollfd) * nfds,
  17. .type = 0x21
  18. };
  19.  
  20. ipc_buffer_t fds_out = {
  21. .addr = fds,
  22. .size = sizeof(struct bsd_pollfd) * nfds,
  23. .type = 0x22
  24. };
  25.  
  26. ipc_buffer_t *buffers[] = {
  27. &fds_in,
  28. &fds_out,
  29. };
  30.  
  31. ipc_request_t rq = ipc_default_request;
  32. rq.request_id = 6;
  33. rq.raw_data = (uint32_t*)raw;
  34. rq.raw_data_size = sizeof(raw);
  35. rq.num_buffers = 2;
  36. rq.buffers = buffers;
  37.  
  38. int32_t response[2]; // ret, errno
  39.  
  40. ipc_response_fmt_t rs = ipc_default_response_fmt;
  41. rs.raw_data_size = sizeof(response);
  42. rs.raw_data = (uint32_t*) response;
  43.  
  44. r = ipc_send(bsd_object, &rq, &rs);
  45. if(r) {
  46. bsd_result = r;
  47. return -1;
  48. }
  49.  
  50. if(response[0] < 0) {
  51. bsd_result = LIBTRANSISTOR_ERR_BSD_ERRNO_SET;
  52. bsd_errno = response[1];
  53. return -1;
  54. }
  55.  
  56. return response[0];
  57. }
Add Comment
Please, Sign In to add comment