This commit is contained in:
azw 2023-04-17 03:46:22 +00:00
parent 448879ecaa
commit 03489644bf
2 changed files with 5 additions and 7 deletions

View File

@ -58,7 +58,7 @@ namespace a8
listen_socket = ::socket(AF_INET, SOCK_DGRAM, 0);
if (listen_socket == -1){
if (master->on_error) {
master->on_error(master, errno);
master->on_error(errno);
}
return false;
}
@ -74,7 +74,7 @@ namespace a8
sa.sin_port = htons(master->bind_port);
if (::bind(listen_socket, (sockaddr*)&sa, sizeof(sa)) < 0) {
if (master->on_error) {
master->on_error(master, errno);
master->on_error(errno);
}
::close(listen_socket);
listen_socket = -1;
@ -113,9 +113,7 @@ namespace a8
(struct sockaddr*)&destAddr,
(socklen_t*)&addrLen);
if(ret > 0) {
#if 0
master->OnSocketRead(recv_buf, ret);
#endif
master->on_recv_packet(nullptr);
}
}
}

View File

@ -20,8 +20,8 @@ namespace a8
class UdpListener
{
public:
std::function<void (a8::UdpListener*, int error_id)> on_error;
std::function<void (a8::UdpListener*, UdpPacket*)> on_recv_packet;
std::function<void (int error_id)> on_error;
std::function<void (UdpPacket*)> on_recv_packet;
std::string bind_address;
unsigned short bind_port = 0;