rselect() timeout only happens once on SoftiWARP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



System information
Linux Distribution:    Ubuntu 20.04 LTS
Kernel Version: 5.4.0-33-generic
InfiniBand Hardware: SoftiWARP
modinfo siw:
filename:       /lib/modules/5.4.0-33-generic/kernel/drivers/infiniband/sw/siw/siw.ko
alias:          rdma-link-siw
license:        Dual BSD/GPL
description:    Software iWARP Driver
author:         Bernard Metzler
srcversion:     5450ABB35545870E9970346
depends:        ib_core,libcrc32c
retpoline:      Y
intree:         Y
name:           siw
gcc version: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0

Steps to Reproduce
Compile and run rsever.c and rclient.c. (gcc -o rclient rclient.c -lrdmacm)
Press enter on client side after 10 sec, and again after 10sec...

Expected behaviour (behaviour for server.c and client.c): 
Waiting for connection on port 12345...
Client connected. Waiting for data...
Timeout: No data received in 5 seconds.
Timeout: No data received in 5 seconds..
Received: Hello from RDMA client!
Timeout: No data received in 5 seconds.
Timeout: No data received in 5 seconds..
Received: Hello from RDMA client!
Timeout: No data received in 5 seconds.
...
Actual behaviour:
      Waiting for connection on port 12345...
Client connected. Waiting for data...
Timeout: No data received in 5 seconds.
Received: Hello from RDMA client!
Received: Hello from RDMA client!
...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rdma/rsocket.h>

#define PORT 12345
#define TIMEOUT_SEC 5
#define BUFFER_SIZE 1024

