"'"));
}
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) {
try {
}
// protected
const ByteArray4 IPAddressV4::fetchMask(size_t numBits) {
- static const uint8_t bits = bitCount();
+ static const size_t bits = bitCount();
if (numBits > bits) {
throw IPAddressFormatException(
to<std::string>("IPv4 addresses are 32 bits"));
std::string toFullyQualified() const { return str(); }
// @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.
if (!getaddrinfo(ip.c_str(), nullptr, &hints, &result)) {
struct sockaddr_in6* ipAddr = (struct sockaddr_in6*)result->ai_addr;
addr_.in6Addr_ = ipAddr->sin6_addr;
- scope_ = ipAddr->sin6_scope_id;
+ scope_ = uint16_t(ipAddr->sin6_scope_id);
freeaddrinfo(result);
} else {
throw IPAddressFormatException(
// sockaddr_in6 constructor
IPAddressV6::IPAddressV6(const sockaddr_in6& src)
: addr_(src.sin6_addr)
- , scope_(src.sin6_scope_id)
+ , scope_(uint16_t(src.sin6_scope_id))
{
}
// protected
const ByteArray16 IPAddressV6::fetchMask(size_t numBits) {
- static const uint8_t bits = bitCount();
+ static const size_t bits = bitCount();
if (numBits > bits) {
throw IPAddressFormatException("IPv6 addresses are 128 bits.");
}
std::string str() const;
// @see IPAddress#version
- size_t version() const { return 6; }
+ uint8_t version() const { return 6; }
/**
* Return the solicited-node multicast address for this address.
}
// Update parsed with the newly parsed byte
- parsed[byteIndex] = ((upper << 4) | lower);
+ parsed[byteIndex] = uint8_t((upper << 4) | lower);
}
if (p != str.end()) {
}
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);
// If there is room, put a terminating NUL byte in sun_path. In general the
// path should be NUL terminated, although getsockname() and getpeername()
}
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) {
// can be mapped into IPv6 space.
for (const struct addrinfo* ai = info; ai != nullptr; ai = ai->ai_next) {
if (ai->ai_family == AF_INET6) {
- setFromSockaddr(ai->ai_addr, ai->ai_addrlen);
+ setFromSockaddr(ai->ai_addr, socklen_t(ai->ai_addrlen));
return;
}
}
// 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(
// Call strnlen(), just in case the length was overspecified.
socklen_t maxLength = addrlen - offsetof(struct sockaddr_un, sun_path);
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);
}
}
template <typename IPAddrType>
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()) {
getNthMSBitImplThrow(ip.bitCount(), family);
}
} else {
value += ('a' - 10);
}
- *(buf++) = value;
+ *(buf++) = char(value);
val %= powerToPrint;
found = true;
}
*(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) {
}
}
- return std::string(str, buf - str);
+ return std::string(str, size_t(buf - str));
}
}
}
// Make end time at least >= start time.
handshakeEndTime_ = handshakeStartTime_;
if (handshakeConnectTimeout_ > 0) {
- handshakeTimeout_.scheduleTimeout(handshakeConnectTimeout_);
+ handshakeTimeout_.scheduleTimeout(
+ std::chrono::milliseconds(handshakeConnectTimeout_));
}
handleConnect();
}
assert(connectCallback_ == nullptr);
// We use a different connect timeout here than the handshake timeout, so
// that we can disambiguate the 2 timers.
- int timeout = connectTimeout_.count();
- if (timeout > 0) {
- if (!connectionTimeout_.scheduleTimeout(timeout)) {
+ if (connectTimeout_.count() > 0) {
+ if (!connectionTimeout_.scheduleTimeout(connectTimeout_)) {
throw AsyncSocketException(
AsyncSocketException::INTERNAL_ERROR,
withAddr("failed to schedule AsyncSSLSocket connect timeout"));
return AsyncSocket::performRead(buf, buflen, offset);
}
- ssize_t bytes = 0;
+ int bytes = 0;
if (!isBufferMovable_) {
- bytes = SSL_read(ssl_, *buf, *buflen);
+ bytes = SSL_read(ssl_, *buf, int(*buflen));
}
#ifdef SSL_MODE_MOVE_BUFFER_OWNERSHIP
else {
bytes = eorAwareSSLWrite(
ssl_,
sslWriteBuf,
- len,
+ int(len),
(isSet(flags, WriteFlags::EOR) && i + buffersStolen + 1 == count));
if (bytes <= 0) {
- int error = SSL_get_error(ssl_, bytes);
+ int error = SSL_get_error(ssl_, int(bytes));
if (error == SSL_ERROR_WANT_WRITE) {
// The caller will register for write event if not already.
- *partialWritten = offset;
+ *partialWritten = uint32_t(offset);
return WriteResult(totalWritten);
}
- auto writeResult = interpretSSLError(bytes, error);
+ auto writeResult = interpretSSLError(int(bytes), error);
if (writeResult.writeReturn < 0) {
return writeResult;
} // else fall through to below to correctly record totalWritten
(*countWritten)++;
v = &(vec[++i]);
}
- *partialWritten = bytes;
+ *partialWritten = uint32_t(bytes);
return WriteResult(totalWritten);
}
}
OpenSSLUtils::getBioFd(b, nullptr), &msg, flags);
BIO_clear_retry_flags(b);
if (!result.exception && result.writeReturn <= 0) {
- if (OpenSSLUtils::getBioShouldRetryWrite(result.writeReturn)) {
+ if (OpenSSLUtils::getBioShouldRetryWrite(int(result.writeReturn))) {
BIO_set_retry_write(b);
}
}
- return result.writeReturn;
+ return int(result.writeReturn);
}
int AsyncSSLSocket::sslVerifyCallback(
}
// 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(
errno,
"failed to bind to async server socket for port ",
short /* events */,
void* arg) {
AsyncSignalHandler* handler = static_cast<AsyncSignalHandler*>(arg);
- handler->signalReceived(signum);
+ handler->signalReceived(int(signum));
}
} // folly
void AsyncSocket::scheduleConnectTimeout() {
// Connection in progress.
- int timeout = connectTimeout_.count();
+ auto timeout = connectTimeout_.count();
if (timeout > 0) {
// Start a timer in case the connection takes too long.
- if (!writeTimeout_.scheduleTimeout(timeout)) {
+ if (!writeTimeout_.scheduleTimeout(uint32_t(timeout))) {
throw AsyncSocketException(
AsyncSocketException::INTERNAL_ERROR,
withAddr("failed to schedule AsyncSocket connect timeout"));
uint32_t countWritten = 0;
uint32_t partialWritten = 0;
- int bytesWritten = 0;
+ ssize_t bytesWritten = 0;
bool mustRegister = false;
if ((state_ == StateEnum::ESTABLISHED || state_ == StateEnum::FAST_OPEN) &&
!connecting()) {
assert(writeReqTail_ == nullptr);
assert((eventFlags_ & EventHandler::WRITE) == 0);
- auto writeResult =
- performWrite(vec, count, flags, &countWritten, &partialWritten);
+ auto writeResult = performWrite(
+ vec, uint32_t(count), flags, &countWritten, &partialWritten);
bytesWritten = writeResult.writeReturn;
if (bytesWritten < 0) {
auto errnoCopy = errno;
// Create a new WriteRequest to add to the queue
WriteRequest* req;
try {
- req = BytesWriteRequest::newRequest(this, callback, vec + countWritten,
- count - countWritten, partialWritten,
- bytesWritten, std::move(ioBuf), flags);
+ req = BytesWriteRequest::newRequest(
+ this,
+ callback,
+ vec + countWritten,
+ uint32_t(count - countWritten),
+ partialWritten,
+ uint32_t(bytesWritten),
+ std::move(ioBuf),
+ flags);
} catch (const std::exception& ex) {
// we mainly expect to catch std::bad_alloc here
AsyncSocketException tex(AsyncSocketException::INTERNAL_ERROR,
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();
if (writeReqTail_ == nullptr) {
}
- if (setsockopt(fd_, IPPROTO_TCP, TCP_CONGESTION, cname.c_str(),
- cname.length() + 1) != 0) {
+ if (setsockopt(
+ fd_,
+ IPPROTO_TCP,
+ TCP_CONGESTION,
+ cname.c_str(),
+ socklen_t(cname.length() + 1)) != 0) {
int errnoCopy = errno;
VLOG(2) << "failed to update TCP_CONGESTION option on AsyncSocket "
<< this << "(fd=" << fd_ << ", state=" << state_ << "): "
uint32_t bytesWritten;
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;
if (v->iov_len > bytesWritten) {
// Partial write finished in the middle of this iovec
return WriteResult(totalWritten);
}
- bytesWritten -= v->iov_len;
+ bytesWritten -= uint32_t(v->iov_len);
}
assert(bytesWritten == 0);
}
void bytesWritten(size_t count) {
- totalBytesWritten_ += count;
+ totalBytesWritten_ += uint32_t(count);
socket_->appBytesWritten_ += count;
}
, avgLoopTime_(2000000)
, maxLatencyLoopTime_(avgLoopTime_)
, 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_)
, startWork_(0)
, observer_(nullptr)
, avgLoopTime_(2000000)
, maxLatencyLoopTime_(avgLoopTime_)
, 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_)
, startWork_(0)
, observer_(nullptr)
VLOG(5) << "EventBase(): Destroyed.";
}
-int EventBase::getNotificationQueueSize() const {
+size_t EventBase::getNotificationQueueSize() const {
return queue_->size();
}
assert(isInEventBaseThread());
// Set up the timeval and add the event
struct timeval tv;
- tv.tv_sec = timeout.count() / 1000LL;
- tv.tv_usec = (timeout.count() % 1000LL) * 1000LL;
+ tv.tv_sec = long(timeout.count() / 1000LL);
+ tv.tv_usec = long((timeout.count() % 1000LL) * 1000LL);
struct event* ev = obj->getEvent();
if (event_add(ev, &tv) < 0) {
*/
void waitUntilRunning();
- int getNotificationQueueSize() const;
+ size_t getNotificationQueueSize() const;
void setMaxReadAtOnce(uint32_t maxAtOnce);
* Return the set of events that we're currently registered for.
*/
uint16_t getRegisteredEvents() const {
- return (isHandlerRegistered()) ?
- event_.ev_events : 0;
+ return (isHandlerRegistered()) ? uint16_t(event_.ev_events) : 0u;
}
/**
void HHWheelTimer::scheduleNextTimeout() {
auto nextTick = calcNextTick();
- long tick = 1;
+ int64_t tick = 1;
if (nextTick & WHEEL_MASK) {
auto bi = makeBitIterator(bitmap_.begin());
}
ssize_t bytes_written = 0;
- ssize_t bytes_expected = 0;
+ size_t bytes_expected = 0;
do {
if (eventfd_ >= 0) {
// eventfd(2) dictates that we must write a 64-bit integer
uint64_t signal = 1;
- bytes_expected = static_cast<ssize_t>(sizeof(signal));
+ bytes_expected = sizeof(signal);
bytes_written = ::write(eventfd_, &signal, bytes_expected);
} else {
uint8_t signal = 1;
- bytes_expected = static_cast<ssize_t>(sizeof(signal));
+ bytes_expected = sizeof(signal);
bytes_written = ::write(pipeFds_[1], &signal, bytes_expected);
}
} while (bytes_written == -1 && errno == EINTR);
}
#endif
- if (bytes_written == bytes_expected) {
+ if (bytes_written == ssize_t(bytes_expected)) {
signal_ = true;
} else {
#ifdef __ANDROID__