From 02340285c564a7e82105137192d46d554a6fce3a Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Sun, 30 May 2021 20:37:54 +0100 Subject: Added -Wshorten-64-to-32 and fixed all warnings. --- src/inspsocket.cpp | 67 +++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 31 deletions(-) (limited to 'src/inspsocket.cpp') diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index adbd5e7be..480347fd2 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -55,7 +55,7 @@ BufferedSocket::BufferedSocket(int newfd) SocketEngine::AddFd(this, FD_WANT_FAST_READ | FD_WANT_EDGE_WRITE); } -void BufferedSocket::DoConnect(const irc::sockets::sockaddrs& dest, const irc::sockets::sockaddrs& bind, unsigned int maxtime) +void BufferedSocket::DoConnect(const irc::sockets::sockaddrs& dest, const irc::sockets::sockaddrs& bind, unsigned long maxtime) { BufferedSocketError err = BeginConnect(dest, bind, maxtime); if (err != I_ERR_NONE) @@ -66,7 +66,7 @@ void BufferedSocket::DoConnect(const irc::sockets::sockaddrs& dest, const irc::s } } -BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs& dest, const irc::sockets::sockaddrs& bind, unsigned int timeout) +BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs& dest, const irc::sockets::sockaddrs& bind, unsigned long timeout) { if (!HasFd()) fd = socket(dest.family(), SOCK_STREAM, 0); @@ -139,7 +139,7 @@ Cullable::Result StreamSocket::Cull() return EventHandler::Cull(); } -int StreamSocket::HookChainRead(IOHook* hook, std::string& rq) +long StreamSocket::HookChainRead(IOHook* hook, std::string& rq) { if (!hook) return ReadToRecvQ(rq); @@ -148,7 +148,7 @@ int StreamSocket::HookChainRead(IOHook* hook, std::string& rq) if (iohm) { // Call the next hook to put data into the recvq of the current hook - const int ret = HookChainRead(iohm->GetNextHook(), iohm->GetRecvQ()); + const long ret = HookChainRead(iohm->GetNextHook(), iohm->GetRecvQ()); if (ret <= 0) return ret; } @@ -159,7 +159,7 @@ void StreamSocket::DoRead() { const std::string::size_type prevrecvqsize = recvq.size(); - const int result = HookChainRead(GetIOHook(), recvq); + const long result = HookChainRead(GetIOHook(), recvq); if (result < 0) { SetError("Read Error"); // will not overwrite a better error message @@ -170,42 +170,46 @@ void StreamSocket::DoRead() OnDataReady(); } -int StreamSocket::ReadToRecvQ(std::string& rq) +long StreamSocket::ReadToRecvQ(std::string& rq) { - char* ReadBuffer = ServerInstance->GetReadBuffer(); - int n = SocketEngine::Recv(this, ReadBuffer, ServerInstance->Config->NetBufferSize, 0); - if (n == ServerInstance->Config->NetBufferSize) + char* ReadBuffer = ServerInstance->GetReadBuffer(); + ssize_t n = SocketEngine::Recv(this, ReadBuffer, ServerInstance->Config->NetBufferSize, 0); + if (n >= 0) + { + unsigned long nrecv = static_cast(n); + if (nrecv == ServerInstance->Config->NetBufferSize) { SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ); rq.append(ReadBuffer, n); } - else if (n > 0) + else if (nrecv > 0) { SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ); rq.append(ReadBuffer, n); } - else if (n == 0) + else if (nrecv == 0) { error = "Connection closed"; SocketEngine::ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); return -1; } - else if (SocketEngine::IgnoreError()) - { - SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_READ_WILL_BLOCK); - return 0; - } - else if (errno == EINTR) - { - SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ); - return 0; - } - else - { - error = SocketEngine::LastError(); - SocketEngine::ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); - return -1; - } + } + else if (SocketEngine::IgnoreError()) + { + SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_READ_WILL_BLOCK); + return 0; + } + else if (errno == EINTR) + { + SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ); + return 0; + } + else + { + error = SocketEngine::LastError(); + SocketEngine::ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); + return -1; + } return n; } @@ -231,7 +235,7 @@ void StreamSocket::DoWrite() IOHook* hook = GetIOHook(); while (hook) { - int rv = hook->OnStreamSocketWrite(this, *psendq); + ssize_t rv = hook->OnStreamSocketWrite(this, *psendq); psendq = NULL; // rv == 0 means the socket has blocked. Stop trying to send data. @@ -270,8 +274,9 @@ void StreamSocket::FlushSendQ(SendQueue& sq) int eventChange = FD_WANT_EDGE_WRITE; while (error.empty() && !sq.empty() && eventChange == FD_WANT_EDGE_WRITE) { - // Prepare a writev() call to write all buffers efficiently - int bufcount = sq.size(); + // Prepare a writev() call to write all buffers efficiently. This cast is + // safe as we clamp to MYIOV_MAX right away anyway. + int bufcount = static_cast(sq.size()); // cap the number of buffers at MYIOV_MAX if (bufcount > MYIOV_MAX) @@ -280,7 +285,7 @@ void StreamSocket::FlushSendQ(SendQueue& sq) } int rv_max = 0; - int rv; + ssize_t rv; { SocketEngine::IOVector iovecs[MYIOV_MAX]; size_t j = 0; -- cgit v1.3.1-10-gc9f91