libavformat: Remove FF_NETERRNO()
Map EAGAIN and EINTR from ff_neterrno to the normal AVERROR() error codes. Provide fallback definitions of other errno.h network errors, mapping them to the corresponding winsock errors. This eases catching these error codes in common code, without having to distinguish between FF_NETERRNO(EAGAIN) and AVERROR(EAGAIN). This fixes roundup issue 2614, unbreaking blocking network IO on windows. Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
This commit is contained in:
parent
8f935b9271
commit
28c4741a66
32
ffserver.c
32
ffserver.c
@ -692,8 +692,8 @@ static int http_server(void)
|
|||||||
second to handle timeouts */
|
second to handle timeouts */
|
||||||
do {
|
do {
|
||||||
ret = poll(poll_table, poll_entry - poll_table, delay);
|
ret = poll(poll_table, poll_entry - poll_table, delay);
|
||||||
if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
|
if (ret < 0 && ff_neterrno() != AVERROR(EAGAIN) &&
|
||||||
ff_neterrno() != FF_NETERROR(EINTR))
|
ff_neterrno() != AVERROR(EINTR))
|
||||||
return -1;
|
return -1;
|
||||||
} while (ret < 0);
|
} while (ret < 0);
|
||||||
|
|
||||||
@ -916,8 +916,8 @@ static int handle_connection(HTTPContext *c)
|
|||||||
read_loop:
|
read_loop:
|
||||||
len = recv(c->fd, c->buffer_ptr, 1, 0);
|
len = recv(c->fd, c->buffer_ptr, 1, 0);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
|
if (ff_neterrno() != AVERROR(EAGAIN) &&
|
||||||
ff_neterrno() != FF_NETERROR(EINTR))
|
ff_neterrno() != AVERROR(EINTR))
|
||||||
return -1;
|
return -1;
|
||||||
} else if (len == 0) {
|
} else if (len == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -952,8 +952,8 @@ static int handle_connection(HTTPContext *c)
|
|||||||
return 0;
|
return 0;
|
||||||
len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
|
len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
|
if (ff_neterrno() != AVERROR(EAGAIN) &&
|
||||||
ff_neterrno() != FF_NETERROR(EINTR)) {
|
ff_neterrno() != AVERROR(EINTR)) {
|
||||||
/* error : close connection */
|
/* error : close connection */
|
||||||
av_freep(&c->pb_buffer);
|
av_freep(&c->pb_buffer);
|
||||||
return -1;
|
return -1;
|
||||||
@ -1022,8 +1022,8 @@ static int handle_connection(HTTPContext *c)
|
|||||||
return 0;
|
return 0;
|
||||||
len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
|
len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
|
if (ff_neterrno() != AVERROR(EAGAIN) &&
|
||||||
ff_neterrno() != FF_NETERROR(EINTR)) {
|
ff_neterrno() != AVERROR(EINTR)) {
|
||||||
/* error : close connection */
|
/* error : close connection */
|
||||||
av_freep(&c->pb_buffer);
|
av_freep(&c->pb_buffer);
|
||||||
return -1;
|
return -1;
|
||||||
@ -1049,8 +1049,8 @@ static int handle_connection(HTTPContext *c)
|
|||||||
len = send(c->fd, c->packet_buffer_ptr,
|
len = send(c->fd, c->packet_buffer_ptr,
|
||||||
c->packet_buffer_end - c->packet_buffer_ptr, 0);
|
c->packet_buffer_end - c->packet_buffer_ptr, 0);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
|
if (ff_neterrno() != AVERROR(EAGAIN) &&
|
||||||
ff_neterrno() != FF_NETERROR(EINTR)) {
|
ff_neterrno() != AVERROR(EINTR)) {
|
||||||
/* error : close connection */
|
/* error : close connection */
|
||||||
av_freep(&c->packet_buffer);
|
av_freep(&c->packet_buffer);
|
||||||
return -1;
|
return -1;
|
||||||
@ -2550,8 +2550,8 @@ static int http_send_data(HTTPContext *c)
|
|||||||
/* TCP data output */
|
/* TCP data output */
|
||||||
len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
|
len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
|
if (ff_neterrno() != AVERROR(EAGAIN) &&
|
||||||
ff_neterrno() != FF_NETERROR(EINTR))
|
ff_neterrno() != AVERROR(EINTR))
|
||||||
/* error : close connection */
|
/* error : close connection */
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
@ -2624,8 +2624,8 @@ static int http_receive_data(HTTPContext *c)
|
|||||||
len = recv(c->fd, c->buffer_ptr, 1, 0);
|
len = recv(c->fd, c->buffer_ptr, 1, 0);
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
|
if (ff_neterrno() != AVERROR(EAGAIN) &&
|
||||||
ff_neterrno() != FF_NETERROR(EINTR))
|
ff_neterrno() != AVERROR(EINTR))
|
||||||
/* error : close connection */
|
/* error : close connection */
|
||||||
goto fail;
|
goto fail;
|
||||||
return 0;
|
return 0;
|
||||||
@ -2651,8 +2651,8 @@ static int http_receive_data(HTTPContext *c)
|
|||||||
len = recv(c->fd, c->buffer_ptr,
|
len = recv(c->fd, c->buffer_ptr,
|
||||||
FFMIN(c->chunk_size, c->buffer_end - c->buffer_ptr), 0);
|
FFMIN(c->chunk_size, c->buffer_end - c->buffer_ptr), 0);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
|
if (ff_neterrno() != AVERROR(EAGAIN) &&
|
||||||
ff_neterrno() != FF_NETERROR(EINTR))
|
ff_neterrno() != AVERROR(EINTR))
|
||||||
/* error : close connection */
|
/* error : close connection */
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (len == 0)
|
} else if (len == 0)
|
||||||
|
@ -27,9 +27,21 @@
|
|||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
#define ff_neterrno() (-WSAGetLastError())
|
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
|
||||||
#define FF_NETERROR(err) (-WSA##err)
|
#define ETIMEDOUT WSAETIMEDOUT
|
||||||
#define WSAEAGAIN WSAEWOULDBLOCK
|
#define ECONNREFUSED WSAECONNREFUSED
|
||||||
|
#define EINPROGRESS WSAEINPROGRESS
|
||||||
|
|
||||||
|
static inline int ff_neterrno() {
|
||||||
|
int err = WSAGetLastError();
|
||||||
|
switch (err) {
|
||||||
|
case WSAEWOULDBLOCK:
|
||||||
|
return AVERROR(EAGAIN);
|
||||||
|
case WSAEINTR:
|
||||||
|
return AVERROR(EINTR);
|
||||||
|
}
|
||||||
|
return -err;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@ -37,7 +49,6 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
#define ff_neterrno() AVERROR(errno)
|
#define ff_neterrno() AVERROR(errno)
|
||||||
#define FF_NETERROR(err) AVERROR(err)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_ARPA_INET_H
|
#if HAVE_ARPA_INET_H
|
||||||
|
@ -231,8 +231,8 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
len = recvfrom (s->rtp_fd, buf, size, 0,
|
len = recvfrom (s->rtp_fd, buf, size, 0,
|
||||||
(struct sockaddr *)&from, &from_len);
|
(struct sockaddr *)&from, &from_len);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
|
if (ff_neterrno() == AVERROR(EAGAIN) ||
|
||||||
ff_neterrno() == FF_NETERROR(EINTR))
|
ff_neterrno() == AVERROR(EINTR))
|
||||||
continue;
|
continue;
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
}
|
}
|
||||||
@ -251,8 +251,8 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
len = recvfrom (s->rtcp_fd, buf, size, 0,
|
len = recvfrom (s->rtcp_fd, buf, size, 0,
|
||||||
(struct sockaddr *)&from, &from_len);
|
(struct sockaddr *)&from, &from_len);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
|
if (ff_neterrno() == AVERROR(EAGAIN) ||
|
||||||
ff_neterrno() == FF_NETERROR(EINTR))
|
ff_neterrno() == AVERROR(EINTR))
|
||||||
continue;
|
continue;
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
}
|
}
|
||||||
@ -264,15 +264,15 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
len = recvfrom (s->rtp_fd, buf, size, 0,
|
len = recvfrom (s->rtp_fd, buf, size, 0,
|
||||||
(struct sockaddr *)&from, &from_len);
|
(struct sockaddr *)&from, &from_len);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
|
if (ff_neterrno() == AVERROR(EAGAIN) ||
|
||||||
ff_neterrno() == FF_NETERROR(EINTR))
|
ff_neterrno() == AVERROR(EINTR))
|
||||||
continue;
|
continue;
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (n < 0) {
|
} else if (n < 0) {
|
||||||
if (ff_neterrno() == FF_NETERROR(EINTR))
|
if (ff_neterrno() == AVERROR(EINTR))
|
||||||
continue;
|
continue;
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
}
|
}
|
||||||
|
@ -1528,7 +1528,7 @@ redirect:
|
|||||||
goto fail;
|
goto fail;
|
||||||
lower_transport_mask &= ~(1 << lower_transport);
|
lower_transport_mask &= ~(1 << lower_transport);
|
||||||
if (lower_transport_mask == 0 && err == 1) {
|
if (lower_transport_mask == 0 && err == 1) {
|
||||||
err = FF_NETERROR(EPROTONOSUPPORT);
|
err = AVERROR(EPROTONOSUPPORT);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
} while (err);
|
} while (err);
|
||||||
@ -1615,7 +1615,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
|
} else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
|
||||||
return FF_NETERROR(ETIMEDOUT);
|
return AVERROR(ETIMEDOUT);
|
||||||
} else if (n < 0 && errno != EINTR)
|
} else if (n < 0 && errno != EINTR)
|
||||||
return AVERROR(errno);
|
return AVERROR(errno);
|
||||||
}
|
}
|
||||||
|
@ -311,7 +311,7 @@ retry:
|
|||||||
|
|
||||||
ret = ff_rtsp_fetch_packet(s, pkt);
|
ret = ff_rtsp_fetch_packet(s, pkt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (ret == FF_NETERROR(ETIMEDOUT) && !rt->packets) {
|
if (ret == AVERROR(ETIMEDOUT) && !rt->packets) {
|
||||||
if (rt->lower_transport == RTSP_LOWER_TRANSPORT_UDP &&
|
if (rt->lower_transport == RTSP_LOWER_TRANSPORT_UDP &&
|
||||||
rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_TCP)) {
|
rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_TCP)) {
|
||||||
RTSPMessageHeader reply1, *reply = &reply1;
|
RTSPMessageHeader reply1, *reply = &reply1;
|
||||||
|
@ -240,7 +240,7 @@ static int sap_write_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
if (!sap->last_time || now - sap->last_time > 5000000) {
|
if (!sap->last_time || now - sap->last_time > 5000000) {
|
||||||
int ret = url_write(sap->ann_fd, sap->ann, sap->ann_size);
|
int ret = url_write(sap->ann_fd, sap->ann, sap->ann_size);
|
||||||
/* Don't abort even if we get "Destination unreachable" */
|
/* Don't abort even if we get "Destination unreachable" */
|
||||||
if (ret < 0 && ret != FF_NETERROR(ECONNREFUSED))
|
if (ret < 0 && ret != AVERROR(ECONNREFUSED))
|
||||||
return ret;
|
return ret;
|
||||||
sap->last_time = now;
|
sap->last_time = now;
|
||||||
}
|
}
|
||||||
|
@ -72,13 +72,13 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
|
|||||||
ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
|
ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
struct pollfd p = {fd, POLLOUT, 0};
|
struct pollfd p = {fd, POLLOUT, 0};
|
||||||
if (ff_neterrno() == FF_NETERROR(EINTR)) {
|
if (ff_neterrno() == AVERROR(EINTR)) {
|
||||||
if (url_interrupt_cb())
|
if (url_interrupt_cb())
|
||||||
goto fail1;
|
goto fail1;
|
||||||
goto redo;
|
goto redo;
|
||||||
}
|
}
|
||||||
if (ff_neterrno() != FF_NETERROR(EINPROGRESS) &&
|
if (ff_neterrno() != AVERROR(EINPROGRESS) &&
|
||||||
ff_neterrno() != FF_NETERROR(EAGAIN))
|
ff_neterrno() != AVERROR(EAGAIN))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* wait until we are connected or until abort */
|
/* wait until we are connected or until abort */
|
||||||
@ -136,7 +136,7 @@ static int tcp_wait_fd(int fd, int write)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = poll(&p, 1, 100);
|
ret = poll(&p, 1, 100);
|
||||||
return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : FF_NETERROR(EAGAIN);
|
return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tcp_read(URLContext *h, uint8_t *buf, int size)
|
static int tcp_read(URLContext *h, uint8_t *buf, int size)
|
||||||
|
@ -455,7 +455,7 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
return AVERROR(EINTR);
|
return AVERROR(EINTR);
|
||||||
ret = poll(&p, 1, 100);
|
ret = poll(&p, 1, 100);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (ff_neterrno() == FF_NETERROR(EINTR))
|
if (ff_neterrno() == AVERROR(EINTR))
|
||||||
continue;
|
continue;
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
}
|
}
|
||||||
@ -463,8 +463,8 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
continue;
|
continue;
|
||||||
len = recv(s->udp_fd, buf, size, 0);
|
len = recv(s->udp_fd, buf, size, 0);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
|
if (ff_neterrno() != AVERROR(EAGAIN) &&
|
||||||
ff_neterrno() != FF_NETERROR(EINTR))
|
ff_neterrno() != AVERROR(EINTR))
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -486,8 +486,8 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size)
|
|||||||
} else
|
} else
|
||||||
ret = send(s->udp_fd, buf, size, 0);
|
ret = send(s->udp_fd, buf, size, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (ff_neterrno() != FF_NETERROR(EINTR) &&
|
if (ff_neterrno() != AVERROR(EINTR) &&
|
||||||
ff_neterrno() != FF_NETERROR(EAGAIN))
|
ff_neterrno() != AVERROR(EAGAIN))
|
||||||
return ff_neterrno();
|
return ff_neterrno();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user