Пример #1
0
static int
new_tcp_stream(const char *name, int fd, int connect_status,
               const struct sockaddr_in *remote, struct stream **streamp)
{
    struct sockaddr_in local;
    socklen_t local_len = sizeof local;
    int on = 1;
    int retval;

    /* Get the local IP and port information */
    retval = getsockname(fd, (struct sockaddr *)&local, &local_len);
    if (retval) {
        memset(&local, 0, sizeof local);
    }

    retval = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof on);
    if (retval) {
        VLOG_ERR("%s: setsockopt(TCP_NODELAY): %s", name, strerror(errno));
        close(fd);
        return errno;
    }

    retval = new_fd_stream(name, fd, connect_status, streamp);
    if (!retval) {
        struct stream *stream = *streamp;
        stream_set_remote_ip(stream, remote->sin_addr.s_addr);
        stream_set_remote_port(stream, remote->sin_port);
        stream_set_local_ip(stream, local.sin_addr.s_addr);
        stream_set_local_port(stream, local.sin_port);
    }
    return retval;
}
Пример #2
0
static int
new_tcp_stream(const char *name, int fd, int connect_status,
               struct stream **streamp)
{
    struct sockaddr_storage local;
    socklen_t local_len = sizeof local;
    int on = 1;
    int retval;

    /* Get the local IP and port information */
    retval = getsockname(fd, (struct sockaddr *) &local, &local_len);
    if (retval) {
        memset(&local, 0, sizeof local);
    }

    retval = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof on);
    if (retval) {
        int error = sock_errno();
        VLOG_ERR("%s: setsockopt(TCP_NODELAY): %s",
                 name, sock_strerror(error));
        close(fd);
        return error;
    }

    return new_fd_stream(name, fd, connect_status, streamp);
}
Пример #3
0
/* Takes ownership of 'name'. */
static int
new_tcp_stream(char *name, int fd, int connect_status, struct stream **streamp)
{
    if (connect_status == 0) {
        setsockopt_tcp_nodelay(fd);
    }

    return new_fd_stream(name, fd, connect_status, AF_INET, streamp);
}
Пример #4
0
static int
unix_open(const char *name, char *suffix, struct stream **streamp,
          uint8_t dscp OVS_UNUSED)
{
    char *connect_path;
    int fd;

    connect_path = abs_file_name(ovs_rundir(), suffix);
    fd = make_unix_socket(SOCK_STREAM, true, NULL, connect_path);

    if (fd < 0) {
        VLOG_DBG("%s: connection failed (%s)",
                 connect_path, ovs_strerror(-fd));
        free(connect_path);
        return -fd;
    }

    free(connect_path);
    return new_fd_stream(name, fd, check_connection_completion(fd), streamp);
}
Пример #5
0
static int
unix_open(const char *name, char *suffix, struct stream **streamp)
{
    const char *connect_path = suffix;
    char *bind_path;
    int fd;

    bind_path = xasprintf("/tmp/stream-unix.%ld.%d",
                          (long int) getpid(), n_unix_sockets++);
    fd = make_unix_socket(SOCK_STREAM, true, false, bind_path, connect_path);
    if (fd < 0) {
        VLOG_ERR("%s: connection to %s failed: %s",
                 bind_path, connect_path, strerror(-fd));
        free(bind_path);
        return -fd;
    }

    return new_fd_stream(name, fd, check_connection_completion(fd),
                         bind_path, streamp);
}