r = dns_stream_update_io(s);
if (r < 0)
return dns_stream_complete(s, -r);
+
+ s->packet_received = true;
}
}
}
- /* Call "complete" callback if finished reading and writing one packet, and there's nothing else left
- * to write. */
- if (s->type == DNS_STREAM_LLMNR_SEND &&
- (s->write_packet && s->n_written >= sizeof(s->write_size) + s->write_packet->size) &&
- ordered_set_isempty(s->write_queue) &&
- (s->read_packet && s->n_read >= sizeof(s->read_size) + s->read_packet->size))
- return dns_stream_complete(s, 0);
+ if (s->type == DNS_STREAM_LLMNR_SEND && s->packet_received) {
+ uint32_t events;
+
+ /* Complete the stream if finished reading and writing one packet, and there's nothing
+ * else left to write. */
+
+ r = sd_event_source_get_io_events(s->io_event_source, &events);
+ if (r < 0)
+ return r;
+
+ if (!FLAGS_SET(events, EPOLLOUT))
+ return dns_stream_complete(s, 0);
+ }
/* If we did something, let's restart the timeout event source */
if (progressed && s->timeout_event_source) {
} else
log_debug("Invalid LLMNR TCP packet, ignoring.");
- dns_stream_unref(s);
return 0;
}
return -errno;
}
- /* We don't configure a "complete" handler here, we rely on the default handler than simply drops the
- * reference to the stream, thus freeing it */
+ /* We don't configure a "complete" handler here, we rely on the default handler, thus freeing it */
r = dns_stream_new(m, &stream, DNS_STREAM_LLMNR_RECV, DNS_PROTOCOL_LLMNR, cfd, NULL,
on_llmnr_stream_packet, NULL, DNS_STREAM_DEFAULT_TIMEOUT_USEC);
if (r < 0) {