int main() {
    int server_fd, client_fd;
    struct sockaddr_in addr;
    char buffer[BUFFER_SIZE];
    fd_set read_fds;
    struct timeval timeout;

    // Create an RSocket (RDMA socket)
    if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        perror("rsocket");
        return EXIT_FAILURE;
    }

    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = INADDR_ANY;
    addr.sin_port = htons(PORT);

    // Bind the socket
    if (bind(server_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
        perror("rbind");
        close(server_fd);
        return EXIT_FAILURE;
    }

    // Listen for incoming connections
    if (listen(server_fd, 1) < 0) {
        perror("rlisten");
        close(server_fd);
        return EXIT_FAILURE;
    }
    printf("Waiting for connection on port %d...\n", PORT);

    // Accept a connection
    if ((client_fd = accept(server_fd, NULL, NULL)) < 0) {
        perror("raccept");
        close(server_fd);
        return EXIT_FAILURE;
    }
    printf("Client connected. Waiting for data...\n");

    while (1) {
        // Initialize the fd set and timeout
        FD_ZERO(&read_fds);
        FD_SET(client_fd, &read_fds);
        timeout.tv_sec = TIMEOUT_SEC;
        timeout.tv_usec = 0;

        int activity = select(client_fd + 1, &read_fds, NULL, NULL, &timeout);

        if (activity < 0) {
            perror("rselect");
            break;
        } else if (activity == 0) {
            printf("Timeout: No data received in %d seconds.\n", TIMEOUT_SEC);
            continue;
        }

        if (FD_ISSET(client_fd, &read_fds)) {
            int bytes_received = recv(client_fd, buffer, BUFFER_SIZE - 1, 0);
            if (bytes_received <= 0) {
                printf("Connection closed or error.\n");
                break;
            }
            buffer[bytes_received] = '\0';
            printf("Received: %s\n", buffer);
        }
    }

    close(client_fd);
    close(server_fd);
    return EXIT_SUCCESS;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rdma/rsocket.h>

#define SERVER_IP "192.168.0.1"
#define PORT 12345
#define BUFFER_SIZE 1024

int main() {
    int client_fd;
    struct sockaddr_in server_addr;
    char message[BUFFER_SIZE];

    // Create an RSocket (RDMA socket)
    if ((client_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        perror("rsocket");
        return EXIT_FAILURE;
    }

    memset(&server_addr, 0, sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(PORT);
    if (inet_pton(AF_INET, SERVER_IP, &server_addr.sin_addr) <= 0) {
        perror("inet_pton");
        close(client_fd);
        return EXIT_FAILURE;
    }

    // Connect to the server
    if (connect(client_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) {
        perror("rconnect");
        close(client_fd);
        return EXIT_FAILURE;
    }
    printf("Connected to server at %s:%d\n", SERVER_IP, PORT);

    while (1) {
        printf("Press Enter to send a message...");
        getchar(); // Wait for user input

        snprintf(message, BUFFER_SIZE, "Hello from RDMA client!");
        if (send(client_fd, message, strlen(message), 0) < 0) {
            perror("rsend");
            break;
        }
        printf("Message sent: %s\n", message);
    }

    // Close connection
    close(client_fd);
    return EXIT_SUCCESS;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rdma/rsocket.h>

#define SERVER_IP "192.168.0.1"
#define PORT 12345
#define BUFFER_SIZE 1024

int main() {
    int client_fd;
    struct sockaddr_in server_addr;
    char message[BUFFER_SIZE];

    // Create an RSocket (RDMA socket)
    if ((client_fd = rsocket(AF_INET, SOCK_STREAM, 0)) < 0) {
        perror("rsocket");
        return EXIT_FAILURE;
    }

    memset(&server_addr, 0, sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(PORT);
    if (inet_pton(AF_INET, SERVER_IP, &server_addr.sin_addr) <= 0) {
        perror("inet_pton");
        rclose(client_fd);
        return EXIT_FAILURE;
    }

    // Connect to the server
    if (rconnect(client_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) {
        perror("rconnect");
        rclose(client_fd);
        return EXIT_FAILURE;
    }
    printf("Connected to server at %s:%d\n", SERVER_IP, PORT);

    while (1) {
        printf("Press Enter to send a message...");
        getchar(); // Wait for user input

        snprintf(message, BUFFER_SIZE, "Hello from RDMA client!");
        if (rsend(client_fd, message, strlen(message), 0) < 0) {
            perror("rsend");
            break;
        }
        printf("Message sent: %s\n", message);
    }

    // Close connection
    rclose(client_fd);
    return EXIT_SUCCESS;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rdma/rsocket.h>

#define PORT 12345
#define TIMEOUT_SEC 5
#define BUFFER_SIZE 1024

int main() {
    int server_fd, client_fd;
    struct sockaddr_in addr;
    char buffer[BUFFER_SIZE];
    fd_set read_fds;
    struct timeval timeout;

    // Create an RSocket (RDMA socket)
    if ((server_fd = rsocket(AF_INET, SOCK_STREAM, 0)) < 0) {
        perror("rsocket");
        return EXIT_FAILURE;
    }

    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = INADDR_ANY;
    addr.sin_port = htons(PORT);

    // Bind the socket
    if (rbind(server_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
        perror("rbind");
        rclose(server_fd);
        return EXIT_FAILURE;
    }

    // Listen for incoming connections
    if (rlisten(server_fd, 1) < 0) {
        perror("rlisten");
        rclose(server_fd);
        return EXIT_FAILURE;
    }
    printf("Waiting for connection on port %d...\n", PORT);

    // Accept a connection
    if ((client_fd = raccept(server_fd, NULL, NULL)) < 0) {
        perror("raccept");
        rclose(server_fd);
        return EXIT_FAILURE;
    }
    printf("Client connected. Waiting for data...\n");

    while (1) {
        // Initialize the fd set and timeout
        FD_ZERO(&read_fds);
        FD_SET(client_fd, &read_fds);
        timeout.tv_sec = TIMEOUT_SEC;
        timeout.tv_usec = 0;

        int activity = rselect(client_fd + 1, &read_fds, NULL, NULL, &timeout);

        if (activity < 0) {
            perror("rselect");
            break;
        } else if (activity == 0) {
            printf("Timeout: No data received in %d seconds.\n", TIMEOUT_SEC);
            continue;
        }

        if (FD_ISSET(client_fd, &read_fds)) {
            int bytes_received = rrecv(client_fd, buffer, BUFFER_SIZE - 1, 0);
            if (bytes_received <= 0) {
                printf("Connection closed or error.\n");
                break;
            }
            buffer[bytes_received] = '\0';
            printf("Received: %s\n", buffer);
        }
    }

    rclose(client_fd);
    rclose(server_fd);
    return EXIT_SUCCESS;
}

[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux