]> git.sesse.net Git - jam/blobdiff - jam.c
EINTR, not EAGAIN.
[jam] / jam.c
diff --git a/jam.c b/jam.c
index c1f9bb17adc729cca87bcbaef4cc82ff4d767432..9eab9c9cfd57d7b0b63859e7c049f016e184e639 100644 (file)
--- a/jam.c
+++ b/jam.c
@@ -42,6 +42,7 @@ const static struct option longopts[] = {
        { "destination-list", required_argument, NULL, 'd' },
        { "num-senders", required_argument, NULL, 'n' },
        { "num-sockets-per-sender", required_argument, NULL, 'N' },
+       { "num-receivers", required_argument, NULL, 'r' },
        { "port", required_argument, NULL, 'p' },
        { "sender-only", no_argument, NULL, 'o' },
        { NULL, 0, NULL, 0 }
@@ -119,7 +120,7 @@ void parse_options(int argc, char **argv)
        int option_index = 0;
 
        for ( ;; ) {
-               int c = getopt_long(argc, argv, "s:d:n:N:p:o", longopts, &option_index); 
+               int c = getopt_long(argc, argv, "s:d:n:N:r:p:o", longopts, &option_index); 
                switch (c) {
                case 's':
                        read_ip_list(optarg, &sources, &num_sources, &room_sources);
@@ -130,6 +131,9 @@ void parse_options(int argc, char **argv)
                case 'n':
                        num_senders = atoi(optarg);
                        break;
+               case 'r':
+                       num_receivers = atoi(optarg);
+                       break;
                case 'N':
                        num_sockets_per_sender = atoi(optarg);
                        break;
@@ -241,6 +245,8 @@ void *sender_worker(void *arg)
        for ( ;; ) {
                int num_active = epoll_wait(ep_fd, events, num_sockets_per_sender, -1);
                if (num_active == -1) {
+                       if (errno == EINTR)
+                               continue;
                        perror("epoll_wait");
                        exit(1);
                }
@@ -256,7 +262,7 @@ void *sender_worker(void *arg)
 
                        ret = send(s->fd, buf, bytes_to_send, MSG_NOSIGNAL);
                        if (ret == -1) {
-                               if (errno == EAGAIN)
+                               if (errno == EAGAIN || errno == EINTR)
                                        continue;
 
                                perror("send()");
@@ -278,7 +284,7 @@ void *sender_worker(void *arg)
                        
                        if (s->bytes_left == 0) {
                                if (epoll_ctl(ep_fd, EPOLL_CTL_DEL, s->fd, NULL) == -1) {
-                                       perror("EPOLL_CTL_ADD");
+                                       perror("EPOLL_CTL_DEL");
                                        exit(1);
                                }
                                close(s->fd);
@@ -330,6 +336,8 @@ void *receiver_worker(void *arg)
        for ( ;; ) {
                int num_active = epoll_wait(ep_fd, events, epoll_room_in_receiver, -1);
                if (num_active == -1) {
+                       if (errno == EINTR)
+                               continue;
                        perror("epoll_wait");
                        exit(1);
                }
@@ -344,7 +352,7 @@ void *receiver_worker(void *arg)
 
                                sock = accept(server_sock, (struct sockaddr *)&addr, &addr_len);
                                if (sock == -1) {
-                                       if (errno == EAGAIN) {
+                                       if (errno == EAGAIN || errno == EINTR) {
                                                // another thread snatched it, ignore
                                                continue;
                                        } else {
@@ -366,13 +374,11 @@ void *receiver_worker(void *arg)
 
                        ret = read(sock, buf, 65536);
                        if (ret == 0) {
-                               close(sock);
-                               
                                if (epoll_ctl(ep_fd, EPOLL_CTL_DEL, sock, NULL) == -1) {
-                                       perror("EPOLL_CTL_ADD");
+                                       perror("EPOLL_CTL_DEL");
                                        exit(1);
                                }
-
+                               close(sock);
                                continue;
                        }
 
@@ -430,6 +436,8 @@ void *receiver_dispatcher(void *arg)
                        exit(1);
                }
        }
+
+       return NULL;
 }
 
 int get_server_socket(unsigned short port)