Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void prepare_data(int32_t *data, int len)
- {
- for (int i = 0; i < len; ++i)
- {
- int val = rand() % 1000;
- data[i] = htonl(val);
- }
- }
- int main(int argc, char** argv) {
- int fd;
- int32_t data[3];
- int32_t data_recv[3];
- if(argc!=3) {
- usage(argv[0]);
- return EXIT_FAILURE;
- }
- if(sethandler(SIG_IGN,SIGPIPE)) ERR("Seting SIGPIPE:");
- prepare_data(data, 3);
- //~ for (int i = 0; i < 3; ++i)
- //~ {
- //~ //struct timeval time = {0, 750000L};
- //~ fd=connect_socket(argv[1],argv[2]);
- //~ struct timeval time = {3, 0};
- //~ fprintf(stdout, "Process [%d] sends val: %d\n", getpid(), ntohl(data[i]));
- //~ if(bulk_write(fd,(char *)&data[i],sizeof(int32_t[1]))<0) ERR("write:");
- //~ if(bulk_read(fd,(char *)&data_recv[i],sizeof(int32_t[1]))<(int)sizeof(int32_t[1])) ERR("read:");
- //~ fprintf(stdout, "Process [%d] received val: %d\n", getpid(), ntohl(data_recv[i]));
- //~ select(1, NULL, NULL, NULL, &time);
- //~ if(TEMP_FAILURE_RETRY(close(fd))<0)ERR("close");
- //~ }
- fd=connect_socket(argv[1],argv[2]);
- for (int i = 0; i < 3; ++i)
- {
- struct timeval time = {3, 0};
- fprintf(stdout, "Process [%d] sends val: %d\n", getpid(), ntohl(data[i]));
- if(send(fd, (void*) &data[i], sizeof(int32_t[1]), 0) < 0 ) ERR("send");
- if(recv(fd, (void*) &data[i], sizeof(int32_t[1]), 0) < 0) ERR("recv");
- fprintf(stdout, "Process [%d] received val: %d\n", getpid(), ntohl(data_recv[i]));
- select(1, NULL, NULL, NULL, &time);
- }
- if(TEMP_FAILURE_RETRY(close(fd))<0)ERR("close");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement