| 1042 | } |
| 1043 | |
| 1044 | static int udp_write(URLContext *h, const uint8_t *buf, int size) |
| 1045 | { |
| 1046 | UDPContext *s = h->priv_data; |
| 1047 | int ret; |
| 1048 | |
| 1049 | #if HAVE_PTHREAD_CANCEL |
| 1050 | if (s->tx_fifo) { |
| 1051 | uint8_t tmp[4]; |
| 1052 | |
| 1053 | pthread_mutex_lock(&s->mutex); |
| 1054 | |
| 1055 | /* |
| 1056 | Return error if last tx failed. |
| 1057 | Here we can't know on which packet error was, but it needs to know that error exists. |
| 1058 | */ |
| 1059 | if (s->circular_buffer_error<0) { |
| 1060 | int err = s->circular_buffer_error; |
| 1061 | pthread_mutex_unlock(&s->mutex); |
| 1062 | return err; |
| 1063 | } |
| 1064 | |
| 1065 | if (av_fifo_can_write(s->tx_fifo) < size + 4) { |
| 1066 | /* What about a partial packet tx ? */ |
| 1067 | pthread_mutex_unlock(&s->mutex); |
| 1068 | return AVERROR(ENOMEM); |
| 1069 | } |
| 1070 | AV_WL32(tmp, size); |
| 1071 | av_fifo_write(s->tx_fifo, tmp, 4); /* size of packet */ |
| 1072 | av_fifo_write(s->tx_fifo, buf, size); /* the data */ |
| 1073 | pthread_cond_signal(&s->cond); |
| 1074 | pthread_mutex_unlock(&s->mutex); |
| 1075 | return size; |
| 1076 | } |
| 1077 | #endif |
| 1078 | if (!(h->flags & AVIO_FLAG_NONBLOCK)) { |
| 1079 | ret = ff_network_wait_fd(s->udp_fd, 1); |
| 1080 | if (ret < 0) |
| 1081 | return ret; |
| 1082 | } |
| 1083 | |
| 1084 | if (!s->is_connected) { |
| 1085 | ret = sendto (s->udp_fd, buf, size, 0, |
| 1086 | (struct sockaddr *) &s->dest_addr, |
| 1087 | s->dest_addr_len); |
| 1088 | } else |
| 1089 | ret = send(s->udp_fd, buf, size, 0); |
| 1090 | |
| 1091 | return ret < 0 ? ff_neterrno() : ret; |
| 1092 | } |
| 1093 | |
| 1094 | static int udp_close(URLContext *h) |
| 1095 | { |
nothing calls this directly
no test coverage detected