Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples using ipc_close should use deadline #212

Open
suvarchal opened this issue Jan 2, 2022 · 1 comment
Open

Examples using ipc_close should use deadline #212

suvarchal opened this issue Jan 2, 2022 · 1 comment

Comments

@suvarchal
Copy link

Examples (at least) listed below should end with ipc_close(s, -1);
http://libdill.org/ipc_connect.html
http://libdill.org/ipc_close.html

example fix (just last line)

int s = ipc_connect("/tmp/test.ipc", -1);
bsend(s, "ABC", 3, -1);
char buf[3];
brecv(s, buf, sizeof(buf), -1);
ipc_close(s, -1);
@ljluestc
Copy link

#include <libdill.h>
#include <stdio.h>

int main() {
    // Connect to the IPC endpoint
    int s = ipc_connect("/tmp/test.ipc", -1);
    if (s < 0) {
        perror("Error connecting to IPC endpoint");
        return 1;
    }

    // Send data
    int sent = bsend(s, "ABC", 3, -1);
    if (sent < 0) {
        perror("Error sending data");
        ipc_close(s, -1);
        return 1;
    }

    // Receive data
    char buf[3];
    int received = brecv(s, buf, sizeof(buf), -1);
    if (received < 0) {
        perror("Error receiving data");
        ipc_close(s, -1);
        return 1;
    }

    printf("Received data: %.*s\n", received, buf);

    // Close the IPC connection
    ipc_close(s, -1);

    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants