Commit 0d01f645 authored by Kai Vogelgesang's avatar Kai Vogelgesang
Browse files

Change PrrtSocket_bind return type to int, Add error message to python bindings

parent 17b3cb02
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ cdef extern from "proto/socket.h":
    ctypedef prrtSocket PrrtSocket

    cdef PrrtSocket* PrrtSocket_create(const uint32_t maximum_payload_size, const uint32_t target_delay)
    bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port)
    int PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port)
    int PrrtSocket_close(const PrrtSocket *sock_ptr)
    int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port)
    int PrrtSocket_send_sync(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data_len)
+6 −3
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ bool PrrtSocket_enable_hardware_timestamping(PrrtSocket *s, const char * interfa
    return false;
}

bool PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port) {
int PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port) {
    check(port <= 65534, "Port %d cannot be bound to.", port);

    size_t size = sizeof(struct sockaddr_in);
@@ -205,10 +205,13 @@ bool PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port)

    s->isBound = true;

    return true;
    return 0;
    error:
    PrrtSocket_close(s);
    return false;
    if (h_errno) {
        return h_errno;
    }
    return -2;
}

bool PrrtSocket_connect(PrrtSocket *s, const char *host, const uint16_t port) {
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ bool PrrtSocket_enable_hardware_timestamping(PrrtSocket *s, const char * interfa

bool PrrtSocket_enable_thread_pinning(PrrtSocket *s);

bool PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port);
int PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port);

bool PrrtSocket_set_sock_opt(PrrtSocket *s, const char *name, const uint32_t value);

+10 −2
Original line number Diff line number Diff line
@@ -150,12 +150,20 @@ cdef class PrrtSocket:
        self._c_socket = cprrt.PrrtSocket_create(maximum_payload_size, target_delay_us)
        if thread_pinning:
            cprrt.PrrtSocket_enable_thread_pinning(self._c_socket)
        if not cprrt.PrrtSocket_bind(self._c_socket, host.encode("utf8"), port):
        h_errno = cprrt.PrrtSocket_bind(self._c_socket, host.encode("utf8"), port)
        if h_errno != 0:
            # PrrtSocket_bind calls PrrtSocket_close on error
            # so we need to set _c_socket to NULL because otherwise __dealloc__
            # will attempt to call PrrtSocket_close again on the closed socket
            self._c_socket = NULL
            raise ValueError("PrrtSocket_bind failed")
            # TODO: use hstrerror() instead
            raise ValueError("PrrtSocket_bind failed: " + ({
                1: 'host not found.',
                2: 'try again.',
                3: 'no recovery.',
                4: 'no data.',
                -1: 'netdb internal error.',
            }).get(h_errno, 'unknown error.'))

    # Channel Properties
    property data_rate_btl_fwd:
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ int main(int argc, char **argv) {
        PrrtSocket_enable_thread_pinning(s);
    }

    check(PrrtSocket_bind(s, "0.0.0.0", arguments.port), "bind failed");
    check(PrrtSocket_bind(s, "0.0.0.0", arguments.port) == 0, "bind failed");

    XlapTimestampTable *tstable_data = malloc(sizeof(XlapTimestampTable));
    XlapTimestampTable *tstable_redundancy = malloc(sizeof(XlapTimestampTable));