Fixed IPv6

This commit is contained in:
WolverinDEV 2020-05-19 11:27:57 +02:00
parent 438b2ad1c6
commit a8694b6adf

View File

@ -76,21 +76,21 @@ void UDPSocket::finalize() {
return;
unique_lock lock(this->io_lock);
auto event_read = std::exchange(this->event_read, nullptr);
auto event_write = std::exchange(this->event_write, nullptr);
auto io_base = std::exchange(this->io_base, nullptr);
auto ev_read = std::exchange(this->event_read, nullptr);
auto ev_write = std::exchange(this->event_write, nullptr);
auto io_base_loop = std::exchange(this->io_base, nullptr);
lock.unlock();
if(is_event_thread) {
if(event_read) event_del_block(event_read);
if(event_write) event_del_block(event_write);
if(ev_read) event_del_block(ev_read);
if(ev_write) event_del_block(ev_write);
} else {
if(event_read) event_del_noblock(event_read);
if(event_write) event_del_noblock(event_write);
if(ev_read) event_del_noblock(ev_read);
if(ev_write) event_del_noblock(ev_write);
}
if(io_base) {
event_base_loopexit(io_base, nullptr);
if(io_base_loop) {
event_base_loopexit(io_base_loop, nullptr);
}
if(is_event_thread) {
@ -132,15 +132,15 @@ void UDPSocket::io_execute(void* ptr_event_base) {
event_base_free(base);
}
void UDPSocket::callback_read(evutil_socket_t fd) {
sockaddr source_address{};
sockaddr_storage source_address{};
socklen_t source_address_length;
ssize_t read_length = -1;
size_t buffer_length = 1600; /* IPv6 MTU is ~1.5k */
char buffer[1600];
source_address_length = sizeof(sockaddr);
read_length = recvfrom(fd, (char*) buffer, (int) buffer_length, MSG_DONTWAIT, &source_address, &source_address_length);
source_address_length = sizeof(sockaddr_storage);
read_length = recvfrom(fd, (char*) buffer, (int) buffer_length, MSG_DONTWAIT, (sockaddr*) &source_address, &source_address_length);
if(read_length <= 0) {
int error;
#ifdef WIN32