mirror of
https://github.com/transmission/transmission
synced 2025-03-09 21:54:09 +00:00
Compare system function return value to a specific value indicating the error
This commit is contained in:
parent
b342d134cb
commit
efaa9d0ddc
6 changed files with 27 additions and 27 deletions
|
@ -599,7 +599,7 @@ char* tr_clientForId(char* buf, size_t buflen, void const* id_in)
|
|||
}
|
||||
}
|
||||
|
||||
if (*buf)
|
||||
if (*buf != '\0')
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
|
@ -624,7 +624,7 @@ char* tr_clientForId(char* buf, size_t buflen, void const* id_in)
|
|||
strint(id + 5, 2), getMnemonicEnd(id[7]));
|
||||
}
|
||||
|
||||
if (*buf)
|
||||
if (*buf != '\0')
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
|
@ -643,7 +643,7 @@ char* tr_clientForId(char* buf, size_t buflen, void const* id_in)
|
|||
mainline_style(buf, buflen, "Queen Bee", id);
|
||||
}
|
||||
|
||||
if (*buf)
|
||||
if (*buf != '\0')
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -261,14 +261,14 @@ tr_socket_t tr_netOpenPeerSocket(tr_session* session, tr_address const* addr, tr
|
|||
{
|
||||
int n = 8192;
|
||||
|
||||
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, (void const*)&n, sizeof(n)) != 0)
|
||||
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, (void const*)&n, sizeof(n)) == -1)
|
||||
{
|
||||
tr_logAddInfo("Unable to set SO_RCVBUF on socket %" PRIdMAX ": %s", (intmax_t)s,
|
||||
tr_net_strerror(err_buf, sizeof(err_buf), sockerrno));
|
||||
}
|
||||
}
|
||||
|
||||
if (evutil_make_socket_nonblocking(s) < 0)
|
||||
if (evutil_make_socket_nonblocking(s) == -1)
|
||||
{
|
||||
tr_netClose(session, s);
|
||||
return TR_BAD_SOCKET;
|
||||
|
@ -281,7 +281,7 @@ tr_socket_t tr_netOpenPeerSocket(tr_session* session, tr_address const* addr, tr
|
|||
assert(source_addr);
|
||||
sourcelen = setup_sockaddr(source_addr, 0, &source_sock);
|
||||
|
||||
if (bind(s, (struct sockaddr*)&source_sock, sourcelen) != 0)
|
||||
if (bind(s, (struct sockaddr*)&source_sock, sourcelen) == -1)
|
||||
{
|
||||
tr_logAddError(_("Couldn't set source address %s on %" PRIdMAX ": %s"), tr_address_to_string(source_addr), (intmax_t)s,
|
||||
tr_net_strerror(err_buf, sizeof(err_buf), sockerrno));
|
||||
|
@ -289,7 +289,7 @@ tr_socket_t tr_netOpenPeerSocket(tr_session* session, tr_address const* addr, tr
|
|||
return TR_BAD_SOCKET; /* -errno */
|
||||
}
|
||||
|
||||
if (connect(s, (struct sockaddr*)&sock, addrlen) < 0 &&
|
||||
if (connect(s, (struct sockaddr*)&sock, addrlen) == -1 &&
|
||||
#ifdef _WIN32
|
||||
sockerrno != WSAEWOULDBLOCK &&
|
||||
#endif
|
||||
|
@ -346,7 +346,7 @@ static tr_socket_t tr_netBindTCPImpl(tr_address const* addr, tr_port port, bool
|
|||
return TR_BAD_SOCKET;
|
||||
}
|
||||
|
||||
if (evutil_make_socket_nonblocking(fd) < 0)
|
||||
if (evutil_make_socket_nonblocking(fd) == -1)
|
||||
{
|
||||
*errOut = sockerrno;
|
||||
tr_netCloseSocket(fd);
|
||||
|
@ -376,7 +376,7 @@ static tr_socket_t tr_netBindTCPImpl(tr_address const* addr, tr_port port, bool
|
|||
|
||||
addrlen = setup_sockaddr(addr, htons(port), &sock);
|
||||
|
||||
if (bind(fd, (struct sockaddr*)&sock, addrlen) != 0)
|
||||
if (bind(fd, (struct sockaddr*)&sock, addrlen) == -1)
|
||||
{
|
||||
int const err = sockerrno;
|
||||
|
||||
|
@ -474,7 +474,7 @@ tr_socket_t tr_netAccept(tr_session* session, tr_socket_t b, tr_address* addr, t
|
|||
{
|
||||
tr_socket_t fd = tr_fdSocketAccept(session, b, addr, port);
|
||||
|
||||
if (fd != TR_BAD_SOCKET && evutil_make_socket_nonblocking(fd) < 0)
|
||||
if (fd != TR_BAD_SOCKET && evutil_make_socket_nonblocking(fd) == -1)
|
||||
{
|
||||
tr_netClose(session, fd);
|
||||
fd = TR_BAD_SOCKET;
|
||||
|
@ -518,14 +518,14 @@ static int get_source_address(struct sockaddr const* dst, socklen_t dst_len, str
|
|||
/* Since it's a UDP socket, this doesn't actually send any packets. */
|
||||
rc = connect(s, dst, dst_len);
|
||||
|
||||
if (rc < 0)
|
||||
if (rc == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
rc = getsockname(s, src, src_len);
|
||||
|
||||
if (rc < 0)
|
||||
if (rc == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -322,12 +322,12 @@ int tr_lpdInit(tr_session* ss, tr_address* tr_addr UNUSED)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (evutil_make_socket_nonblocking(lpd_socket) < 0)
|
||||
if (evutil_make_socket_nonblocking(lpd_socket) == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (setsockopt(lpd_socket, SOL_SOCKET, SO_REUSEADDR, (void const*)&opt_on, sizeof opt_on) < 0)
|
||||
if (setsockopt(lpd_socket, SOL_SOCKET, SO_REUSEADDR, (void const*)&opt_on, sizeof opt_on) == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
@ -336,12 +336,12 @@ int tr_lpdInit(tr_session* ss, tr_address* tr_addr UNUSED)
|
|||
lpd_mcastAddr.sin_family = AF_INET;
|
||||
lpd_mcastAddr.sin_port = htons(lpd_mcastPort);
|
||||
|
||||
if (evutil_inet_pton(lpd_mcastAddr.sin_family, lpd_mcastGroup, &lpd_mcastAddr.sin_addr) < 0)
|
||||
if (evutil_inet_pton(lpd_mcastAddr.sin_family, lpd_mcastGroup, &lpd_mcastAddr.sin_addr) == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (bind(lpd_socket, (struct sockaddr*)&lpd_mcastAddr, sizeof lpd_mcastAddr) < 0)
|
||||
if (bind(lpd_socket, (struct sockaddr*)&lpd_mcastAddr, sizeof lpd_mcastAddr) == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
@ -351,12 +351,12 @@ int tr_lpdInit(tr_session* ss, tr_address* tr_addr UNUSED)
|
|||
mcastReq.imr_multiaddr = lpd_mcastAddr.sin_addr;
|
||||
mcastReq.imr_interface.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
if (setsockopt(lpd_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void const*)&mcastReq, sizeof mcastReq) < 0)
|
||||
if (setsockopt(lpd_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void const*)&mcastReq, sizeof mcastReq) == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (setsockopt(lpd_socket, IPPROTO_IP, IP_MULTICAST_LOOP, (void const*)&opt_off, sizeof opt_off) < 0)
|
||||
if (setsockopt(lpd_socket, IPPROTO_IP, IP_MULTICAST_LOOP, (void const*)&opt_off, sizeof opt_off) == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
@ -373,18 +373,18 @@ int tr_lpdInit(tr_session* ss, tr_address* tr_addr UNUSED)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (evutil_make_socket_nonblocking(lpd_socket2) < 0)
|
||||
if (evutil_make_socket_nonblocking(lpd_socket2) == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* configure outbound multicast TTL */
|
||||
if (setsockopt(lpd_socket2, IPPROTO_IP, IP_MULTICAST_TTL, (void const*)&scope, sizeof scope) < 0)
|
||||
if (setsockopt(lpd_socket2, IPPROTO_IP, IP_MULTICAST_TTL, (void const*)&scope, sizeof scope) == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (setsockopt(lpd_socket2, IPPROTO_IP, IP_MULTICAST_LOOP, (void const*)&opt_off, sizeof opt_off) < 0)
|
||||
if (setsockopt(lpd_socket2, IPPROTO_IP, IP_MULTICAST_LOOP, (void const*)&opt_off, sizeof opt_off) == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ static void rebind_ipv6(tr_session* ss, bool force)
|
|||
|
||||
rc = bind(s, (struct sockaddr*)&sin6, sizeof(sin6));
|
||||
|
||||
if (rc < 0)
|
||||
if (rc == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ static void rebind_ipv6(tr_session* ss, bool force)
|
|||
/* FIXME: dup2 doesn't work for sockets on Windows */
|
||||
rc = dup2(s, ss->udp6_socket);
|
||||
|
||||
if (rc < 0)
|
||||
if (rc == -1)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ void tr_udpInit(tr_session* ss)
|
|||
sin.sin_port = htons(ss->udp_port);
|
||||
rc = bind(ss->udp_socket, (struct sockaddr*)&sin, sizeof(sin));
|
||||
|
||||
if (rc < 0)
|
||||
if (rc == -1)
|
||||
{
|
||||
tr_logAddNamedError("UDP", "Couldn't bind IPv4 socket");
|
||||
tr_netCloseSocket(ss->udp_socket);
|
||||
|
|
|
@ -106,7 +106,7 @@ static int piperead(tr_pipe_end_t s, void* buf, int len)
|
|||
{
|
||||
int ret = recv(s, buf, len, 0);
|
||||
|
||||
if (ret < 0)
|
||||
if (ret == -1)
|
||||
{
|
||||
int const werror = WSAGetLastError();
|
||||
|
||||
|
@ -191,7 +191,7 @@ static void readFromPipe(evutil_socket_t fd, short eventType, void* veh)
|
|||
{
|
||||
ret = piperead(fd, &ch, 1);
|
||||
}
|
||||
while (!eh->die && ret < 0 && errno == EAGAIN);
|
||||
while (!eh->die && ret == -1 && errno == EAGAIN);
|
||||
|
||||
dbgmsg("command is [%c], ret is %d, errno is %d", ch, ret, (int)errno);
|
||||
|
||||
|
|
|
@ -356,7 +356,7 @@ static void tr_select(int nfds, fd_set* r_fd_set, fd_set* w_fd_set, fd_set* c_fd
|
|||
tr_wait_msec(msec);
|
||||
}
|
||||
else if (select(0, r_fd_set->fd_count != 0 ? r_fd_set : NULL, w_fd_set->fd_count != 0 ? w_fd_set : NULL,
|
||||
c_fd_set->fd_count != 0 ? c_fd_set : NULL, t) < 0)
|
||||
c_fd_set->fd_count != 0 ? c_fd_set : NULL, t) == -1)
|
||||
{
|
||||
char errstr[512];
|
||||
int const e = EVUTIL_SOCKET_ERROR();
|
||||
|
|
Loading…
Add table
Reference in a new issue