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