<commit_before>/* copyright (c) 2014 <NAME> <<EMAIL>> */

/* the functions in this file handle the whole "receiving" thing */

#include "net.h"



int main(int argc, char* argv[])
{
    int datafd, controlfd;
    ssize_t rval, rval_send;
    uint8_t statusbyte;
    uint8_t *buf;
    size_t bufsize;

    if (argc != 5) {
        fprintf(stderr, "usage: %s chunksize host dataport controlport\nchunksize is in bytes\n", argv[0]);
        exit(10);
    }
    bufsize = (size_t) atol(argv[1]);
    buf = malloc(bufsize);
    assert(buf != NULL);

    controlfd = make_socket(argv[2], argv[4]);
    sleep(1);

    while (1) {
        rval = read(controlfd, &statusbyte, 1);

        if (rval != 1) {
            perror("read on controlfd");
            exit(1);
        }

        if (statusbyte == DONE) {
            fprintf(stderr, "received DONE\n");
            break;
        }

        assert (statusbyte == CONT);

        datafd = make_socket(argv[2], argv[3]);
        rval = read_all(datafd, buf, bufsize);

        if (rval == -1) {
            perror("read on datafd");
            exit(1);
        }

        if (rval == 0) { /* eof on datafd */
            fprintf(stderr, "unexpected EOF on datafd\n");
            exit(1);
        }

        rval_send = write_all(1, buf, (size_t)rval);

        if (rval_send != rval) {
            perror("write on stdout");
            exit(1);
        }

        close(datafd);
    }

    close(controlfd);

    return 0;
}<commit_msg>show total bytes transferred and time it took.<commit_after>/* copyright (c) 2014 <NAME> <<EMAIL>> */

/* the functions in this file handle the whole "receiving" thing */

#include "net.h"
#include <sys/time.h>



int main(int argc, char* argv[])
{
    int datafd, controlfd;
    ssize_t rval, rval_send;
    uint8_t statusbyte;
    uint8_t *buf;
    size_t bufsize, totalsize = 0;
    struct timeval start, end;
    float elapsed;

    if (argc != 5) {
        fprintf(stderr, "usage: %s chunksize host dataport controlport\nchunksize is in bytes\n", argv[0]);
        exit(10);
    }
    bufsize = (size_t) atol(argv[1]);
    buf = malloc(bufsize);
    assert(buf != NULL);

    controlfd = make_socket(argv[2], argv[4]);
    sleep(1);
    gettimeofday(&start, NULL);

    while (1) {
        rval = read(controlfd, &statusbyte, 1);

        if (rval != 1) {
            perror("read on controlfd");
            exit(1);
        }

        if (statusbyte == DONE) {
            fprintf(stderr, "received DONE\n");
            gettimeofday(&end, NULL);
            elapsed = (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000;
            fprintf(stderr, "transferred %zu bytes in %.3f seconds\n", totalsize, elapsed);

            break;
        }

        assert (statusbyte == CONT);

        datafd = make_socket(argv[2], argv[3]);
        rval = read_all(datafd, buf, bufsize);

        if (rval == -1) {
            perror("read on datafd");
            exit(1);
        }

        if (rval == 0) { /* eof on datafd */
            fprintf(stderr, "unexpected EOF on datafd\n");
            exit(1);
        }

        rval_send = write_all(1, buf, (size_t)rval);

        if (rval_send != rval) {
            perror("write on stdout");
            exit(1);
        }

        totalsize += (size_t) rval;
        close(datafd);
    }

    close(controlfd);

    return 0;
}
{'fraction_non_alphanumeric': 0.14243498817966904, 'fraction_numerical': 0.018617021276595744, 'mean_word_length': 1.9332755632582321, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3157595', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1140, 'n_words': 289}