*buf = '\0';
#ifdef _WIN32
FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, buflen, NULL);
+ while (len > 0 && buf[len - 1] >= '\0' && buf[len - 1] <= ' ')
+ buf[--len] = '\0';
#else
tr_strlcpy (buf, tr_strerror (err), buflen);
#endif
tr_netSetTOS (tr_socket_t s,
int tos)
{
-#ifdef IP_TOS
- if (setsockopt (s, IPPROTO_IP, IP_TOS, (const void *) &tos, sizeof (tos)) != -1)
- return;
+#if defined (IP_TOS) && !defined (_WIN32)
+ if (setsockopt (s, IPPROTO_IP, IP_TOS, (const void *) &tos, sizeof (tos)) == -1)
+ {
+ char err_buf[512];
+ tr_logAddNamedInfo ("Net", "Can't set TOS '%d': %s", tos,
+ tr_net_strerror (err_buf, sizeof (err_buf), sockerrno));
+ }
#else
(void) s;
- errno = ENOSYS;
+ (void) tos;
#endif
-
- tr_logAddNamedInfo ("Net", "Can't set TOS '%d': %s", tos, tr_strerror (errno));
}
void
{
#ifdef TCP_CONGESTION
if (setsockopt (s, IPPROTO_TCP, TCP_CONGESTION,
- (const void *) algorithm, strlen (algorithm) + 1) != -1)
- return;
-
+ (const void *) algorithm, strlen (algorithm) + 1) == -1)
+ {
+ char err_buf[512];
+ tr_logAddNamedInfo ("Net", "Can't set congestion control algorithm '%s': %s",
+ algorithm, tr_net_strerror (err_buf, sizeof (err_buf), sockerrno));
+ }
#else
(void) s;
- errno = ENOSYS;
+ (void) algorithm;
#endif
-
- tr_logAddNamedInfo ("Net", "Can't set congestion control algorithm '%s': %s",
- algorithm, tr_strerror (errno));
}
bool
const tr_address * source_addr;
socklen_t sourcelen;
struct sockaddr_storage source_sock;
+ char err_buf[512];
assert (tr_address_is_valid (addr));
if (clientIsSeed) {
int n = 8192;
if (setsockopt (s, SOL_SOCKET, SO_RCVBUF, (const void *) &n, sizeof (n)))
- tr_logAddInfo ("Unable to set SO_RCVBUF on socket %"TR_PRI_SOCK": %s", s, tr_strerror (sockerrno));
+ tr_logAddInfo ("Unable to set SO_RCVBUF on socket %"TR_PRI_SOCK": %s", s,
+ tr_net_strerror (err_buf, sizeof (err_buf), sockerrno));
}
if (evutil_make_socket_nonblocking (s) < 0) {
if (bind (s, (struct sockaddr *) &source_sock, sourcelen))
{
tr_logAddError (_("Couldn't set source address %s on %"TR_PRI_SOCK": %s"),
- tr_address_to_string (source_addr), s, tr_strerror (errno));
+ tr_address_to_string (source_addr), s,
+ tr_net_strerror (err_buf, sizeof (err_buf), sockerrno));
tr_netClose (session, s);
return TR_BAD_SOCKET; /* -errno */
}
{
int tmperrno;
tmperrno = sockerrno;
- if ((tmperrno != ENETUNREACH && tmperrno != EHOSTUNREACH)
- || addr->type == TR_AF_INET)
+ if ((tmperrno != ENETUNREACH && tmperrno != EHOSTUNREACH) || addr->type == TR_AF_INET)
+ {
tr_logAddError (_("Couldn't connect socket %"TR_PRI_SOCK" to %s, port %d (errno %d - %s)"),
- s, tr_address_to_string (addr), (int)ntohs (port), tmperrno,
- tr_strerror (tmperrno));
+ s, tr_address_to_string (addr), (int)ntohs (port), tmperrno,
+ tr_net_strerror (err_buf, sizeof (err_buf), tmperrno));
+ }
tr_netClose (session, s);
s = TR_BAD_SOCKET; /* -tmperrno */
}
{
const char * fmt;
const char * hint;
+ char err_buf[512];
if (err == EADDRINUSE)
hint = _("Is another copy of Transmission already running?");
else
fmt = _("Couldn't bind port %d on %s: %s (%s)");
- tr_logAddError (fmt, port, tr_address_to_string (addr), tr_strerror (err), hint);
+ tr_logAddError (fmt, port, tr_address_to_string (addr),
+ tr_net_strerror (err_buf, sizeof (err_buf), err), hint);
}
tr_netCloseSocket (fd);
*errOut = err;
else /* tcp peer connection */
{
int e;
+ char err_buf[512];
EVUTIL_SET_SOCKET_ERROR (0);
res = evbuffer_read (io->inbuf, io->socket, (int)howmuch);
e = EVUTIL_SOCKET_ERROR ();
- dbgmsg (io, "read %d from peer (%s)", res, (res==-1?tr_strerror (e):""));
+ dbgmsg (io, "read %d from peer (%s)", res,
+ (res==-1?tr_net_strerror (err_buf, sizeof (err_buf), e):""));
if (evbuffer_get_length (io->inbuf))
canReadWrapper (io);
if ((res <= 0) && (io->gotError) && (e != EAGAIN) && (e != EINTR) && (e != EINPROGRESS))
{
- char errstr[512];
short what = BEV_EVENT_READING | BEV_EVENT_ERROR;
if (res == 0)
what |= BEV_EVENT_EOF;
dbgmsg (io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)",
- res, what, e, tr_net_strerror (errstr, sizeof (errstr), e));
+ res, what, e, tr_net_strerror (err_buf, sizeof (err_buf), e));
io->gotError (io, what, io->userData);
}
}
{
int size, rbuf, sbuf, rc;
socklen_t rbuf_len = sizeof (rbuf), sbuf_len = sizeof (sbuf);
+ char err_buf[512];
size = large ? RECV_BUFFER_SIZE : SMALL_BUFFER_SIZE;
rc = setsockopt (fd, SOL_SOCKET, SO_RCVBUF, (const void *) &size, sizeof (size));
if (rc < 0)
tr_logAddNamedError ("UDP", "Failed to set receive buffer: %s",
- tr_strerror (errno));
+ tr_net_strerror (err_buf, sizeof (err_buf), sockerrno));
size = large ? SEND_BUFFER_SIZE : SMALL_BUFFER_SIZE;
rc = setsockopt (fd, SOL_SOCKET, SO_SNDBUF, (const void *) &size, sizeof (size));
if (rc < 0)
tr_logAddNamedError ("UDP", "Failed to set send buffer: %s",
- tr_strerror (errno));
+ tr_net_strerror (err_buf, sizeof (err_buf), sockerrno));
if (large) {
rc = getsockopt (fd, SOL_SOCKET, SO_RCVBUF, (void *) &rbuf, &rbuf_len);