#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int makeSocket() { int sockfd; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket failed"); exit(EXIT_FAILURE); } return sockfd; } void connectTo(int sock, const char* host, int port) { struct sockaddr_in serv_addr; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = inet_addr(host); serv_addr.sin_port = htons(port); if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { perror("Connection failed"); exit(EXIT_FAILURE); } printf("Connected to %s: %d\n", host, port); } int main(int argc, char* argv[]) { if (argc != 2) { printf("Usage: ./prov.out timeout (ms)"); exit(EXIT_FAILURE); } int timeout = atoi(argv[1]); //printf("Selected timeout: %f", static_cast(timeout) / 1000); int socket = makeSocket(); connectTo(socket, "127.0.0.1", 7777); //allocating 100 megabytes of memory uint64_t* chunky_boy = new uint64_t[67108]; size_t chunky_boy_size = 67108 * sizeof(uint64_t); printf("chonky size %d", static_cast(chunky_boy_size)); //setting memory to verify non-emptyness memset(chunky_boy, 45678, chunky_boy_size); int buffer_size = 1024 * 32; for ( ;;) { for ( int j = 0; j < chunky_boy_size; ) { ssize_t bytes = send(socket, reinterpret_cast(chunky_boy) + j, std::min(static_cast(chunky_boy_size) - j, buffer_size), 0); if (timeout != 0) { sleep(timeout); } j += buffer_size; } //usleep(1000); } return 0; }