Commit b4a27a03 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Fix some implicit truncation and sign coersion in the networking APIs

Summary: Split out of an earlier pair of diffs, this focuses exclusively on Folly's networking APIs and works to eliminate places where values were being implicitly truncated.

Reviewed By: yfeldblum

Differential Revision: D4288042

fbshipit-source-id: dd6e19acd319296a45c29c8050dc62f06571e1e6
parent 4168732c
...@@ -89,7 +89,8 @@ CIDRNetwork IPAddress::createNetwork(StringPiece ipSlashCidr, ...@@ -89,7 +89,8 @@ CIDRNetwork IPAddress::createNetwork(StringPiece ipSlashCidr,
"'")); "'"));
} }
IPAddress subnet(vec.at(0)); IPAddress subnet(vec.at(0));
uint8_t cidr = (defaultCidr > -1) ? defaultCidr : (subnet.isV4() ? 32 : 128); uint8_t cidr =
(defaultCidr > -1) ? uint8_t(defaultCidr) : (subnet.isV4() ? 32 : 128);
if (elemCount == 2) { if (elemCount == 2) {
try { try {
......
...@@ -236,7 +236,7 @@ uint8_t IPAddressV4::getNthMSByte(size_t byteIndex) const { ...@@ -236,7 +236,7 @@ uint8_t IPAddressV4::getNthMSByte(size_t byteIndex) const {
} }
// protected // protected
const ByteArray4 IPAddressV4::fetchMask(size_t numBits) { const ByteArray4 IPAddressV4::fetchMask(size_t numBits) {
static const uint8_t bits = bitCount(); static const size_t bits = bitCount();
if (numBits > bits) { if (numBits > bits) {
throw IPAddressFormatException( throw IPAddressFormatException(
to<std::string>("IPv4 addresses are 32 bits")); to<std::string>("IPv4 addresses are 32 bits"));
......
...@@ -204,7 +204,7 @@ class IPAddressV4 { ...@@ -204,7 +204,7 @@ class IPAddressV4 {
std::string toFullyQualified() const { return str(); } std::string toFullyQualified() const { return str(); }
// @see IPAddress#version // @see IPAddress#version
size_t version() const { return 4; } uint8_t version() const { return 4; }
/** /**
* Return the mask associated with the given number of bits. * Return the mask associated with the given number of bits.
......
...@@ -89,7 +89,7 @@ IPAddressV6::IPAddressV6(StringPiece addr) { ...@@ -89,7 +89,7 @@ IPAddressV6::IPAddressV6(StringPiece addr) {
if (!getaddrinfo(ip.c_str(), nullptr, &hints, &result)) { if (!getaddrinfo(ip.c_str(), nullptr, &hints, &result)) {
struct sockaddr_in6* ipAddr = (struct sockaddr_in6*)result->ai_addr; struct sockaddr_in6* ipAddr = (struct sockaddr_in6*)result->ai_addr;
addr_.in6Addr_ = ipAddr->sin6_addr; addr_.in6Addr_ = ipAddr->sin6_addr;
scope_ = ipAddr->sin6_scope_id; scope_ = uint16_t(ipAddr->sin6_scope_id);
freeaddrinfo(result); freeaddrinfo(result);
} else { } else {
throw IPAddressFormatException( throw IPAddressFormatException(
...@@ -106,7 +106,7 @@ IPAddressV6::IPAddressV6(const in6_addr& src) ...@@ -106,7 +106,7 @@ IPAddressV6::IPAddressV6(const in6_addr& src)
// sockaddr_in6 constructor // sockaddr_in6 constructor
IPAddressV6::IPAddressV6(const sockaddr_in6& src) IPAddressV6::IPAddressV6(const sockaddr_in6& src)
: addr_(src.sin6_addr) : addr_(src.sin6_addr)
, scope_(src.sin6_scope_id) , scope_(uint16_t(src.sin6_scope_id))
{ {
} }
...@@ -384,7 +384,7 @@ uint8_t IPAddressV6::getNthMSByte(size_t byteIndex) const { ...@@ -384,7 +384,7 @@ uint8_t IPAddressV6::getNthMSByte(size_t byteIndex) const {
// protected // protected
const ByteArray16 IPAddressV6::fetchMask(size_t numBits) { const ByteArray16 IPAddressV6::fetchMask(size_t numBits) {
static const uint8_t bits = bitCount(); static const size_t bits = bitCount();
if (numBits > bits) { if (numBits > bits) {
throw IPAddressFormatException("IPv6 addresses are 128 bits."); throw IPAddressFormatException("IPv6 addresses are 128 bits.");
} }
......
...@@ -267,7 +267,7 @@ class IPAddressV6 { ...@@ -267,7 +267,7 @@ class IPAddressV6 {
std::string str() const; std::string str() const;
// @see IPAddress#version // @see IPAddress#version
size_t version() const { return 6; } uint8_t version() const { return 6; }
/** /**
* Return the solicited-node multicast address for this address. * Return the solicited-node multicast address for this address.
......
...@@ -128,7 +128,7 @@ void MacAddress::parse(StringPiece str) { ...@@ -128,7 +128,7 @@ void MacAddress::parse(StringPiece str) {
} }
// Update parsed with the newly parsed byte // Update parsed with the newly parsed byte
parsed[byteIndex] = ((upper << 4) | lower); parsed[byteIndex] = uint8_t((upper << 4) | lower);
} }
if (p != str.end()) { if (p != str.end()) {
......
...@@ -229,7 +229,7 @@ void SocketAddress::setFromPath(StringPiece path) { ...@@ -229,7 +229,7 @@ void SocketAddress::setFromPath(StringPiece path) {
} }
size_t len = path.size(); size_t len = path.size();
storage_.un.len = offsetof(struct sockaddr_un, sun_path) + len; storage_.un.len = socklen_t(offsetof(struct sockaddr_un, sun_path) + len);
memcpy(storage_.un.addr->sun_path, path.data(), len); memcpy(storage_.un.addr->sun_path, path.data(), len);
// If there is room, put a terminating NUL byte in sun_path. In general the // If there is room, put a terminating NUL byte in sun_path. In general the
// path should be NUL terminated, although getsockname() and getpeername() // path should be NUL terminated, although getsockname() and getpeername()
...@@ -631,7 +631,7 @@ struct addrinfo* SocketAddress::getAddrInfo(const char* host, ...@@ -631,7 +631,7 @@ struct addrinfo* SocketAddress::getAddrInfo(const char* host,
} }
void SocketAddress::setFromAddrInfo(const struct addrinfo* info) { void SocketAddress::setFromAddrInfo(const struct addrinfo* info) {
setFromSockaddr(info->ai_addr, info->ai_addrlen); setFromSockaddr(info->ai_addr, socklen_t(info->ai_addrlen));
} }
void SocketAddress::setFromLocalAddr(const struct addrinfo* info) { void SocketAddress::setFromLocalAddr(const struct addrinfo* info) {
...@@ -639,13 +639,13 @@ void SocketAddress::setFromLocalAddr(const struct addrinfo* info) { ...@@ -639,13 +639,13 @@ void SocketAddress::setFromLocalAddr(const struct addrinfo* info) {
// can be mapped into IPv6 space. // can be mapped into IPv6 space.
for (const struct addrinfo* ai = info; ai != nullptr; ai = ai->ai_next) { for (const struct addrinfo* ai = info; ai != nullptr; ai = ai->ai_next) {
if (ai->ai_family == AF_INET6) { if (ai->ai_family == AF_INET6) {
setFromSockaddr(ai->ai_addr, ai->ai_addrlen); setFromSockaddr(ai->ai_addr, socklen_t(ai->ai_addrlen));
return; return;
} }
} }
// Otherwise, just use the first address in the list. // Otherwise, just use the first address in the list.
setFromSockaddr(info->ai_addr, info->ai_addrlen); setFromSockaddr(info->ai_addr, socklen_t(info->ai_addrlen));
} }
void SocketAddress::setFromSocket( void SocketAddress::setFromSocket(
...@@ -707,7 +707,8 @@ void SocketAddress::updateUnixAddressLength(socklen_t addrlen) { ...@@ -707,7 +707,8 @@ void SocketAddress::updateUnixAddressLength(socklen_t addrlen) {
// Call strnlen(), just in case the length was overspecified. // Call strnlen(), just in case the length was overspecified.
socklen_t maxLength = addrlen - offsetof(struct sockaddr_un, sun_path); socklen_t maxLength = addrlen - offsetof(struct sockaddr_un, sun_path);
size_t pathLength = strnlen(storage_.un.addr->sun_path, maxLength); size_t pathLength = strnlen(storage_.un.addr->sun_path, maxLength);
storage_.un.len = offsetof(struct sockaddr_un, sun_path) + pathLength; storage_.un.len =
socklen_t(offsetof(struct sockaddr_un, sun_path) + pathLength);
} }
} }
......
...@@ -43,7 +43,7 @@ inline std::string familyNameStr(sa_family_t family) { ...@@ -43,7 +43,7 @@ inline std::string familyNameStr(sa_family_t family) {
template <typename IPAddrType> template <typename IPAddrType>
inline bool inline bool
getNthMSBitImpl(const IPAddrType& ip, uint8_t bitIndex, sa_family_t family) { getNthMSBitImpl(const IPAddrType& ip, size_t bitIndex, sa_family_t family) {
if (bitIndex >= ip.bitCount()) { if (bitIndex >= ip.bitCount()) {
getNthMSBitImplThrow(ip.bitCount(), family); getNthMSBitImplThrow(ip.bitCount(), family);
} }
......
...@@ -203,7 +203,7 @@ inline void writeIntegerString(IntegralType val, char** buffer) { ...@@ -203,7 +203,7 @@ inline void writeIntegerString(IntegralType val, char** buffer) {
} else { } else {
value += ('a' - 10); value += ('a' - 10);
} }
*(buf++) = value; *(buf++) = char(value);
val %= powerToPrint; val %= powerToPrint;
found = true; found = true;
} }
...@@ -227,7 +227,7 @@ inline std::string fastIpv4ToString(const in_addr& inAddr) { ...@@ -227,7 +227,7 @@ inline std::string fastIpv4ToString(const in_addr& inAddr) {
*(buf++) = '.'; *(buf++) = '.';
writeIntegerString<uint8_t, 3>(octets[3], &buf); writeIntegerString<uint8_t, 3>(octets[3], &buf);
return std::string(str, buf - str); return std::string(str, size_t(buf - str));
} }
inline std::string fastIpv6ToString(const in6_addr& in6Addr) { inline std::string fastIpv6ToString(const in6_addr& in6Addr) {
...@@ -251,7 +251,7 @@ inline std::string fastIpv6ToString(const in6_addr& in6Addr) { ...@@ -251,7 +251,7 @@ inline std::string fastIpv6ToString(const in6_addr& in6Addr) {
} }
} }
return std::string(str, buf - str); return std::string(str, size_t(buf - str));
} }
} }
} }
...@@ -730,7 +730,8 @@ void AsyncSSLSocket::startSSLConnect() { ...@@ -730,7 +730,8 @@ void AsyncSSLSocket::startSSLConnect() {
// Make end time at least >= start time. // Make end time at least >= start time.
handshakeEndTime_ = handshakeStartTime_; handshakeEndTime_ = handshakeStartTime_;
if (handshakeConnectTimeout_ > 0) { if (handshakeConnectTimeout_ > 0) {
handshakeTimeout_.scheduleTimeout(handshakeConnectTimeout_); handshakeTimeout_.scheduleTimeout(
std::chrono::milliseconds(handshakeConnectTimeout_));
} }
handleConnect(); handleConnect();
} }
...@@ -1159,9 +1160,8 @@ void AsyncSSLSocket::scheduleConnectTimeout() { ...@@ -1159,9 +1160,8 @@ void AsyncSSLSocket::scheduleConnectTimeout() {
assert(connectCallback_ == nullptr); assert(connectCallback_ == nullptr);
// We use a different connect timeout here than the handshake timeout, so // We use a different connect timeout here than the handshake timeout, so
// that we can disambiguate the 2 timers. // that we can disambiguate the 2 timers.
int timeout = connectTimeout_.count(); if (connectTimeout_.count() > 0) {
if (timeout > 0) { if (!connectionTimeout_.scheduleTimeout(connectTimeout_)) {
if (!connectionTimeout_.scheduleTimeout(timeout)) {
throw AsyncSocketException( throw AsyncSocketException(
AsyncSocketException::INTERNAL_ERROR, AsyncSocketException::INTERNAL_ERROR,
withAddr("failed to schedule AsyncSSLSocket connect timeout")); withAddr("failed to schedule AsyncSSLSocket connect timeout"));
...@@ -1234,9 +1234,9 @@ AsyncSSLSocket::performRead(void** buf, size_t* buflen, size_t* offset) { ...@@ -1234,9 +1234,9 @@ AsyncSSLSocket::performRead(void** buf, size_t* buflen, size_t* offset) {
return AsyncSocket::performRead(buf, buflen, offset); return AsyncSocket::performRead(buf, buflen, offset);
} }
ssize_t bytes = 0; int bytes = 0;
if (!isBufferMovable_) { if (!isBufferMovable_) {
bytes = SSL_read(ssl_, *buf, *buflen); bytes = SSL_read(ssl_, *buf, int(*buflen));
} }
#ifdef SSL_MODE_MOVE_BUFFER_OWNERSHIP #ifdef SSL_MODE_MOVE_BUFFER_OWNERSHIP
else { else {
...@@ -1451,17 +1451,17 @@ AsyncSocket::WriteResult AsyncSSLSocket::performWrite( ...@@ -1451,17 +1451,17 @@ AsyncSocket::WriteResult AsyncSSLSocket::performWrite(
bytes = eorAwareSSLWrite( bytes = eorAwareSSLWrite(
ssl_, ssl_,
sslWriteBuf, sslWriteBuf,
len, int(len),
(isSet(flags, WriteFlags::EOR) && i + buffersStolen + 1 == count)); (isSet(flags, WriteFlags::EOR) && i + buffersStolen + 1 == count));
if (bytes <= 0) { if (bytes <= 0) {
int error = SSL_get_error(ssl_, bytes); int error = SSL_get_error(ssl_, int(bytes));
if (error == SSL_ERROR_WANT_WRITE) { if (error == SSL_ERROR_WANT_WRITE) {
// The caller will register for write event if not already. // The caller will register for write event if not already.
*partialWritten = offset; *partialWritten = uint32_t(offset);
return WriteResult(totalWritten); return WriteResult(totalWritten);
} }
auto writeResult = interpretSSLError(bytes, error); auto writeResult = interpretSSLError(int(bytes), error);
if (writeResult.writeReturn < 0) { if (writeResult.writeReturn < 0) {
return writeResult; return writeResult;
} // else fall through to below to correctly record totalWritten } // else fall through to below to correctly record totalWritten
...@@ -1484,7 +1484,7 @@ AsyncSocket::WriteResult AsyncSSLSocket::performWrite( ...@@ -1484,7 +1484,7 @@ AsyncSocket::WriteResult AsyncSSLSocket::performWrite(
(*countWritten)++; (*countWritten)++;
v = &(vec[++i]); v = &(vec[++i]);
} }
*partialWritten = bytes; *partialWritten = uint32_t(bytes);
return WriteResult(totalWritten); return WriteResult(totalWritten);
} }
} }
...@@ -1576,11 +1576,11 @@ int AsyncSSLSocket::bioWrite(BIO* b, const char* in, int inl) { ...@@ -1576,11 +1576,11 @@ int AsyncSSLSocket::bioWrite(BIO* b, const char* in, int inl) {
OpenSSLUtils::getBioFd(b, nullptr), &msg, flags); OpenSSLUtils::getBioFd(b, nullptr), &msg, flags);
BIO_clear_retry_flags(b); BIO_clear_retry_flags(b);
if (!result.exception && result.writeReturn <= 0) { if (!result.exception && result.writeReturn <= 0) {
if (OpenSSLUtils::getBioShouldRetryWrite(result.writeReturn)) { if (OpenSSLUtils::getBioShouldRetryWrite(int(result.writeReturn))) {
BIO_set_retry_write(b); BIO_set_retry_write(b);
} }
} }
return result.writeReturn; return int(result.writeReturn);
} }
int AsyncSSLSocket::sslVerifyCallback( int AsyncSSLSocket::sslVerifyCallback(
......
...@@ -404,7 +404,7 @@ void AsyncServerSocket::bind(uint16_t port) { ...@@ -404,7 +404,7 @@ void AsyncServerSocket::bind(uint16_t port) {
} }
// Bind to the socket // Bind to the socket
if (fsp::bind(s, res->ai_addr, res->ai_addrlen) != 0) { if (fsp::bind(s, res->ai_addr, socklen_t(res->ai_addrlen)) != 0) {
folly::throwSystemError( folly::throwSystemError(
errno, errno,
"failed to bind to async server socket for port ", "failed to bind to async server socket for port ",
......
...@@ -84,7 +84,7 @@ void AsyncSignalHandler::libeventCallback(libevent_fd_t signum, ...@@ -84,7 +84,7 @@ void AsyncSignalHandler::libeventCallback(libevent_fd_t signum,
short /* events */, short /* events */,
void* arg) { void* arg) {
AsyncSignalHandler* handler = static_cast<AsyncSignalHandler*>(arg); AsyncSignalHandler* handler = static_cast<AsyncSignalHandler*>(arg);
handler->signalReceived(signum); handler->signalReceived(int(signum));
} }
} // folly } // folly
...@@ -489,10 +489,10 @@ int AsyncSocket::socketConnect(const struct sockaddr* saddr, socklen_t len) { ...@@ -489,10 +489,10 @@ int AsyncSocket::socketConnect(const struct sockaddr* saddr, socklen_t len) {
void AsyncSocket::scheduleConnectTimeout() { void AsyncSocket::scheduleConnectTimeout() {
// Connection in progress. // Connection in progress.
int timeout = connectTimeout_.count(); auto timeout = connectTimeout_.count();
if (timeout > 0) { if (timeout > 0) {
// Start a timer in case the connection takes too long. // Start a timer in case the connection takes too long.
if (!writeTimeout_.scheduleTimeout(timeout)) { if (!writeTimeout_.scheduleTimeout(uint32_t(timeout))) {
throw AsyncSocketException( throw AsyncSocketException(
AsyncSocketException::INTERNAL_ERROR, AsyncSocketException::INTERNAL_ERROR,
withAddr("failed to schedule AsyncSocket connect timeout")); withAddr("failed to schedule AsyncSocket connect timeout"));
...@@ -715,7 +715,7 @@ void AsyncSocket::writeImpl(WriteCallback* callback, const iovec* vec, ...@@ -715,7 +715,7 @@ void AsyncSocket::writeImpl(WriteCallback* callback, const iovec* vec,
uint32_t countWritten = 0; uint32_t countWritten = 0;
uint32_t partialWritten = 0; uint32_t partialWritten = 0;
int bytesWritten = 0; ssize_t bytesWritten = 0;
bool mustRegister = false; bool mustRegister = false;
if ((state_ == StateEnum::ESTABLISHED || state_ == StateEnum::FAST_OPEN) && if ((state_ == StateEnum::ESTABLISHED || state_ == StateEnum::FAST_OPEN) &&
!connecting()) { !connecting()) {
...@@ -725,8 +725,8 @@ void AsyncSocket::writeImpl(WriteCallback* callback, const iovec* vec, ...@@ -725,8 +725,8 @@ void AsyncSocket::writeImpl(WriteCallback* callback, const iovec* vec,
assert(writeReqTail_ == nullptr); assert(writeReqTail_ == nullptr);
assert((eventFlags_ & EventHandler::WRITE) == 0); assert((eventFlags_ & EventHandler::WRITE) == 0);
auto writeResult = auto writeResult = performWrite(
performWrite(vec, count, flags, &countWritten, &partialWritten); vec, uint32_t(count), flags, &countWritten, &partialWritten);
bytesWritten = writeResult.writeReturn; bytesWritten = writeResult.writeReturn;
if (bytesWritten < 0) { if (bytesWritten < 0) {
auto errnoCopy = errno; auto errnoCopy = errno;
...@@ -766,14 +766,20 @@ void AsyncSocket::writeImpl(WriteCallback* callback, const iovec* vec, ...@@ -766,14 +766,20 @@ void AsyncSocket::writeImpl(WriteCallback* callback, const iovec* vec,
// Create a new WriteRequest to add to the queue // Create a new WriteRequest to add to the queue
WriteRequest* req; WriteRequest* req;
try { try {
req = BytesWriteRequest::newRequest(this, callback, vec + countWritten, req = BytesWriteRequest::newRequest(
count - countWritten, partialWritten, this,
bytesWritten, std::move(ioBuf), flags); callback,
vec + countWritten,
uint32_t(count - countWritten),
partialWritten,
uint32_t(bytesWritten),
std::move(ioBuf),
flags);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
// we mainly expect to catch std::bad_alloc here // we mainly expect to catch std::bad_alloc here
AsyncSocketException tex(AsyncSocketException::INTERNAL_ERROR, AsyncSocketException tex(AsyncSocketException::INTERNAL_ERROR,
withAddr(string("failed to append new WriteRequest: ") + ex.what())); withAddr(string("failed to append new WriteRequest: ") + ex.what()));
return failWrite(__func__, callback, bytesWritten, tex); return failWrite(__func__, callback, size_t(bytesWritten), tex);
} }
req->consume(); req->consume();
if (writeReqTail_ == nullptr) { if (writeReqTail_ == nullptr) {
...@@ -1187,8 +1193,12 @@ int AsyncSocket::setCongestionFlavor(const std::string &cname) { ...@@ -1187,8 +1193,12 @@ int AsyncSocket::setCongestionFlavor(const std::string &cname) {
} }
if (setsockopt(fd_, IPPROTO_TCP, TCP_CONGESTION, cname.c_str(), if (setsockopt(
cname.length() + 1) != 0) { fd_,
IPPROTO_TCP,
TCP_CONGESTION,
cname.c_str(),
socklen_t(cname.length() + 1)) != 0) {
int errnoCopy = errno; int errnoCopy = errno;
VLOG(2) << "failed to update TCP_CONGESTION option on AsyncSocket " VLOG(2) << "failed to update TCP_CONGESTION option on AsyncSocket "
<< this << "(fd=" << fd_ << ", state=" << state_ << "): " << this << "(fd=" << fd_ << ", state=" << state_ << "): "
...@@ -1897,7 +1907,7 @@ AsyncSocket::WriteResult AsyncSocket::performWrite( ...@@ -1897,7 +1907,7 @@ AsyncSocket::WriteResult AsyncSocket::performWrite(
uint32_t bytesWritten; uint32_t bytesWritten;
uint32_t n; uint32_t n;
for (bytesWritten = totalWritten, n = 0; n < count; ++n) { for (bytesWritten = uint32_t(totalWritten), n = 0; n < count; ++n) {
const iovec* v = vec + n; const iovec* v = vec + n;
if (v->iov_len > bytesWritten) { if (v->iov_len > bytesWritten) {
// Partial write finished in the middle of this iovec // Partial write finished in the middle of this iovec
...@@ -1906,7 +1916,7 @@ AsyncSocket::WriteResult AsyncSocket::performWrite( ...@@ -1906,7 +1916,7 @@ AsyncSocket::WriteResult AsyncSocket::performWrite(
return WriteResult(totalWritten); return WriteResult(totalWritten);
} }
bytesWritten -= v->iov_len; bytesWritten -= uint32_t(v->iov_len);
} }
assert(bytesWritten == 0); assert(bytesWritten == 0);
......
...@@ -635,7 +635,7 @@ class AsyncSocket : virtual public AsyncTransportWrapper { ...@@ -635,7 +635,7 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
} }
void bytesWritten(size_t count) { void bytesWritten(size_t count) {
totalBytesWritten_ += count; totalBytesWritten_ += uint32_t(count);
socket_->appBytesWritten_ += count; socket_->appBytesWritten_ += count;
} }
......
...@@ -112,7 +112,7 @@ EventBase::EventBase(bool enableTimeMeasurement) ...@@ -112,7 +112,7 @@ EventBase::EventBase(bool enableTimeMeasurement)
, avgLoopTime_(2000000) , avgLoopTime_(2000000)
, maxLatencyLoopTime_(avgLoopTime_) , maxLatencyLoopTime_(avgLoopTime_)
, enableTimeMeasurement_(enableTimeMeasurement) , enableTimeMeasurement_(enableTimeMeasurement)
, nextLoopCnt_(-40) // Early wrap-around so bugs will manifest soon , nextLoopCnt_(uint64_t(-40)) // Early wrap-around so bugs will manifest soon
, latestLoopCnt_(nextLoopCnt_) , latestLoopCnt_(nextLoopCnt_)
, startWork_(0) , startWork_(0)
, observer_(nullptr) , observer_(nullptr)
...@@ -158,7 +158,7 @@ EventBase::EventBase(event_base* evb, bool enableTimeMeasurement) ...@@ -158,7 +158,7 @@ EventBase::EventBase(event_base* evb, bool enableTimeMeasurement)
, avgLoopTime_(2000000) , avgLoopTime_(2000000)
, maxLatencyLoopTime_(avgLoopTime_) , maxLatencyLoopTime_(avgLoopTime_)
, enableTimeMeasurement_(enableTimeMeasurement) , enableTimeMeasurement_(enableTimeMeasurement)
, nextLoopCnt_(-40) // Early wrap-around so bugs will manifest soon , nextLoopCnt_(uint64_t(-40)) // Early wrap-around so bugs will manifest soon
, latestLoopCnt_(nextLoopCnt_) , latestLoopCnt_(nextLoopCnt_)
, startWork_(0) , startWork_(0)
, observer_(nullptr) , observer_(nullptr)
...@@ -216,7 +216,7 @@ EventBase::~EventBase() { ...@@ -216,7 +216,7 @@ EventBase::~EventBase() {
VLOG(5) << "EventBase(): Destroyed."; VLOG(5) << "EventBase(): Destroyed.";
} }
int EventBase::getNotificationQueueSize() const { size_t EventBase::getNotificationQueueSize() const {
return queue_->size(); return queue_->size();
} }
...@@ -717,8 +717,8 @@ bool EventBase::scheduleTimeout(AsyncTimeout* obj, ...@@ -717,8 +717,8 @@ bool EventBase::scheduleTimeout(AsyncTimeout* obj,
assert(isInEventBaseThread()); assert(isInEventBaseThread());
// Set up the timeval and add the event // Set up the timeval and add the event
struct timeval tv; struct timeval tv;
tv.tv_sec = timeout.count() / 1000LL; tv.tv_sec = long(timeout.count() / 1000LL);
tv.tv_usec = (timeout.count() % 1000LL) * 1000LL; tv.tv_usec = long((timeout.count() % 1000LL) * 1000LL);
struct event* ev = obj->getEvent(); struct event* ev = obj->getEvent();
if (event_add(ev, &tv) < 0) { if (event_add(ev, &tv) < 0) {
......
...@@ -443,7 +443,7 @@ class EventBase : private boost::noncopyable, ...@@ -443,7 +443,7 @@ class EventBase : private boost::noncopyable,
*/ */
void waitUntilRunning(); void waitUntilRunning();
int getNotificationQueueSize() const; size_t getNotificationQueueSize() const;
void setMaxReadAtOnce(uint32_t maxAtOnce); void setMaxReadAtOnce(uint32_t maxAtOnce);
......
...@@ -152,8 +152,7 @@ class EventHandler : private boost::noncopyable { ...@@ -152,8 +152,7 @@ class EventHandler : private boost::noncopyable {
* Return the set of events that we're currently registered for. * Return the set of events that we're currently registered for.
*/ */
uint16_t getRegisteredEvents() const { uint16_t getRegisteredEvents() const {
return (isHandlerRegistered()) ? return (isHandlerRegistered()) ? uint16_t(event_.ev_events) : 0u;
event_.ev_events : 0;
} }
/** /**
......
...@@ -281,7 +281,7 @@ size_t HHWheelTimer::cancelAll() { ...@@ -281,7 +281,7 @@ size_t HHWheelTimer::cancelAll() {
void HHWheelTimer::scheduleNextTimeout() { void HHWheelTimer::scheduleNextTimeout() {
auto nextTick = calcNextTick(); auto nextTick = calcNextTick();
long tick = 1; int64_t tick = 1;
if (nextTick & WHEEL_MASK) { if (nextTick & WHEEL_MASK) {
auto bi = makeBitIterator(bitmap_.begin()); auto bi = makeBitIterator(bitmap_.begin());
......
...@@ -488,17 +488,17 @@ class NotificationQueue { ...@@ -488,17 +488,17 @@ class NotificationQueue {
} }
ssize_t bytes_written = 0; ssize_t bytes_written = 0;
ssize_t bytes_expected = 0; size_t bytes_expected = 0;
do { do {
if (eventfd_ >= 0) { if (eventfd_ >= 0) {
// eventfd(2) dictates that we must write a 64-bit integer // eventfd(2) dictates that we must write a 64-bit integer
uint64_t signal = 1; uint64_t signal = 1;
bytes_expected = static_cast<ssize_t>(sizeof(signal)); bytes_expected = sizeof(signal);
bytes_written = ::write(eventfd_, &signal, bytes_expected); bytes_written = ::write(eventfd_, &signal, bytes_expected);
} else { } else {
uint8_t signal = 1; uint8_t signal = 1;
bytes_expected = static_cast<ssize_t>(sizeof(signal)); bytes_expected = sizeof(signal);
bytes_written = ::write(pipeFds_[1], &signal, bytes_expected); bytes_written = ::write(pipeFds_[1], &signal, bytes_expected);
} }
} while (bytes_written == -1 && errno == EINTR); } while (bytes_written == -1 && errno == EINTR);
...@@ -510,7 +510,7 @@ class NotificationQueue { ...@@ -510,7 +510,7 @@ class NotificationQueue {
} }
#endif #endif
if (bytes_written == bytes_expected) { if (bytes_written == ssize_t(bytes_expected)) {
signal_ = true; signal_ = true;
} else { } else {
#ifdef __ANDROID__ #ifdef __ANDROID__
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment