On Thu, Jun 30, 2022 at 4:19 PM Dylan Yudaken <dylany@xxxxxx> wrote: > +int t_create_socket_pair(int fd[2], bool stream) > +{ [ snip... ] > + if (!stream) { > + /* connect the other udp side */ > + if (getsockname(fd[1], &serv_addr, (socklen_t *)&paddrlen)) { > + fprintf(stderr, "getsockname failed\n"); > + goto errno_cleanup; > + } > + inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr); > + > + if (connect(fd[0], &serv_addr, paddrlen)) { > + fprintf(stderr, "connect failed\n"); > + goto errno_cleanup; > + } > + return 0; > + } > + > + /* for stream case we must accept and cleanup the listen socket */ > + > + ret = accept(fd[0], NULL, NULL); > + if (ret < 0) > + goto errno_cleanup; > + > + close(fd[0]); > + fd[0] = ret; > + > + val = 1; > + if (stream && setsockopt(fd[0], SOL_TCP, TCP_NODELAY, &val, sizeof(val))) > + goto errno_cleanup; > + val = 1; > + if (stream && setsockopt(fd[1], SOL_TCP, TCP_NODELAY, &val, sizeof(val))) > + goto errno_cleanup; If we reach here, the @stream is always true, because when it's false, we early return from the `if (!stream)` above. So these two @stream checks for setsockopt() are not needed. > + return 0; > + > +errno_cleanup: > + ret = errno; > + close(fd[0]); > + close(fd[1]); > + return ret; > +} -- Ammar Faizi