mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-21 12:43:57 +00:00
Move new code out of network::socket
This commit is contained in:
@@ -254,7 +254,7 @@ namespace
|
||||
{
|
||||
int16_t socket_events{};
|
||||
|
||||
if (poll_events & (AFD_POLL_ACCEPT | AFD_POLL_RECEIVE))
|
||||
if (poll_events & (AFD_POLL_DISCONNECT | AFD_POLL_ACCEPT | AFD_POLL_RECEIVE))
|
||||
{
|
||||
socket_events |= POLLRDNORM;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,17 @@ namespace network
|
||||
|
||||
bool socket_wrapper::is_listening()
|
||||
{
|
||||
return this->socket_.is_listening();
|
||||
if (!this->socket_.is_valid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int val{};
|
||||
socklen_t len = sizeof(val);
|
||||
const auto res =
|
||||
getsockopt(this->socket_.get_socket(), SOL_SOCKET, SO_ACCEPTCONN, reinterpret_cast<char*>(&val), &len);
|
||||
|
||||
return res != SOCKET_ERROR && val == 1;
|
||||
}
|
||||
|
||||
bool socket_wrapper::bind(const address& addr)
|
||||
@@ -40,22 +50,27 @@ namespace network
|
||||
|
||||
bool socket_wrapper::connect(const address& addr)
|
||||
{
|
||||
return this->socket_.connect(addr);
|
||||
return ::connect(this->socket_.get_socket(), &addr.get_addr(), addr.get_size()) == 0;
|
||||
}
|
||||
|
||||
bool socket_wrapper::listen(int backlog)
|
||||
{
|
||||
return this->socket_.listen(backlog);
|
||||
return ::listen(this->socket_.get_socket(), backlog) == 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<i_socket> socket_wrapper::accept(address& address)
|
||||
{
|
||||
const auto s = this->socket_.accept(address);
|
||||
sockaddr addr{};
|
||||
socklen_t addrlen = sizeof(sockaddr);
|
||||
const auto s = ::accept(this->socket_.get_socket(), &addr, &addrlen);
|
||||
|
||||
if (s == INVALID_SOCKET)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
address.set_address(&addr, addrlen);
|
||||
|
||||
return std::make_unique<socket_wrapper>(s);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user