free(ut);
}
+#define UDP_CQ_BYTES 40000
+
+static int udp_init_session(struct udp_target *ut)
+{
+ int ret;
+
+ if (ut->fd >= 0) /* nothing to do */
+ return 0;
+ ret = create_udp_send_socket(TARGET_ADDR(ut), ut->port,
+ conf.udp_ttl_arg);
+ if (ret < 0)
+ return ret;
+ ut->fd = ret;
+ ret = mark_fd_nonblocking(ut->fd);
+ if (ret < 0) {
+ close(ut->fd);
+ return ret;
+ }
+ add_close_on_fork_list(ut->fd);
+ ut->cq = cq_new(UDP_CQ_BYTES);
+ PARA_NOTICE_LOG("sending to udp %s:%d\n", TARGET_ADDR(ut), ut->port);
+ return 1;
+}
+
static void udp_send_buf(char *buf, size_t len)
{
struct udp_target *ut, *tmp;
int ret;
list_for_each_entry_safe(ut, tmp, &targets, node) {
- if (ut->fd < 0)
+ ret = udp_init_session(ut);
+ if (ret < 0) {
+ udp_delete_target(ut, para_strerror(-ret));
continue;
+ }
ret = send_queued_chunks(ut->fd, ut->cq, 0);
if (ret < 0) {
udp_delete_target(ut, para_strerror(-ret));
}
}
-#define UDP_CQ_BYTES 40000
-
-static int udp_init_session(struct udp_target *ut)
-{
- int ret;
-
- if (ut->fd >= 0) /* nothing to do */
- return 0;
- PARA_NOTICE_LOG("sending to udp %s:%d\n", TARGET_ADDR(ut), ut->port);
- ret = create_udp_send_socket(TARGET_ADDR(ut), ut->port,
- conf.udp_ttl_arg);
- if (ret < 0)
- return ret;
- ut->fd = ret;
- ret = mark_fd_nonblocking(ut->fd);
- if (ret < 0) {
- close(ut->fd);
- return ret;
- }
- add_close_on_fork_list(ut->fd);
- ut->cq = cq_new(UDP_CQ_BYTES);
- return 1;
-}
-
static void udp_shutdown_targets(void)
{
char buf[UDP_AUDIO_HEADER_LEN];
const char *buf, size_t len, const char *header_buf,
size_t header_len)
{
- struct udp_target *ut, *tmp;
size_t sendbuf_len;
uint8_t packet_type = UDP_DATA_PACKET;
- int ret;
char *sendbuf;
struct timeval *chunk_tv;
uint8_t stream_type = header_len? UDP_HEADER_STREAM : UDP_PLAIN_STREAM;
-// PARA_NOTICE_LOG("header_len: %zd, header_buf: %p\n", header_len,
-// header_buf);
+// PARA_NOTICE_LOG("len: %zd, header_len: %zd\n", len, header_len);
if (sender_status != SENDER_ON)
return;
return;
if (list_empty(&targets))
return;
- list_for_each_entry_safe(ut, tmp, &targets, node) {
- ret = udp_init_session(ut);
- if (ret < 0)
- udp_delete_target(ut, para_strerror(-ret));
- }
if (!need_extra_header(current_chunk))
header_len = 0;
if (!current_chunk)