Better logging of NativeFd.

GitOrigin-RevId: 4d094f01a74c46acb5d4a0c8da4e67614bec1b6e
This commit is contained in:
levlam 2018-09-11 19:44:37 +03:00
parent cc077a3971
commit eff963a7c1
4 changed files with 22 additions and 24 deletions

View File

@ -283,7 +283,6 @@ class OpenClose final : public Actor {
auto r_file_fd = FileFd::open("server", FileFd::Read | FileFd::Create);
CHECK(r_file_fd.is_ok()) << r_file_fd.error();
auto file_fd = r_file_fd.move_as_ok();
// LOG(ERROR) << file_fd.get_native_fd();
file_fd.get_poll_info().extract_pollable_fd(observer);
file_fd.close();
cnt_--;

View File

@ -40,7 +40,7 @@ namespace detail {
class ServerSocketFdImpl : private Iocp::Callback {
public:
ServerSocketFdImpl(NativeFd fd, int socket_family) : info_(std::move(fd)), socket_family_(socket_family) {
VLOG(fd) << get_native_fd().socket() << " create ServerSocketFd";
VLOG(fd) << get_native_fd() << " create ServerSocketFd";
Iocp::get()->subscribe(get_native_fd(), this);
notify_iocp_read();
}
@ -105,11 +105,11 @@ class ServerSocketFdImpl : private Iocp::Callback {
info_.set_native_fd({});
}
void on_read() {
VLOG(fd) << get_native_fd().socket() << " on_read";
VLOG(fd) << get_native_fd() << " on_read";
if (is_read_active_) {
is_read_active_ = false;
auto r_socket = SocketFd::from_native_fd(std::move(accept_socket_));
VLOG(fd) << get_native_fd().socket() << " finish accept";
VLOG(fd) << get_native_fd() << " finish accept";
if (r_socket.is_error()) {
return on_error(r_socket.move_as_error());
}
@ -125,7 +125,7 @@ class ServerSocketFdImpl : private Iocp::Callback {
CHECK(!is_read_active_);
accept_socket_ = NativeFd(socket(socket_family_, SOCK_STREAM, 0));
std::memset(&read_overlapped_, 0, sizeof(read_overlapped_));
VLOG(fd) << get_native_fd().socket() << " start accept";
VLOG(fd) << get_native_fd() << " start accept";
BOOL status = AcceptEx(get_native_fd().socket(), accept_socket_.socket(), addr_buf_, 0, MAX_ADDR_SIZE,
MAX_ADDR_SIZE, nullptr, &read_overlapped_);
if (status == TRUE || check_status("Failed to accept connection")) {
@ -183,12 +183,12 @@ class ServerSocketFdImpl : private Iocp::Callback {
UNREACHABLE();
}
void notify_iocp_read() {
VLOG(fd) << get_native_fd().socket() << " notify_read";
VLOG(fd) << get_native_fd() << " notify_read";
inc_refcnt();
Iocp::get()->post(0, this, nullptr);
}
void notify_iocp_close() {
VLOG(fd) << get_native_fd().socket() << " notify_close";
VLOG(fd) << get_native_fd() << " notify_close";
Iocp::get()->post(0, this, reinterpret_cast<WSAOVERLAPPED *>(&close_overlapped_));
}
};

View File

@ -36,7 +36,7 @@ namespace detail {
class SocketFdImpl : private Iocp::Callback {
public:
explicit SocketFdImpl(NativeFd native_fd) : info(std::move(native_fd)) {
VLOG(fd) << get_native_fd().socket() << " create from native_fd";
VLOG(fd) << get_native_fd() << " create from native_fd";
get_poll_info().add_flags(PollFlags::Write());
Iocp::get()->subscribe(get_native_fd(), this);
is_read_active_ = true;
@ -44,7 +44,7 @@ class SocketFdImpl : private Iocp::Callback {
}
SocketFdImpl(NativeFd native_fd, const IPAddress &addr) : info(std::move(native_fd)) {
VLOG(fd) << get_native_fd().socket() << " create from native_fd and connect";
VLOG(fd) << get_native_fd() << " create from native_fd and connect";
get_poll_info().add_flags(PollFlags::Write());
Iocp::get()->subscribe(get_native_fd(), this);
LPFN_CONNECTEX ConnectExPtr = nullptr;
@ -232,7 +232,7 @@ class SocketFdImpl : private Iocp::Callback {
}
void on_error(Status status) {
VLOG(fd) << get_native_fd().socket() << " on error " << status;
VLOG(fd) << get_native_fd() << " on error " << status;
{
auto lock = lock_.lock();
pending_errors_.push(std::move(status));
@ -241,7 +241,7 @@ class SocketFdImpl : private Iocp::Callback {
}
void on_connected() {
VLOG(fd) << get_native_fd().socket() << " on connected";
VLOG(fd) << get_native_fd() << " on connected";
CHECK(!is_connected_);
CHECK(is_read_active_);
is_connected_ = true;
@ -251,7 +251,7 @@ class SocketFdImpl : private Iocp::Callback {
}
void on_read(size_t size) {
VLOG(fd) << get_native_fd().socket() << " on read " << size;
VLOG(fd) << get_native_fd() << " on read " << size;
CHECK(is_read_active_);
is_read_active_ = false;
if (size == 0) {
@ -264,7 +264,7 @@ class SocketFdImpl : private Iocp::Callback {
}
void on_write(size_t size) {
VLOG(fd) << get_native_fd().socket() << " on write " << size;
VLOG(fd) << get_native_fd() << " on write " << size;
if (size == 0) {
if (is_write_active_) {
return;
@ -278,12 +278,12 @@ class SocketFdImpl : private Iocp::Callback {
}
void on_close() {
VLOG(fd) << get_native_fd().socket() << " on close";
VLOG(fd) << get_native_fd() << " on close";
close_flag_ = true;
info.set_native_fd({});
}
bool dec_refcnt() {
VLOG(fd) << get_native_fd().socket() << " dec_refcnt from " << refcnt_;
VLOG(fd) << get_native_fd() << " dec_refcnt from " << refcnt_;
if (--refcnt_ == 0) {
delete this;
return true;
@ -293,7 +293,7 @@ class SocketFdImpl : private Iocp::Callback {
void inc_refcnt() {
CHECK(refcnt_ != 0);
refcnt_++;
VLOG(fd) << get_native_fd().socket() << " inc_refcnt to " << refcnt_;
VLOG(fd) << get_native_fd() << " inc_refcnt to " << refcnt_;
}
void notify_iocp_write() {

View File

@ -272,7 +272,7 @@ class UdpSocketFdImpl : private Iocp::Callback {
}
void on_error(Status status) {
VLOG(fd) << get_native_fd().socket() << " on error " << status;
VLOG(fd) << get_native_fd() << " on error " << status;
{
auto lock = lock_.lock();
pending_errors_.push(std::move(status));
@ -281,7 +281,7 @@ class UdpSocketFdImpl : private Iocp::Callback {
}
void on_connected() {
VLOG(fd) << get_native_fd().socket() << " on connected";
VLOG(fd) << get_native_fd() << " on connected";
CHECK(!is_connected_);
CHECK(is_receive_active_);
is_connected_ = true;
@ -291,7 +291,7 @@ class UdpSocketFdImpl : private Iocp::Callback {
}
void on_receive(size_t size) {
VLOG(fd) << get_native_fd().socket() << " on receive " << size;
VLOG(fd) << get_native_fd() << " on receive " << size;
CHECK(is_receive_active_);
is_receive_active_ = false;
receive_helper_.from_native(receive_message_, size, to_receive_);
@ -306,7 +306,7 @@ class UdpSocketFdImpl : private Iocp::Callback {
}
void on_send(size_t size) {
VLOG(fd) << get_native_fd().socket() << " on send " << size;
VLOG(fd) << get_native_fd() << " on send " << size;
if (size == 0) {
if (is_send_active_) {
return;
@ -319,7 +319,7 @@ class UdpSocketFdImpl : private Iocp::Callback {
}
void on_close() {
VLOG(fd) << get_native_fd().socket() << " on close";
VLOG(fd) << get_native_fd() << " on close";
close_flag_ = true;
info_.set_native_fd({});
}
@ -527,8 +527,7 @@ class UdpSocketFdImpl {
return Status::OK();
}
auto error =
Status::PosixError(recvmsg_errno, PSLICE() << "Receive from [fd=" << get_native_fd() << "] has failed");
auto error = Status::PosixError(recvmsg_errno, PSLICE() << "Receive from " << get_native_fd() << " has failed");
switch (recvmsg_errno) {
case EBADF:
case EFAULT:
@ -575,7 +574,7 @@ class UdpSocketFdImpl {
return Status::OK();
}
auto error = Status::PosixError(sendmsg_errno, PSLICE() << "Send from [fd=" << get_native_fd() << "] has failed");
auto error = Status::PosixError(sendmsg_errno, PSLICE() << "Send from " << get_native_fd() << " has failed");
switch (sendmsg_errno) {
// Still may send some other packets, but there is no point to resend this particular message
case EACCES: