test-socket-signal: update receive process
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sun, 24 Oct 2010 14:33:41 +0000 (17:33 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sun, 24 Oct 2010 14:33:41 +0000 (17:33 +0300)
Utils/test-socket-signal/peer.c

index 649660d..8895c19 100644 (file)
@@ -69,7 +69,7 @@ static struct {
        .frequency = DEFAULT_FREQUENCY
 };
 
-static char rcv_buf[RECEIVE_BUFFER_SIZE];
+static char *rcv_buf;
 static char *snd_buf;
 
 /* connection socket */
@@ -90,12 +90,13 @@ static void init_buffer_random(char *buf, size_t len)
 
 static void init_buffers(void)
 {
-       init_buffer_random(rcv_buf, RECEIVE_BUFFER_SIZE);
+       init_buffer_random(rcv_buf, cmd_args.peer_buffer_size);
        init_buffer_random(snd_buf, PACKET_PAYLOAD_SIZE);
 }
 
 static void init(void)
 {
+       rcv_buf = malloc(cmd_args.peer_buffer_size * sizeof(char));
        snd_buf = malloc(PACKET_SIZE * sizeof(char));
        DIE(snd_buf == NULL, "malloc");
 
@@ -104,6 +105,7 @@ static void init(void)
 
 static void cleanup(void)
 {
+       free(rcv_buf);
        free(snd_buf);
 }
 
@@ -135,7 +137,7 @@ static ssize_t receive_buffer(int sockfd)
        ssize_t n;
 
        while (nbytes < (ssize_t) cmd_args.peer_buffer_size) {
-               n = recv(sockfd, rcv_buf, RECEIVE_BUFFER_SIZE, 0);
+               n = recv(sockfd, rcv_buf, cmd_args.peer_buffer_size - nbytes, 0);
                if (n <= 0)
                        break;
                nbytes += n;