Guest User

Untitled

a guest
Oct 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <xs.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <assert.H>
  6. #include <sys/select.h>
  7.  
  8. #define ENDPOINT "tcp://127.0.0.1:5555"
  9.  
  10. int main()
  11. {
  12. void *ctx = xs_init();
  13. void *s1 = xs_socket(ctx, XS_XREQ);
  14. void *s2 = xs_socket(ctx, XS_XREP);
  15. int rc;
  16. char buffer[20] = "Hello !";
  17.  
  18. assert( xs_bind(s1, ENDPOINT) >= 0 );
  19. assert( xs_connect(s2, ENDPOINT) >= 0 );
  20.  
  21.  
  22. sleep(1);
  23. assert( xs_send(s1, buffer, strlen(buffer) + 1, 0) >= 0 );
  24.  
  25. int fd;
  26. size_t fd_size = sizeof(fd);
  27. assert( xs_getsockopt(s2, XS_FD, &fd, &fd_size) >= 0 );
  28.  
  29.  
  30. fd_set rset;
  31. FD_ZERO(&rset);
  32. FD_SET(fd, &rset);
  33.  
  34. assert( select(fd + 1, &rset, NULL, NULL, NULL) > 0 );
  35. printf("set ? %d\n", FD_ISSET(fd, &rset));
  36.  
  37. xs_close(s1);
  38. xs_close(s2);
  39. xs_term(ctx);
  40. return 0;
  41. }
Add Comment
Please, Sign In to add comment