Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <xs.h>
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <assert.H>
- #include <sys/select.h>
- #define ENDPOINT "tcp://127.0.0.1:5555"
- int main()
- {
- void *ctx = xs_init();
- void *s1 = xs_socket(ctx, XS_XREQ);
- void *s2 = xs_socket(ctx, XS_XREP);
- int rc;
- char buffer[20] = "Hello !";
- assert( xs_bind(s1, ENDPOINT) >= 0 );
- assert( xs_connect(s2, ENDPOINT) >= 0 );
- sleep(1);
- assert( xs_send(s1, buffer, strlen(buffer) + 1, 0) >= 0 );
- int fd;
- size_t fd_size = sizeof(fd);
- assert( xs_getsockopt(s2, XS_FD, &fd, &fd_size) >= 0 );
- fd_set rset;
- FD_ZERO(&rset);
- FD_SET(fd, &rset);
- assert( select(fd + 1, &rset, NULL, NULL, NULL) > 0 );
- printf("set ? %d\n", FD_ISSET(fd, &rset));
- xs_close(s1);
- xs_close(s2);
- xs_term(ctx);
- return 0;
- }
Add Comment
Please, Sign In to add comment