Commit d359ca68 authored by Jim Meyering's avatar Jim Meyering Committed by Facebook Github Bot

folly/io: avoid shadowing warnings

Summary: Fix shadowing warnings.

Reviewed By: russoue

Differential Revision: D3979165

fbshipit-source-id: 19a3940e210e4d5a698dbc0e6d74b317a74a94fa
parent 67fcea20
...@@ -361,7 +361,7 @@ void AsyncServerSocket::bind( ...@@ -361,7 +361,7 @@ void AsyncServerSocket::bind(
} }
void AsyncServerSocket::bind(uint16_t port) { void AsyncServerSocket::bind(uint16_t port) {
struct addrinfo hints, *res, *res0; struct addrinfo hints, *res0;
char sport[sizeof("65536")]; char sport[sizeof("65536")];
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
...@@ -423,7 +423,7 @@ void AsyncServerSocket::bind(uint16_t port) { ...@@ -423,7 +423,7 @@ void AsyncServerSocket::bind(uint16_t port) {
// - 0.0.0.0 (IPv4-only) // - 0.0.0.0 (IPv4-only)
// - :: (IPv6+IPv4) in this order // - :: (IPv6+IPv4) in this order
// See: https://sourceware.org/bugzilla/show_bug.cgi?id=9981 // See: https://sourceware.org/bugzilla/show_bug.cgi?id=9981
for (res = res0; res; res = res->ai_next) { for (struct addrinfo* res = res0; res; res = res->ai_next) {
if (res->ai_family == AF_INET6) { if (res->ai_family == AF_INET6) {
setupAddress(res); setupAddress(res);
} }
...@@ -440,7 +440,7 @@ void AsyncServerSocket::bind(uint16_t port) { ...@@ -440,7 +440,7 @@ void AsyncServerSocket::bind(uint16_t port) {
} }
try { try {
for (res = res0; res; res = res->ai_next) { for (struct addrinfo* res = res0; res; res = res->ai_next) {
if (res->ai_family != AF_INET6) { if (res->ai_family != AF_INET6) {
setupAddress(res); setupAddress(res);
} }
......
...@@ -125,8 +125,8 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing1) { ...@@ -125,8 +125,8 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing1) {
int n = 3; int n = 3;
auto vec = makeVec({3, 3, 3}); auto vec = makeVec({3, 3, 3});
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 9)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 9))
.WillOnce(Invoke([this] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this] (SSL *, const void *buf, int m) {
verifyVec(buf, n, 0); verifyVec(buf, m, 0);
return 9; })); return 9; }));
uint32_t countWritten = 0; uint32_t countWritten = 0;
uint32_t partialWritten = 0; uint32_t partialWritten = 0;
...@@ -142,15 +142,15 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing2) { ...@@ -142,15 +142,15 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing2) {
auto vec = makeVec({1500, 3, 3}); auto vec = makeVec({1500, 3, 3});
int pos = 0; int pos = 0;
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 6)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 6))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
uint32_t countWritten = 0; uint32_t countWritten = 0;
uint32_t partialWritten = 0; uint32_t partialWritten = 0;
sock_->testPerformWrite(vec.get(), n, WriteFlags::NONE, &countWritten, sock_->testPerformWrite(vec.get(), n, WriteFlags::NONE, &countWritten,
...@@ -166,10 +166,10 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing3) { ...@@ -166,10 +166,10 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing3) {
int pos = 0; int pos = 0;
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500))
.Times(2) .Times(2)
.WillRepeatedly(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillRepeatedly(Invoke([this, &pos] (SSL *, const void *buf, int m) {
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
uint32_t countWritten = 0; uint32_t countWritten = 0;
uint32_t partialWritten = 0; uint32_t partialWritten = 0;
sock_->testPerformWrite(vec.get(), n, WriteFlags::NONE, &countWritten, sock_->testPerformWrite(vec.get(), n, WriteFlags::NONE, &countWritten,
...@@ -184,8 +184,8 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing4) { ...@@ -184,8 +184,8 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing4) {
auto vec = makeVec({300, 300, 300, 300, 300}); auto vec = makeVec({300, 300, 300, 300, 300});
int pos = 0; int pos = 0;
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += 1000; pos += 1000;
return 1000; /* 500 bytes "pending" */ })); return 1000; /* 500 bytes "pending" */ }));
uint32_t countWritten = 0; uint32_t countWritten = 0;
...@@ -196,9 +196,9 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing4) { ...@@ -196,9 +196,9 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing4) {
EXPECT_EQ(partialWritten, 100); EXPECT_EQ(partialWritten, 100);
consumeVec(vec.get(), countWritten, partialWritten); consumeVec(vec.get(), countWritten, partialWritten);
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 500)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 500))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return 500; })); return 500; }));
sock_->testPerformWrite(vec.get() + countWritten, n - countWritten, sock_->testPerformWrite(vec.get() + countWritten, n - countWritten,
WriteFlags::NONE, WriteFlags::NONE,
...@@ -213,15 +213,15 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing5) { ...@@ -213,15 +213,15 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing5) {
auto vec = makeVec({1000, 500, 500}); auto vec = makeVec({1000, 500, 500});
int pos = 0; int pos = 0;
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 500)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 500))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
uint32_t countWritten = 0; uint32_t countWritten = 0;
uint32_t partialWritten = 0; uint32_t partialWritten = 0;
sock_->testPerformWrite(vec.get(), n, WriteFlags::NONE, &countWritten, sock_->testPerformWrite(vec.get(), n, WriteFlags::NONE, &countWritten,
...@@ -236,8 +236,8 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing6) { ...@@ -236,8 +236,8 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing6) {
auto vec = makeVec({1000, 500}); auto vec = makeVec({1000, 500});
int pos = 0; int pos = 0;
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += 700; pos += 700;
return 700; })); return 700; }));
uint32_t countWritten = 0; uint32_t countWritten = 0;
...@@ -248,10 +248,10 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing6) { ...@@ -248,10 +248,10 @@ TEST_F(AsyncSSLSocketWriteTest, write_coalescing6) {
EXPECT_EQ(partialWritten, 700); EXPECT_EQ(partialWritten, 700);
consumeVec(vec.get(), countWritten, partialWritten); consumeVec(vec.get(), countWritten, partialWritten);
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 800)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 800))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
sock_->testPerformWrite(vec.get() + countWritten, n - countWritten, sock_->testPerformWrite(vec.get() + countWritten, n - countWritten,
WriteFlags::NONE, WriteFlags::NONE,
&countWritten, &partialWritten); &countWritten, &partialWritten);
...@@ -280,18 +280,18 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor1) { ...@@ -280,18 +280,18 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor1) {
// + some random SSL overhead // + some random SSL overhead
.WillOnce(Return(3728)); .WillOnce(Return(3728));
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500))
.WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int m) {
// the first 1500 does not have the EOR byte // the first 1500 does not have the EOR byte
sock_->checkEor(0, 0); sock_->checkEor(0, 0);
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 6)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 6))
.WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int m) {
sock_->checkEor(appEor, 3600 + n); sock_->checkEor(appEor, 3600 + m);
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
uint32_t countWritten = 0; uint32_t countWritten = 0;
uint32_t partialWritten = 0; uint32_t partialWritten = 0;
...@@ -322,18 +322,18 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor2) { ...@@ -322,18 +322,18 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor2) {
// + some random SSL overhead // + some random SSL overhead
.WillOnce(Return(4100)); .WillOnce(Return(4100));
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1500))
.WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int m) {
// the first 1500 does not have the EOR byte // the first 1500 does not have the EOR byte
sock_->checkEor(0, 0); sock_->checkEor(0, 0);
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 300)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 300))
.WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([=, &pos] (SSL *, const void *buf, int m) {
sock_->checkEor(appEor, 3600 + n); sock_->checkEor(appEor, 3600 + m);
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
uint32_t countWritten = 0; uint32_t countWritten = 0;
uint32_t partialWritten = 0; uint32_t partialWritten = 0;
...@@ -365,9 +365,9 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor3) { ...@@ -365,9 +365,9 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor3) {
// + some random SSL overhead // + some random SSL overhead
.WillOnce(Return(3100)); .WillOnce(Return(3100));
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1600)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 1600))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
sock_->checkEor(appEor, 2000 + n); sock_->checkEor(appEor, 2000 + m);
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += 1000; pos += 1000;
return 1000; })); return 1000; }));
...@@ -384,11 +384,11 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor3) { ...@@ -384,11 +384,11 @@ TEST_F(AsyncSSLSocketWriteTest, write_with_eor3) {
.WillOnce(Return(3100)) .WillOnce(Return(3100))
.WillOnce(Return(3800)); .WillOnce(Return(3800));
EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 600)) EXPECT_CALL(*(sock_.get()), sslWriteImpl(_, _, 600))
.WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int n) { .WillOnce(Invoke([this, &pos] (SSL *, const void *buf, int m) {
sock_->checkEor(appEor, 3100 + n); sock_->checkEor(appEor, 3100 + m);
verifyVec(buf, n, pos); verifyVec(buf, m, pos);
pos += n; pos += m;
return n; })); return m; }));
sock_->testPerformWrite(vec.get() + countWritten, n - countWritten, sock_->testPerformWrite(vec.get() + countWritten, n - countWritten,
WriteFlags::EOR, WriteFlags::EOR,
&countWritten, &partialWritten); &countWritten, &partialWritten);
......
...@@ -281,13 +281,13 @@ TEST_F(HHWheelTimerTest, Stress) { ...@@ -281,13 +281,13 @@ TEST_F(HHWheelTimerTest, Stress) {
TestTimeout timeouts[10000]; TestTimeout timeouts[10000];
long runtimeouts = 0; long runtimeouts = 0;
for (long i = 0; i < timeoutcount; i++) { for (long i = 0; i < timeoutcount; i++) {
long newtimeout = Random::rand32(1, 10000); long timeout = Random::rand32(1, 10000);
if (Random::rand32(3)) { if (Random::rand32(3)) {
// NOTE: hhwheel timer runs before eventbase runAfterDelay, // NOTE: hhwheel timer runs before eventbase runAfterDelay,
// so runAfterDelay cancelTimeout() must run at least one timerwheel // so runAfterDelay cancelTimeout() must run at least one timerwheel
// before scheduleTimeout, to ensure it runs first. // before scheduleTimeout, to ensure it runs first.
newtimeout += 256; timeout += 256;
t.scheduleTimeout(&timeouts[i], std::chrono::milliseconds(newtimeout)); t.scheduleTimeout(&timeouts[i], std::chrono::milliseconds(timeout));
eventBase.runAfterDelay( eventBase.runAfterDelay(
[&, i]() { [&, i]() {
timeouts[i].fn = nullptr; timeouts[i].fn = nullptr;
...@@ -295,13 +295,13 @@ TEST_F(HHWheelTimerTest, Stress) { ...@@ -295,13 +295,13 @@ TEST_F(HHWheelTimerTest, Stress) {
runtimeouts++; runtimeouts++;
LOG(INFO) << "Ran " << runtimeouts << " timeouts, cancelled"; LOG(INFO) << "Ran " << runtimeouts << " timeouts, cancelled";
}, },
newtimeout - 256); timeout - 256);
timeouts[i].fn = [&, i, newtimeout]() { timeouts[i].fn = [&, i, timeout]() {
LOG(INFO) << "FAIL:timer " << i << " still fired in " << newtimeout; LOG(INFO) << "FAIL:timer " << i << " still fired in " << timeout;
EXPECT_FALSE(true); EXPECT_FALSE(true);
}; };
} else { } else {
t.scheduleTimeout(&timeouts[i], std::chrono::milliseconds(newtimeout)); t.scheduleTimeout(&timeouts[i], std::chrono::milliseconds(timeout));
timeouts[i].fn = [&, i]() { timeouts[i].fn = [&, i]() {
timeoutcount++; timeoutcount++;
long newtimeout = Random::rand32(1, 10000); long newtimeout = Random::rand32(1, 10000);
......
...@@ -466,10 +466,10 @@ TEST(NotificationQueueTest, ConsumeUntilDrainedStress) { ...@@ -466,10 +466,10 @@ TEST(NotificationQueueTest, ConsumeUntilDrainedStress) {
EventBase eventBase; EventBase eventBase;
IntQueue queue; IntQueue queue;
QueueConsumer consumer; QueueConsumer consumer;
consumer.fn = [&](int i) { consumer.fn = [&](int j) {
EXPECT_THROW(queue.tryPutMessage(i), std::runtime_error); EXPECT_THROW(queue.tryPutMessage(j), std::runtime_error);
EXPECT_FALSE(queue.tryPutMessageNoThrow(i)); EXPECT_FALSE(queue.tryPutMessageNoThrow(j));
EXPECT_THROW(queue.putMessage(i), std::runtime_error); EXPECT_THROW(queue.putMessage(j), std::runtime_error);
std::vector<int> ints{1, 2, 3}; std::vector<int> ints{1, 2, 3};
EXPECT_THROW( EXPECT_THROW(
queue.putMessages(ints.begin(), ints.end()), queue.putMessages(ints.begin(), ints.end()),
...@@ -477,8 +477,8 @@ TEST(NotificationQueueTest, ConsumeUntilDrainedStress) { ...@@ -477,8 +477,8 @@ TEST(NotificationQueueTest, ConsumeUntilDrainedStress) {
}; };
consumer.setMaxReadAtOnce(10); // We should ignore this consumer.setMaxReadAtOnce(10); // We should ignore this
consumer.startConsuming(&eventBase, &queue); consumer.startConsuming(&eventBase, &queue);
for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) {
queue.putMessage(i); queue.putMessage(j);
} }
EXPECT_TRUE(consumer.consumeUntilDrained()); EXPECT_TRUE(consumer.consumeUntilDrained());
EXPECT_EQ(20, consumer.messages.size()); EXPECT_EQ(20, consumer.messages.size());
......
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