Commit 4c6953fb authored by Alessandro Rubini's avatar Alessandro Rubini

unix and wrs socket: open in non-blocking mode and report write errors

It may happen, though rarely, that frames are not sent (or not freed
at kernel level), and we build up an output queue, so at some point we
get -EAGAIN on sending.

With blocking writes, this situation was stalling the whole process.
This patch helped us diagnosing a problem in our own network driver,
which had a memory leakage, but using non-blocking sockets and
reporting erors is the right thing to do anyways.

This patch reports the error using pp_diag with a priority 0; thus
the message is always printed, but by virtue of pp_diag we have the
name of the port automatically added.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 0bef6863
......@@ -210,6 +210,11 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
ppi->t_ops->get(ppi, t);
ret = send(ch->fd, hdr, len, 0);
if (ret < 0) {
pp_diag(ppi, frames, 0, "send failed: %s\n",
strerror(errno));
return ret;
}
if (pp_diag_allow(ppi, frames, 2))
dump_1588pkt("send: ", pkt, len, t);
return ret;
......@@ -228,9 +233,13 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
ppi->t_ops->get(ppi, t);
ret = send(ch->fd, vhdr, len, 0);
if (ret < 0) {
pp_diag(ppi, frames, 0, "send failed: %s\n",
strerror(errno));
return ret;
}
if (pp_diag_allow(ppi, frames, 2))
dump_1588pkt("send: ", vhdr, len, t);
return ret;
case PPSI_PROTO_UDP:
addr.sin_family = AF_INET;
......@@ -243,8 +252,11 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
ret = sendto(ppi->ch[chtype].fd, pkt, len, 0,
(struct sockaddr *)&addr,
sizeof(struct sockaddr_in));
if (pp_diag_allow(ppi, frames, 2))
dump_payloadpkt("send: ", pkt, len, t);
if (ret < 0) {
pp_diag(ppi, frames, 0, "send failed: %s\n",
strerror(errno));
return ret;
}
return ret;
default:
......@@ -265,7 +277,7 @@ static int unix_open_ch_raw(struct pp_instance *ppi, char *ifname, int chtype)
/* open socket */
context = "socket()";
sock = socket(PF_PACKET, SOCK_RAW, ETH_P_1588);
sock = socket(PF_PACKET, SOCK_RAW | SOCK_NONBLOCK, ETH_P_1588);
if (sock < 0)
goto err_out;
......@@ -339,7 +351,7 @@ static int unix_open_ch_udp(struct pp_instance *ppi, char *ifname, int chtype)
char *context;
context = "socket()";
sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
sock = socket(PF_INET, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
if (sock < 0)
goto err_out;
......
......@@ -468,6 +468,11 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
ppi->t_ops->get(ppi, t);
ret = send(ch->fd, hdr, len, 0);
if (ret < 0) {
pp_diag(ppi, frames, 0, "send failed: %s\n",
strerror(errno));
break;
}
poll_tx_timestamp(ppi, pkt, len, s, ch->fd, t);
if (drop) /* avoid messaging about stamps that are not used */
......@@ -498,6 +503,11 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
if (len < 64)
len = 64;
ret = send(ch->fd, vhdr, len, 0);
if (ret < 0) {
pp_diag(ppi, frames, 0, "send failed: %s\n",
strerror(errno));
break;
}
poll_tx_timestamp(ppi, pkt, len, s, ch->fd, t);
if (drop) /* avoid messaging about stamps that are not used */
......@@ -519,6 +529,11 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
addr.sin_port = 3200;
ret = sendto(fd, pkt, len, 0, (struct sockaddr *)&addr,
sizeof(struct sockaddr_in));
if (ret < 0) {
pp_diag(ppi, frames, 0, "send failed: %s\n",
strerror(errno));
break;
}
poll_tx_timestamp(ppi, pkt, len, s, fd, t);
if (drop) /* like above: skil messages about timestamps */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment