use ff_neterrno() and FF_NETERROR() for networking error handling

Originally committed as revision 8845 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Alex Beregszaszi 2007-04-27 00:35:54 +00:00
parent 0bdacf29d4
commit 8da4034f52
5 changed files with 33 additions and 16 deletions

View File

@ -588,7 +588,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 && errno != EAGAIN && errno != EINTR) if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))
return -1; return -1;
} while (ret < 0); } while (ret < 0);
@ -791,7 +792,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 (errno != EAGAIN && errno != EINTR) if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))
return -1; return -1;
} else if (len == 0) { } else if (len == 0) {
return -1; return -1;
@ -826,7 +828,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 (errno != EAGAIN && errno != EINTR) { if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR)) {
/* error : close connection */ /* error : close connection */
av_freep(&c->pb_buffer); av_freep(&c->pb_buffer);
return -1; return -1;
@ -896,7 +899,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 (errno != EAGAIN && errno != EINTR) { if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR)) {
/* error : close connection */ /* error : close connection */
av_freep(&c->pb_buffer); av_freep(&c->pb_buffer);
return -1; return -1;
@ -922,7 +926,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 (errno != EAGAIN && errno != EINTR) { if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR)) {
/* error : close connection */ /* error : close connection */
av_freep(&c->packet_buffer); av_freep(&c->packet_buffer);
return -1; return -1;
@ -2333,7 +2338,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 (errno != EAGAIN && errno != EINTR) { if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR)) {
/* error : close connection */ /* error : close connection */
return -1; return -1;
} else { } else {
@ -2390,7 +2396,8 @@ static int http_receive_data(HTTPContext *c)
len = recv(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0); len = recv(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);
if (len < 0) { if (len < 0) {
if (errno != EAGAIN && errno != EINTR) { if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR)) {
/* error : close connection */ /* error : close connection */
goto fail; goto fail;
} }

View File

@ -29,6 +29,9 @@
#endif #endif
#include <netdb.h> #include <netdb.h>
#define ff_neterrno() errno
#define FF_NETERROR(err) err
#if !defined(HAVE_INET_ATON) #if !defined(HAVE_INET_ATON)
/* in os_support.c */ /* in os_support.c */
int inet_aton (const char * str, struct in_addr * add); int inet_aton (const char * str, struct in_addr * add);

View File

@ -178,7 +178,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 (errno == EAGAIN || errno == EINTR) if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
ff_neterrno() == FF_NETERROR(EINTR))
continue; continue;
return AVERROR_IO; return AVERROR_IO;
} }
@ -201,7 +202,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 (errno == EAGAIN || errno == EINTR) if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
ff_neterrno() == FF_NETERROR(EINTR))
continue; continue;
return AVERROR_IO; return AVERROR_IO;
} }
@ -213,7 +215,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 (errno == EAGAIN || errno == EINTR) if (ff_neterrno() == FF_NETERROR(EAGAIN) ||
ff_neterrno() == FF_NETERROR(EINTR))
continue; continue;
return AVERROR_IO; return AVERROR_IO;
} }

View File

@ -68,9 +68,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
ret = connect(fd, (struct sockaddr *)&dest_addr, ret = connect(fd, (struct sockaddr *)&dest_addr,
sizeof(dest_addr)); sizeof(dest_addr));
if (ret < 0) { if (ret < 0) {
if (errno == EINTR) if (ff_neterrno() == FF_NETERROR(EINTR))
goto redo; goto redo;
if (errno != EINPROGRESS) if (ff_neterrno() != FF_NETERROR(EINPROGRESS))
goto fail; goto fail;
/* wait until we are connected or until abort */ /* wait until we are connected or until abort */
@ -126,7 +126,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
if (ret > 0 && FD_ISSET(s->fd, &rfds)) { if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
len = recv(s->fd, buf, size, 0); len = recv(s->fd, buf, size, 0);
if (len < 0) { if (len < 0) {
if (errno != EINTR && errno != EAGAIN) if (ff_neterrno() != FF_NETERROR(EINTR) &&
ff_neterrno() != FF_NETERROR(EAGAIN))
return AVERROR(errno); return AVERROR(errno);
} else return len; } else return len;
} else if (ret < 0) { } else if (ret < 0) {
@ -155,7 +156,8 @@ static int tcp_write(URLContext *h, uint8_t *buf, int size)
if (ret > 0 && FD_ISSET(s->fd, &wfds)) { if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
len = send(s->fd, buf, size, 0); len = send(s->fd, buf, size, 0);
if (len < 0) { if (len < 0) {
if (errno != EINTR && errno != EAGAIN) if (ff_neterrno() != FF_NETERROR(EINTR) &&
ff_neterrno() != FF_NETERROR(EAGAIN))
return AVERROR(errno); return AVERROR(errno);
continue; continue;
} }

View File

@ -428,7 +428,8 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
len = recvfrom (s->udp_fd, buf, size, 0, len = recvfrom (s->udp_fd, buf, size, 0,
(struct sockaddr *)&from, &from_len); (struct sockaddr *)&from, &from_len);
if (len < 0) { if (len < 0) {
if (errno != EAGAIN && errno != EINTR) if (ff_neterrno() != FF_NETERROR(EAGAIN) &&
ff_neterrno() != FF_NETERROR(EINTR))
return AVERROR_IO; return AVERROR_IO;
} else { } else {
break; break;
@ -451,7 +452,8 @@ static int udp_write(URLContext *h, uint8_t *buf, int size)
s->dest_addr_len); s->dest_addr_len);
#endif #endif
if (ret < 0) { if (ret < 0) {
if (errno != EINTR && errno != EAGAIN) if (ff_neterrno() != FF_NETERROR(EINTR) &&
ff_neterrno() != FF_NETERROR(EAGAIN))
return AVERROR_IO; return AVERROR_IO;
} else { } else {
break; break;