diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-13 16:53:02 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-13 16:53:02 +0100 |
commit | b4bd9c1287e08d79b6eca81fa0ff0f84cb422089 (patch) | |
tree | e071bae305c302bd9726cff38d9e072239dc2dd6 /fnet | |
parent | 71ecce0d5fc572a6e71dc9b554c57df9f6ea7827 (diff) |
NULL -> nullptr
Diffstat (limited to 'fnet')
64 files changed, 432 insertions, 427 deletions
diff --git a/fnet/src/examples/frt/rpc/rpc_info.cpp b/fnet/src/examples/frt/rpc/rpc_info.cpp index af15a19b6a4..600af612b40 100644 --- a/fnet/src/examples/frt/rpc/rpc_info.cpp +++ b/fnet/src/examples/frt/rpc/rpc_info.cpp @@ -10,16 +10,16 @@ public: void GetReq(FRT_RPCRequest **req, FRT_Supervisor *supervisor) { - if ((*req) != NULL) + if ((*req) != nullptr) (*req)->SubRef(); (*req) = supervisor->AllocRPCRequest(); } void FreeReqs(FRT_RPCRequest *r1, FRT_RPCRequest *r2) { - if (r1 != NULL) + if (r1 != nullptr) r1->SubRef(); - if (r2 != NULL) + if (r2 != nullptr) r2->SubRef(); } @@ -79,8 +79,8 @@ RPCInfo::Main() bool verbose = (_argc > 2 && strcmp(_argv[2], "verbose") == 0); FRT_Supervisor supervisor; FRT_Target *target = supervisor.GetTarget(_argv[1]); - FRT_RPCRequest *m_list = NULL; - FRT_RPCRequest *info = NULL; + FRT_RPCRequest *m_list = nullptr; + FRT_RPCRequest *info = nullptr; supervisor.Start(); GetReq(&info, &supervisor); diff --git a/fnet/src/examples/frt/rpc/rpc_invoke.cpp b/fnet/src/examples/frt/rpc/rpc_invoke.cpp index d7dc6b86b77..0295e7ea7a9 100644 --- a/fnet/src/examples/frt/rpc/rpc_invoke.cpp +++ b/fnet/src/examples/frt/rpc/rpc_invoke.cpp @@ -15,22 +15,22 @@ private: const char *value = param + 2; switch (param[0]) { case 'b': - req->GetParams()->AddInt8(strtoll(value, NULL, 0)); + req->GetParams()->AddInt8(strtoll(value, nullptr, 0)); break; case 'h': - req->GetParams()->AddInt16(strtoll(value, NULL, 0)); + req->GetParams()->AddInt16(strtoll(value, nullptr, 0)); break; case 'i': - req->GetParams()->AddInt32(strtoll(value, NULL, 0)); + req->GetParams()->AddInt32(strtoll(value, nullptr, 0)); break; case 'l': - req->GetParams()->AddInt64(strtoll(value, NULL, 0)); + req->GetParams()->AddInt64(strtoll(value, nullptr, 0)); break; case 'f': - req->GetParams()->AddFloat(strtod(value, NULL)); + req->GetParams()->AddFloat(strtod(value, nullptr)); break; case 'd': - req->GetParams()->AddDouble(strtod(value, NULL)); + req->GetParams()->AddDouble(strtod(value, nullptr)); break; case 's': req->GetParams()->AddString(value); diff --git a/fnet/src/examples/frt/rpc/rpc_proxy.cpp b/fnet/src/examples/frt/rpc/rpc_proxy.cpp index 19c59f9201d..af01ac60d26 100644 --- a/fnet/src/examples/frt/rpc/rpc_proxy.cpp +++ b/fnet/src/examples/frt/rpc/rpc_proxy.cpp @@ -13,8 +13,8 @@ struct Session uint32_t id; uint32_t finiCnt; - Session(uint32_t xid) : client(NULL), server(NULL), id(xid), finiCnt(0) {} - ~Session() { assert(client == NULL && server == NULL && finiCnt == 2); } + Session(uint32_t xid) : client(nullptr), server(nullptr), id(xid), finiCnt(0) {} + ~Session() { assert(client == nullptr && server == nullptr && finiCnt == 2); } private: Session(const Session &); @@ -93,7 +93,7 @@ RPCProxy::GetPrefix(FRT_RPCRequest *req) (void) currTimePt; char rid[32]; - if (req->GetContext()._value.CHANNEL != NULL) { + if (req->GetContext()._value.CHANNEL != nullptr) { sprintf(rid, "[rid=%u]", req->GetContext()._value.CHANNEL->GetID()); } else { rid[0] = '\0'; @@ -142,10 +142,10 @@ RPCProxy::HOOK_Mismatch(FRT_RPCRequest *req) } req->Detach(); req->SetError(FRTE_NO_ERROR, ""); - if (req->GetConnection()->IsServer() && GetSession(req)->server != NULL) + if (req->GetConnection()->IsServer() && GetSession(req)->server != nullptr) { GetSession(req)->server->InvokeAsync(req, 60.0, &req->getStash().create<ReqDone>(*this)); - } else if (req->GetConnection()->IsClient() && GetSession(req)->client != NULL) + } else if (req->GetConnection()->IsClient() && GetSession(req)->client != nullptr) { FRT_Supervisor::InvokeAsync(GetSession(req)->client->Owner(), GetSession(req)->client, req, 60.0, &req->getStash().create<ReqDone>(*this)); @@ -168,7 +168,7 @@ RPCProxy::HOOK_Init(FRT_RPCRequest *req) _supervisor.Get2WayTarget(_spec, FNET_Context((void *) session)); session->client->SetContext(FNET_Context((void *) session)); - if (session->server->GetConnection() == NULL || + if (session->server->GetConnection() == nullptr || session->server->GetConnection()->GetState() > FNET_Connection::FNET_CONNECTED) { @@ -184,13 +184,13 @@ RPCProxy::HOOK_Down(FRT_RPCRequest *req) { Session *session = GetSession(req); if (req->GetConnection()->IsClient()) { - if (session->client != NULL) { + if (session->client != nullptr) { session->client->Owner()->Close(session->client); } } else { session->server->SubRef(); - session->client = NULL; - session->server = NULL; + session->client = nullptr; + session->server = nullptr; } } diff --git a/fnet/src/examples/frt/rpc/rpc_server.cpp b/fnet/src/examples/frt/rpc/rpc_server.cpp index 5e8dd744fdc..4da65ddfe2b 100644 --- a/fnet/src/examples/frt/rpc/rpc_server.cpp +++ b/fnet/src/examples/frt/rpc/rpc_server.cpp @@ -14,7 +14,7 @@ private: RPCServer &operator=(const RPCServer &); public: - RPCServer() : _supervisor(NULL) {} + RPCServer() : _supervisor(nullptr) {} void InitRPC(FRT_Supervisor *s); void RPC_concat(FRT_RPCRequest *req); void RPC_addFloat(FRT_RPCRequest *req); diff --git a/fnet/src/examples/ping/packets.cpp b/fnet/src/examples/ping/packets.cpp index 8958666b374..f7b50f5d898 100644 --- a/fnet/src/examples/ping/packets.cpp +++ b/fnet/src/examples/ping/packets.cpp @@ -61,5 +61,5 @@ PingPacketFactory::CreatePacket(uint32_t pcode, FNET_Context) case PCODE_PING_REQUEST: return new PingRequest(); case PCODE_PING_REPLY: return new PingReply(); } - return NULL; + return nullptr; } diff --git a/fnet/src/examples/ping/pingclient.cpp b/fnet/src/examples/ping/pingclient.cpp index 075c0b5df32..2f11adb73e5 100644 --- a/fnet/src/examples/ping/pingclient.cpp +++ b/fnet/src/examples/ping/pingclient.cpp @@ -33,7 +33,7 @@ PingClient::Main() uint32_t channelCnt = 0; for (uint32_t i = 0; i < 10; i++) { - channels[i] = (conn == NULL) ? NULL : conn->OpenChannel(&queue, FNET_Context(i)); + channels[i] = (conn == nullptr) ? nullptr : conn->OpenChannel(&queue, FNET_Context(i)); if (channels[i] == 0) { fprintf(stderr, "Could not make channel[%d] to %s\n", i, _argv[1]); break; @@ -48,13 +48,13 @@ PingClient::Main() FNET_Context context; while (channelCnt > 0) { packet = queue.DequeuePacket(5000, &context); - if (packet == NULL) { + if (packet == nullptr) { fprintf(stderr, "Timeout\n"); for(int c = 0; c < 10; c++) { - if (channels[c] != NULL) { + if (channels[c] != nullptr) { channels[c]->Close(); channels[c]->Free(); - channels[c] = NULL; + channels[c] = nullptr; fprintf(stderr, "Closed channel with context %d\n", c); } } @@ -67,17 +67,17 @@ PingClient::Main() fprintf(stderr, "Lost channel with context %d\n", context._value.INT); } - if (channels[context._value.INT] != NULL) { + if (channels[context._value.INT] != nullptr) { channels[context._value.INT]->Close(); channels[context._value.INT]->Free(); - channels[context._value.INT] = NULL; + channels[context._value.INT] = nullptr; fprintf(stderr, "Closed channel with context %d\n", context._value.INT); channelCnt--; } packet->Free(); } - if (conn != NULL) + if (conn != nullptr) conn->SubRef(); transport.ShutDown(true); pool.Close(); diff --git a/fnet/src/examples/ping/pingserver.cpp b/fnet/src/examples/ping/pingserver.cpp index 346307a017c..905a1dc656d 100644 --- a/fnet/src/examples/ping/pingserver.cpp +++ b/fnet/src/examples/ping/pingserver.cpp @@ -48,7 +48,7 @@ PingServer::Main() FNET_SimplePacketStreamer streamer(&factory); FNET_Connector *listener = transport.Listen(_argv[1], &streamer, this); - if (listener != NULL) + if (listener != nullptr) listener->SubRef(); FNET_SignalShutDown ssd(transport); diff --git a/fnet/src/examples/proxy/proxy.cpp b/fnet/src/examples/proxy/proxy.cpp index 9a76077591f..243c1e764c1 100644 --- a/fnet/src/examples/proxy/proxy.cpp +++ b/fnet/src/examples/proxy/proxy.cpp @@ -55,7 +55,7 @@ private: Bridge &operator=(const Bridge &); public: - Bridge() : _client(NULL), _server(NULL) {} + Bridge() : _client(nullptr), _server(nullptr) {} enum packet_source { CLIENT = 0, @@ -83,37 +83,37 @@ Bridge::HandlePacket(FNET_Packet *packet, FNET_Context context) if (context._value.INT == CLIENT) { - if (_server != NULL) { + if (_server != nullptr) { LOG(info, "client connection lost"); _server->Owner()->Close(_server); } ret = FNET_FREE_CHANNEL; - _client = NULL; + _client = nullptr; } else if (context._value.INT == SERVER) { - if (_client != NULL) { + if (_client != nullptr) { LOG(info, "server connection lost"); _client->GetConnection()->Owner()->Close(_client->GetConnection()); } _server->SubRef(); - _server = NULL; + _server = nullptr; } - if (_client == NULL && _server == NULL) + if (_client == nullptr && _server == nullptr) delete this; } else { if (context._value.INT == CLIENT) { - if (_server != NULL) + if (_server != nullptr) _server->PostPacket(packet, FNET_NOID); else packet->Free(); } else if (context._value.INT == SERVER) { - if (_client != NULL) + if (_client != nullptr) _client->Send(packet); else packet->Free(); @@ -196,7 +196,7 @@ Proxy::InitAdminChannel(FNET_Channel *channel) Bridge *bridge = new Bridge(); FNET_Connection *server = _transport.Connect(_argv[2], this, bridge, FNET_Context(Bridge::SERVER)); - if (server == NULL) { + if (server == nullptr) { channel->GetConnection()->Owner()->Close(channel->GetConnection()); delete bridge; return false; @@ -226,7 +226,7 @@ Proxy::Main() FNET_Connector *listener = _transport.Listen(_argv[1], this, this); - if (listener != NULL) + if (listener != nullptr) listener->SubRef(); _transport.SetLogStats(true); diff --git a/fnet/src/tests/fdselector/fdselector.cpp b/fnet/src/tests/fdselector/fdselector.cpp index 5af2716c0d4..61c204aded7 100644 --- a/fnet/src/tests/fdselector/fdselector.cpp +++ b/fnet/src/tests/fdselector/fdselector.cpp @@ -80,7 +80,7 @@ struct State struct Selector : public FNET_FDSelector { - static FNET_Mutex mutex; + static FastOS_Mutex mutex; static int ctorCnt; static int dtorCnt; @@ -100,7 +100,7 @@ struct Selector : public FNET_FDSelector } }; -FNET_Mutex Selector::mutex; +FastOS_Mutex Selector::mutex; int Selector::ctorCnt = 0; int Selector::dtorCnt = 0; diff --git a/fnet/src/tests/frt/method_pt/method_pt.cpp b/fnet/src/tests/frt/method_pt/method_pt.cpp index 539be6846a9..33cd6e5218b 100644 --- a/fnet/src/tests/frt/method_pt/method_pt.cpp +++ b/fnet/src/tests/frt/method_pt/method_pt.cpp @@ -185,20 +185,20 @@ void initTest() { _complexHandler2 = new ComplexHandler2(); _complexHandler3 = new ComplexHandler3(); - ASSERT_TRUE(_supervisor != NULL); - ASSERT_TRUE(_simpleHandler != NULL); - ASSERT_TRUE(_mediumHandler1 != NULL); - ASSERT_TRUE(_mediumHandler2 != NULL); - ASSERT_TRUE(_mediumHandler3 != NULL); - ASSERT_TRUE(_complexHandler1 != NULL); - ASSERT_TRUE(_complexHandler2 != NULL); - ASSERT_TRUE(_complexHandler3 != NULL); + ASSERT_TRUE(_supervisor != nullptr); + ASSERT_TRUE(_simpleHandler != nullptr); + ASSERT_TRUE(_mediumHandler1 != nullptr); + ASSERT_TRUE(_mediumHandler2 != nullptr); + ASSERT_TRUE(_mediumHandler3 != nullptr); + ASSERT_TRUE(_complexHandler1 != nullptr); + ASSERT_TRUE(_complexHandler2 != nullptr); + ASSERT_TRUE(_complexHandler3 != nullptr); ASSERT_TRUE(_supervisor->Listen(0)); std::string spec = vespalib::make_string("tcp/localhost:%d", _supervisor->GetListenPort()); _target = _supervisor->GetTarget(spec.c_str()); - ASSERT_TRUE(_target != NULL); + ASSERT_TRUE(_target != nullptr); bool startOK = _supervisor->Start(); ASSERT_TRUE(startOK); diff --git a/fnet/src/tests/frt/rpc/invoke.cpp b/fnet/src/tests/frt/rpc/invoke.cpp index f2c181a7ac2..c010fcd5f75 100644 --- a/fnet/src/tests/frt/rpc/invoke.cpp +++ b/fnet/src/tests/frt/rpc/invoke.cpp @@ -4,7 +4,7 @@ //------------------------------------------------------------- -FNET_Mutex _delayedReturnCntLock; +FastOS_Mutex _delayedReturnCntLock; uint32_t _delayedReturnCnt = 0; uint32_t _phase_simple_cnt = 0; @@ -20,10 +20,10 @@ uint32_t _phase_echo_cnt = 0; struct LockedReqWait : public FRT_IRequestWait { - FNET_Cond _cond; // cond used to signal req done + FastOS_Cond _cond; // cond used to signal req done bool _done; // flag indicating req done - FNET_Mutex _lockLock; // lock protecting virtual lock + FastOS_Mutex _lockLock; // lock protecting virtual lock bool _lock; // virtual lock bool _wasLocked; // was 'locked' when req done @@ -111,7 +111,7 @@ private: EchoTest &operator=(const EchoTest &); public: - EchoTest() : _echo_stash(NULL), _echo_args(NULL) {} + EchoTest() : _echo_stash(nullptr), _echo_args(nullptr) {} ~EchoTest() { delete _echo_args; @@ -122,7 +122,7 @@ public: { _echo_stash = new vespalib::Stash(); _echo_args = new FRT_Values(_echo_stash); - assert(_echo_stash != NULL && _echo_args != NULL); + assert(_echo_stash != nullptr && _echo_args != nullptr); FRT_ReflectionBuilder rb(supervisor); rb.DefineMethod("echo", "*", "*", true, @@ -270,7 +270,7 @@ public: const char *suffix = "testFast"; uint32_t suffix_len = strlen(suffix); uint32_t name_len = req->GetMethodNameLen(); - bool remote = req->GetContext()._value.VOIDP != NULL; + bool remote = req->GetContext()._value.VOIDP != nullptr; bool instant = name_len > suffix_len && strcmp(req->GetMethodName() + name_len - suffix_len, suffix) == 0; @@ -333,7 +333,7 @@ enum { }; enum { - PHASE_NULL = 0, + PHASE_nullptr = 0, PHASE_SETUP, PHASE_SIMPLE, PHASE_VOID, @@ -349,7 +349,7 @@ enum { const char phase_names[PHASE_ZZZ][32] = { - "NULL", + "nullptr", "SETUP", "SIMPLE", "VOID", @@ -363,7 +363,7 @@ const char phase_names[PHASE_ZZZ][32] = }; enum { - TIMING_NULL = 0, + TIMING_nullptr = 0, TIMING_INSTANT, TIMING_NON_INSTANT, TIMING_ZZZ @@ -371,13 +371,13 @@ enum { const char timing_names[TIMING_ZZZ][32] = { - "NULL", + "nullptr", "INSTANT", "NON-INSTANT" }; enum { - HANDLING_NULL = 0, + HANDLING_nullptr = 0, HANDLING_SYNC, HANDLING_ASYNC, HANDLING_ZZZ @@ -385,7 +385,7 @@ enum { const char handling_names[HANDLING_ZZZ][32] = { - "NULL", + "nullptr", "SYNC", "ASYNC" }; @@ -411,12 +411,12 @@ struct State { _rpc(&_server, _client.GetScheduler()), _echo(), _peerSpec(), - _testPhase(PHASE_NULL), - _timing(TIMING_NULL), - _handling(HANDLING_NULL), + _testPhase(PHASE_nullptr), + _timing(TIMING_nullptr), + _handling(HANDLING_nullptr), _timeout(5.0), - _target(NULL), - _req(NULL) + _target(nullptr), + _req(nullptr) { _client.GetTransport()->SetTCPNoDelay(true); _server.GetTransport()->SetTCPNoDelay(true); @@ -430,7 +430,7 @@ struct State { void NewReq() { - if (_req != NULL) { + if (_req != nullptr) { _req->SubRef(); } _req = new FRT_RPCRequest(); @@ -438,15 +438,15 @@ struct State { void FreeReq() { - if (_req != NULL) { + if (_req != nullptr) { _req->SubRef(); } - _req = NULL; + _req = nullptr; } void LostReq() { - _req = NULL; + _req = nullptr; } void PrepareTestMethod() @@ -915,14 +915,14 @@ TEST_F("invoke test", State()) { } } _state->_testPhase = PHASE_SHUTDOWN; - _state->_timing = TIMING_NULL; - _state->_handling = HANDLING_NULL; + _state->_timing = TIMING_nullptr; + _state->_handling = HANDLING_nullptr; EXPECT_TRUE(_state->WaitForDelayedReturnCount(0, 120.0)); _state->FreeReq(); _state->_client.ShutDown(true); _state->_server.ShutDown(true); _state->_target->SubRef(); - _state->_target = NULL; + _state->_target = nullptr; EXPECT_TRUE(_delayedReturnCnt == 0); EXPECT_TRUE(_phase_simple_cnt == 1); EXPECT_TRUE(_phase_void_cnt == 1); diff --git a/fnet/src/tests/frt/rpc/session.cpp b/fnet/src/tests/frt/rpc/session.cpp index c39fe8cba05..a7b889dc71b 100644 --- a/fnet/src/tests/frt/rpc/session.cpp +++ b/fnet/src/tests/frt/rpc/session.cpp @@ -1,4 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/fnet/frt/frt.h> @@ -6,7 +7,7 @@ class Session { private: - static FNET_Mutex _lock; + static FastOS_Mutex _lock; static int _cnt; int _val; @@ -30,7 +31,7 @@ public: static int GetCnt() { return _cnt; } }; -FNET_Mutex Session::_lock; +FastOS_Mutex Session::_lock; int Session::_cnt(0); @@ -50,7 +51,7 @@ struct RPC : public FRT_Invokable { Session *session = (Session *)req->GetConnection()->GetContext()._value.VOIDP; - bogusFini |= (session == NULL); + bogusFini |= (session == nullptr); delete session; } diff --git a/fnet/src/tests/frt/rpc/sharedblob.cpp b/fnet/src/tests/frt/rpc/sharedblob.cpp index 7c34739e380..29a229a1a89 100644 --- a/fnet/src/tests/frt/rpc/sharedblob.cpp +++ b/fnet/src/tests/frt/rpc/sharedblob.cpp @@ -146,13 +146,13 @@ TEST("testExplicitShared") { EXPECT_EQUAL(1, blob.refcnt); EXPECT_TRUE(strcmp(req->GetParamSpec(), "xixix") == 0); EXPECT_TRUE(req->GetParams()->GetValue(0)._data._len == 0); - EXPECT_TRUE(req->GetParams()->GetValue(0)._data._buf == NULL); + EXPECT_TRUE(req->GetParams()->GetValue(0)._data._buf == nullptr); EXPECT_TRUE(req->GetParams()->GetValue(1)._intval32 == 42); EXPECT_TRUE(req->GetParams()->GetValue(2)._data._len == 0); - EXPECT_TRUE(req->GetParams()->GetValue(2)._data._buf == NULL); + EXPECT_TRUE(req->GetParams()->GetValue(2)._data._buf == nullptr); EXPECT_TRUE(req->GetParams()->GetValue(3)._intval32 == 84); EXPECT_TRUE(req->GetParams()->GetValue(4)._data._len == 0); - EXPECT_TRUE(req->GetParams()->GetValue(4)._data._buf == NULL); + EXPECT_TRUE(req->GetParams()->GetValue(4)._data._buf == nullptr); EXPECT_EQUAL(1, blob.refcnt); req = orb.AllocRPCRequest(req); diff --git a/fnet/src/tests/info/info.cpp b/fnet/src/tests/info/info.cpp index 74c09db99a3..12320427053 100644 --- a/fnet/src/tests/info/info.cpp +++ b/fnet/src/tests/info/info.cpp @@ -74,7 +74,7 @@ TEST("size of important objects") EXPECT_EQUAL(32u, sizeof(FNET_Channel)); EXPECT_EQUAL(40u, sizeof(FNET_PacketQueue_NoLock)); EXPECT_EQUAL(480u, sizeof(FNET_Connection)); - EXPECT_EQUAL(96u, sizeof(FNET_Cond)); + EXPECT_EQUAL(96u, sizeof(FastOS_Cond)); EXPECT_EQUAL(56u, sizeof(FNET_DataBuffer)); EXPECT_EQUAL(24u, sizeof(FastOS_Time)); EXPECT_EQUAL(8u, sizeof(FNET_Context)); diff --git a/fnet/src/tests/locking/castspeed.cpp b/fnet/src/tests/locking/castspeed.cpp index 874769a7579..7fe360b3caf 100644 --- a/fnet/src/tests/locking/castspeed.cpp +++ b/fnet/src/tests/locking/castspeed.cpp @@ -19,7 +19,7 @@ class C: public A public: B *otherB; virtual B* asB() { return otherB; } - C() : otherB(NULL) {} + C() : otherB(nullptr) {} }; class B: public C diff --git a/fnet/src/tests/locking/drainpackets.cpp b/fnet/src/tests/locking/drainpackets.cpp index 066923f0c70..5fedea4790f 100644 --- a/fnet/src/tests/locking/drainpackets.cpp +++ b/fnet/src/tests/locking/drainpackets.cpp @@ -18,7 +18,7 @@ TEST("drain packets") { FastOS_Time start; FastOS_Time stop; - FNET_Mutex lock; + FastOS_Mutex lock; FNET_PacketQueue q1(512); FNET_PacketQueue q2(512); @@ -110,13 +110,13 @@ TEST("drain packets") { FNET_Packet *packet; FNET_Context context; - while ((packet = q1.DequeuePacket(0, &context)) != NULL) { + while ((packet = q1.DequeuePacket(0, &context)) != nullptr) { q3.QueuePacket_NoLock(packet, context); } //------------------------ - while ((packet = q3.DequeuePacket(0, &context)) != NULL) { + while ((packet = q3.DequeuePacket(0, &context)) != nullptr) { q1.QueuePacket_NoLock(packet, context); } } diff --git a/fnet/src/tests/locking/lockspeed.cpp b/fnet/src/tests/locking/lockspeed.cpp index bccedc61b8e..5bdb83c9951 100644 --- a/fnet/src/tests/locking/lockspeed.cpp +++ b/fnet/src/tests/locking/lockspeed.cpp @@ -7,7 +7,7 @@ TEST("lock speed") { FastOS_Time start; FastOS_Time stop; DummyLock dummy; - FNET_Mutex lock; + FastOS_Mutex lock; double dummyTime; double actualTime; double overhead; @@ -85,16 +85,16 @@ TEST("lock speed") { start.SetNow(); for (i = 0; i < 1000000; i++) { - FNET_Mutex lock0; - FNET_Mutex lock1; - FNET_Mutex lock2; - FNET_Mutex lock3; - FNET_Mutex lock4; - FNET_Mutex lock5; - FNET_Mutex lock6; - FNET_Mutex lock7; - FNET_Mutex lock8; - FNET_Mutex lock9; + FastOS_Mutex lock0; + FastOS_Mutex lock1; + FastOS_Mutex lock2; + FastOS_Mutex lock3; + FastOS_Mutex lock4; + FastOS_Mutex lock5; + FastOS_Mutex lock6; + FastOS_Mutex lock7; + FastOS_Mutex lock8; + FastOS_Mutex lock9; } stop.SetNow(); stop -= start; @@ -105,16 +105,16 @@ TEST("lock speed") { start.SetNow(); for (i = 0; i < 1000000; i++) { - FNET_Cond cond0; - FNET_Cond cond1; - FNET_Cond cond2; - FNET_Cond cond3; - FNET_Cond cond4; - FNET_Cond cond5; - FNET_Cond cond6; - FNET_Cond cond7; - FNET_Cond cond8; - FNET_Cond cond9; + FastOS_Cond cond0; + FastOS_Cond cond1; + FastOS_Cond cond2; + FastOS_Cond cond3; + FastOS_Cond cond4; + FastOS_Cond cond5; + FastOS_Cond cond6; + FastOS_Cond cond7; + FastOS_Cond cond8; + FastOS_Cond cond9; } stop.SetNow(); stop -= start; diff --git a/fnet/src/tests/printstuff/printstuff_test.cpp b/fnet/src/tests/printstuff/printstuff_test.cpp index f112763d248..f8593fb7b04 100644 --- a/fnet/src/tests/printstuff/printstuff_test.cpp +++ b/fnet/src/tests/printstuff/printstuff_test.cpp @@ -1,6 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/fnet/frt/frt.h> +#include <vespa/fnet/frt/rpcrequest.h> +#include <vespa/fnet/packetqueue.h> +#include <vespa/fnet/info.h> +#include <vespa/fnet/frt/packets.h> void printError(uint32_t ecode) { fprintf(stderr, "error(%u): %s: %s\n", diff --git a/fnet/src/tests/scheduling/schedule.cpp b/fnet/src/tests/scheduling/schedule.cpp index 0625b83e121..1b72b514d46 100644 --- a/fnet/src/tests/scheduling/schedule.cpp +++ b/fnet/src/tests/scheduling/schedule.cpp @@ -78,10 +78,10 @@ TEST("schedule") { uint32_t taskCnt = 1000000; MyTask **tasks = new MyTask*[taskCnt]; - assert(tasks != NULL); + assert(tasks != nullptr); for (uint32_t i = 0; i < taskCnt; i++) { tasks[i] = new MyTask(rand() & 131071); - assert(tasks[i] != NULL); + assert(tasks[i] != nullptr); } FastOS_Time start; diff --git a/fnet/src/vespa/fnet/channel.cpp b/fnet/src/vespa/fnet/channel.cpp index 7d6de1893bc..81b57218b73 100644 --- a/fnet/src/vespa/fnet/channel.cpp +++ b/fnet/src/vespa/fnet/channel.cpp @@ -1,7 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> +#include "channel.h" +#include "connection.h" bool FNET_Channel::Send(FNET_Packet *packet) diff --git a/fnet/src/vespa/fnet/channellookup.cpp b/fnet/src/vespa/fnet/channellookup.cpp index 2e654d6a2a3..a5f67fec35b 100644 --- a/fnet/src/vespa/fnet/channellookup.cpp +++ b/fnet/src/vespa/fnet/channellookup.cpp @@ -3,7 +3,6 @@ #include "channellookup.h" #include "vespa/fnet/channel.h" #include "controlpacket.h" -#include "ipackethandler.h" #include <vespa/vespalib/stllike/hash_map.hpp> #include <cassert> diff --git a/fnet/src/vespa/fnet/config.cpp b/fnet/src/vespa/fnet/config.cpp index 18fe5fd04b7..b2488e0eee0 100644 --- a/fnet/src/vespa/fnet/config.cpp +++ b/fnet/src/vespa/fnet/config.cpp @@ -1,8 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> - +#include "config.h" FNET_Config::FNET_Config() : _minEventTimeOut(0), @@ -13,10 +11,4 @@ FNET_Config::FNET_Config() _tcpNoDelay(true), _logStats(false), _directWrite(true) -{ -} - - -FNET_Config::~FNET_Config() -{ -} +{ } diff --git a/fnet/src/vespa/fnet/config.h b/fnet/src/vespa/fnet/config.h index 54c6c618532..ea9f8f740df 100644 --- a/fnet/src/vespa/fnet/config.h +++ b/fnet/src/vespa/fnet/config.h @@ -2,6 +2,8 @@ #pragma once +#include <cstdint> + /** * This class is used internally by the @ref FNET_Transport to keep * track of the current configuration. @@ -19,6 +21,5 @@ public: bool _directWrite; FNET_Config(); - ~FNET_Config(); }; diff --git a/fnet/src/vespa/fnet/connection.cpp b/fnet/src/vespa/fnet/connection.cpp index d5ccbca2617..5fc9c62db92 100644 --- a/fnet/src/vespa/fnet/connection.cpp +++ b/fnet/src/vespa/fnet/connection.cpp @@ -105,7 +105,7 @@ FNET_Connection::SetState(State state) _flags._discarding = false; } - BeforeCallback(NULL); + BeforeCallback(nullptr); toDelete = _channels.Broadcast(&FNET_ControlPacket::ChannelLost); AfterCallback(); } @@ -115,7 +115,7 @@ FNET_Connection::SetState(State state) for (const FNET_Channel::UP & ch : toDelete) { if (ch.get() == ach) { - _adminChannel = NULL; + _adminChannel = nullptr; } else { SubRef_NoLock(); } @@ -136,7 +136,7 @@ FNET_Connection::HandlePacket(uint32_t plen, uint32_t pcode, Lock(); channel = _channels.Lookup(chid); - if (channel != NULL) { // deliver packet on open channel + if (channel != nullptr) { // deliver packet on open channel channel->prefetch(); // Prefetch in the shadow of the lock operation in BeforeCallback. __builtin_prefetch(&_streamer); __builtin_prefetch(&_input); @@ -144,7 +144,7 @@ FNET_Connection::HandlePacket(uint32_t plen, uint32_t pcode, BeforeCallback(channel); __builtin_prefetch(channel->GetHandler(), 0); // Prefetch the handler while packet is being decoded. packet = _streamer->Decode(&_input, plen, pcode, channel->GetContext()); - hp_rc = (packet != NULL) ? channel->Receive(packet) + hp_rc = (packet != nullptr) ? channel->Receive(packet) : channel->Receive(&FNET_ControlPacket::BadPacket); AfterCallback(); @@ -154,7 +154,7 @@ FNET_Connection::HandlePacket(uint32_t plen, uint32_t pcode, if (hp_rc == FNET_IPacketHandler::FNET_FREE_CHANNEL) { if (channel == _adminChannel) { - _adminChannel = NULL; + _adminChannel = nullptr; } else { SubRef_NoLock(); } @@ -173,7 +173,7 @@ FNET_Connection::HandlePacket(uint32_t plen, uint32_t pcode, if (_serverAdapter->InitChannel(channel, pcode)) { packet = _streamer->Decode(&_input, plen, pcode, channel->GetContext()); - hp_rc = (packet != NULL) ? channel->Receive(packet) + hp_rc = (packet != nullptr) ? channel->Receive(packet) : channel->Receive(&FNET_ControlPacket::BadPacket); AfterCallback(); @@ -402,7 +402,7 @@ FNET_Connection::FNET_Connection(FNET_TransportThread *owner, : FNET_IOComponent(owner, mySocket, spec, /* time-out = */ true), _streamer(streamer), _serverAdapter(serverAdapter), - _adminChannel(NULL), + _adminChannel(nullptr), _socket(mySocket), _context(), _state(FNET_CONNECTED), // <-- NB @@ -417,10 +417,10 @@ FNET_Connection::FNET_Connection(FNET_TransportThread *owner, _myQueue(256), _output(FNET_WRITE_SIZE * 2), _channels(), - _callbackTarget(NULL), - _cleanup(NULL) + _callbackTarget(nullptr), + _cleanup(nullptr) { - assert(_socket != NULL); + assert(_socket != nullptr); LOG(debug, "Connection(%s): State transition: %s -> %s", GetSpec(), GetStateString(FNET_CONNECTING), GetStateString(FNET_CONNECTED)); } @@ -437,7 +437,7 @@ FNET_Connection::FNET_Connection(FNET_TransportThread *owner, : FNET_IOComponent(owner, mySocket, spec, /* time-out = */ true), _streamer(streamer), _serverAdapter(serverAdapter), - _adminChannel(NULL), + _adminChannel(nullptr), _socket(mySocket), _context(context), _state(FNET_CONNECTING), @@ -452,11 +452,11 @@ FNET_Connection::FNET_Connection(FNET_TransportThread *owner, _myQueue(256), _output(FNET_WRITE_SIZE * 2), _channels(), - _callbackTarget(NULL), - _cleanup(NULL) + _callbackTarget(nullptr), + _cleanup(nullptr) { - assert(_socket != NULL); - if (adminHandler != NULL) { + assert(_socket != nullptr); + if (adminHandler != nullptr) { FNET_Channel::UP admin(new FNET_Channel(FNET_NOID, this, adminHandler, adminContext)); _adminChannel = admin.get(); _channels.Register(admin.release()); @@ -466,12 +466,12 @@ FNET_Connection::FNET_Connection(FNET_TransportThread *owner, FNET_Connection::~FNET_Connection() { - if (_adminChannel != NULL) { + if (_adminChannel != nullptr) { _channels.Unregister(_adminChannel); delete _adminChannel; } - assert(_cleanup == NULL); - assert(_socket->GetSocketEvent() == NULL); + assert(_cleanup == nullptr); + assert(_socket->GetSocketEvent() == nullptr); assert(!_flags._writeLock); delete _socket; } @@ -489,7 +489,7 @@ FNET_Connection::Init() } // init server admin channel - if (rc && CanAcceptChannels() && _adminChannel == NULL) { + if (rc && CanAcceptChannels() && _adminChannel == nullptr) { FNET_Channel::UP ach(new FNET_Channel(FNET_NOID, this)); if (_serverAdapter->InitAdminChannel(ach.get())) { AddRef_NoLock(); @@ -533,10 +533,10 @@ FNET_Connection::OpenChannel(FNET_IPacketHandler *handler, Lock(); if (__builtin_expect(_state < FNET_CLOSING, true)) { newChannel->SetID(GetNextID()); - if (chid != NULL) { + if (chid != nullptr) { *chid = newChannel->GetID(); } - WaitCallback(NULL); + WaitCallback(nullptr); AddRef_NoLock(); ret = newChannel.release(); _channels.Register(ret); @@ -595,12 +595,12 @@ FNET_Connection::CloseAdminChannel() { Lock(); FNET_Channel::UP toDelete; - if (_adminChannel != NULL) { + if (_adminChannel != nullptr) { WaitCallback(_adminChannel); - if (_adminChannel != NULL) { + if (_adminChannel != nullptr) { _channels.Unregister(_adminChannel); toDelete.reset(_adminChannel); - _adminChannel = NULL; + _adminChannel = nullptr; } } Unlock(); @@ -612,7 +612,7 @@ FNET_Connection::PostPacket(FNET_Packet *packet, uint32_t chid) { uint32_t writeWork; - assert(packet != NULL); + assert(packet != nullptr); Lock(); if (_state >= FNET_CLOSING) { if (_flags._discarding) { @@ -670,9 +670,9 @@ FNET_Connection::Sync() void FNET_Connection::CleanupHook() { - if (_cleanup != NULL) { + if (_cleanup != nullptr) { _cleanup->Cleanup(this); - _cleanup = NULL; + _cleanup = nullptr; } } @@ -680,7 +680,7 @@ FNET_Connection::CleanupHook() void FNET_Connection::Close() { - SetSocketEvent(NULL); + SetSocketEvent(nullptr); SetState(FNET_CLOSED); _socket->Shutdown(); _socket->Close(); diff --git a/fnet/src/vespa/fnet/connection.h b/fnet/src/vespa/fnet/connection.h index c66e349cb9b..3374e0b4fc3 100644 --- a/fnet/src/vespa/fnet/connection.h +++ b/fnet/src/vespa/fnet/connection.h @@ -133,7 +133,7 @@ private: void WaitCallback(FNET_Channel *channel) { while (_flags._inCallback - && (_callbackTarget == channel || _callbackTarget == NULL)) { + && (_callbackTarget == channel || _callbackTarget == nullptr)) { _flags._callbackWait = true; Wait(); } @@ -282,7 +282,7 @@ public: * * @return true/false **/ - bool CanAcceptChannels() const { return _serverAdapter != NULL; } + bool CanAcceptChannels() const { return _serverAdapter != nullptr; } /** @@ -337,24 +337,24 @@ public: /** * Open a new channel on this connection. This method will return - * NULL of this connection is broken. Note that this method may only + * nullptr of this connection is broken. Note that this method may only * be invoked on connections in the client aspect. Channels on * server aspect connections are opened with help from a server * adapter. * - * @return an object representing the opened channel or NULL. + * @return an object representing the opened channel or nullptr. * @param handler the owner of the channel to be opened. * @param context application specific context. - * @param chid store the channel id at this location if not NULL + * @param chid store the channel id at this location if not nullptr **/ FNET_Channel *OpenChannel(FNET_IPacketHandler *handler, FNET_Context context, - uint32_t *chid = NULL); + uint32_t *chid = nullptr); /** * Open a new channel on this connection that may only be used to - * send packets. This method will never return NULL. Note that this + * send packets. This method will never return nullptr. Note that this * method may only be invoked on connections in the client * aspect. Channels on server aspect connections are opened with * help from a server adapter. diff --git a/fnet/src/vespa/fnet/connector.cpp b/fnet/src/vespa/fnet/connector.cpp index 706fa73d447..5cb27335523 100644 --- a/fnet/src/vespa/fnet/connector.cpp +++ b/fnet/src/vespa/fnet/connector.cpp @@ -1,9 +1,15 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> +#include "connector.h" +#include "transport_thread.h" +#include "transport.h" +#include "connection.h" +#include <vespa/fastos/serversocket.h> + + #include <vespa/log/log.h> LOG_SETUP(".fnet"); -#include <vespa/fnet/fnet.h> + FNET_Connector::FNET_Connector(FNET_TransportThread *owner, @@ -13,25 +19,29 @@ FNET_Connector::FNET_Connector(FNET_TransportThread *owner, int port, int backlog, FastOS_SocketFactory *factory, const char *strictBindHostName) - : FNET_IOComponent(owner, NULL, spec, /* time-out = */ false), + : FNET_IOComponent(owner, nullptr, spec, /* time-out = */ false), _streamer(streamer), _serverAdapter(serverAdapter), - _serverSocket(NULL), - _strict(strictBindHostName != NULL) + _serverSocket(nullptr), + _strict(strictBindHostName != nullptr) { _serverSocket = new FastOS_ServerSocket(port, backlog, factory, strictBindHostName); - assert(_serverSocket != NULL); + assert(_serverSocket != nullptr); _ioc_socket = _serverSocket; // set socket 'manually' } FNET_Connector::~FNET_Connector() { - assert(_serverSocket->GetSocketEvent() == NULL); + assert(_serverSocket->GetSocketEvent() == nullptr); delete _serverSocket; } +uint32_t +FNET_Connector::GetPortNumber() const { + return _serverSocket->GetLocalPort(); +} bool FNET_Connector::Init() @@ -49,12 +59,10 @@ FNET_Connector::Init() // print some debug output [XXX: remove this later] if(rc) { - LOG(debug, "Connector(%s): TCP listen OK", - GetSpec()); + LOG(debug, "Connector(%s): TCP listen OK", GetSpec()); EnableReadEvent(true); } else { - LOG(warning, "Connector(%s): TCP listen FAILED", - GetSpec()); + LOG(warning, "Connector(%s): TCP listen FAILED", GetSpec()); } return rc; } @@ -63,7 +71,7 @@ FNET_Connector::Init() void FNET_Connector::Close() { - SetSocketEvent(NULL); + SetSocketEvent(nullptr); _serverSocket->Close(); } @@ -71,11 +79,11 @@ FNET_Connector::Close() bool FNET_Connector::HandleReadEvent() { - FastOS_Socket *newSocket = NULL; - FNET_Connection *conn = NULL; + FastOS_Socket *newSocket = nullptr; + FNET_Connection *conn = nullptr; newSocket = _serverSocket->AcceptPlain(); - if (newSocket != NULL) { + if (newSocket != nullptr) { FNET_Transport &transport = Owner()->owner(); FNET_TransportThread *thread = transport.select_thread(newSocket, sizeof(FastOS_Socket)); conn = new FNET_Connection(thread, _streamer, _serverAdapter, newSocket, GetSpec()); diff --git a/fnet/src/vespa/fnet/connector.h b/fnet/src/vespa/fnet/connector.h index b9d8da4dc92..130e15cd318 100644 --- a/fnet/src/vespa/fnet/connector.h +++ b/fnet/src/vespa/fnet/connector.h @@ -2,7 +2,12 @@ #pragma once -#include <vespa/fastos/serversocket.h> +#include "iocomponent.h" + +class FastOS_ServerSocket; +class FNET_IPacketStreamer; +class FNET_IServerAdapter; +class FastOS_SocketFactory; /** * Class used to listen for incoming connections on a single TCP/IP @@ -37,8 +42,8 @@ public: FNET_IServerAdapter *serverAdapter, const char *spec, int port, int backlog = 500, - FastOS_SocketFactory *factory = NULL, - const char *strictBindHostName = NULL); + FastOS_SocketFactory *factory = nullptr, + const char *strictBindHostName = nullptr); ~FNET_Connector(); @@ -47,7 +52,7 @@ public: * * @return port number **/ - uint32_t GetPortNumber() const { return _serverSocket->GetLocalPort(); } + uint32_t GetPortNumber() const; /** * Try to create a listening server socket at the port number diff --git a/fnet/src/vespa/fnet/controlpacket.cpp b/fnet/src/vespa/fnet/controlpacket.cpp index 5c17b4c2441..51334778d3d 100644 --- a/fnet/src/vespa/fnet/controlpacket.cpp +++ b/fnet/src/vespa/fnet/controlpacket.cpp @@ -1,7 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> +#include "controlpacket.h" +#include "context.h" #include <vespa/vespalib/util/stringfmt.h> void diff --git a/fnet/src/vespa/fnet/databuffer.cpp b/fnet/src/vespa/fnet/databuffer.cpp index 578faba1e49..202570ecb2e 100644 --- a/fnet/src/vespa/fnet/databuffer.cpp +++ b/fnet/src/vespa/fnet/databuffer.cpp @@ -1,13 +1,12 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> +#include "databuffer.h" FNET_DataBuffer::FNET_DataBuffer(uint32_t len) - : _bufstart(NULL), - _bufend(NULL), - _datapt(NULL), - _freept(NULL) + : _bufstart(nullptr), + _bufend(nullptr), + _datapt(nullptr), + _freept(nullptr) { if (len > 0 && len < 256) len = 256; @@ -16,9 +15,9 @@ FNET_DataBuffer::FNET_DataBuffer(uint32_t len) Alloc::alloc(len).swap(_ownedBuf); memset(_ownedBuf.get(), 0x55, len); _bufstart = static_cast<char *>(_ownedBuf.get()); - assert(_bufstart != NULL); + assert(_bufstart != nullptr); } else { // len == 0 - _bufstart = NULL; + _bufstart = nullptr; } _bufend = _bufstart + len; _datapt = _freept = _bufstart; diff --git a/fnet/src/vespa/fnet/databuffer.h b/fnet/src/vespa/fnet/databuffer.h index 316755b883f..8639a8ba06b 100644 --- a/fnet/src/vespa/fnet/databuffer.h +++ b/fnet/src/vespa/fnet/databuffer.h @@ -5,6 +5,7 @@ #include <vespa/vespalib/util/compress.h> #include <vespa/vespalib/util/alloc.h> #include <cassert> +#include <cstring> /** * This is a buffer that may hold the stream representation of diff --git a/fnet/src/vespa/fnet/dummypacket.cpp b/fnet/src/vespa/fnet/dummypacket.cpp index 27ee4741d06..0a26d71fe2a 100644 --- a/fnet/src/vespa/fnet/dummypacket.cpp +++ b/fnet/src/vespa/fnet/dummypacket.cpp @@ -1,7 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> +#include "dummypacket.h" +#include "context.h" #include <vespa/vespalib/util/stringfmt.h> diff --git a/fnet/src/vespa/fnet/fdselector.cpp b/fnet/src/vespa/fnet/fdselector.cpp index 3f050599643..d13f1d3c844 100644 --- a/fnet/src/vespa/fnet/fdselector.cpp +++ b/fnet/src/vespa/fnet/fdselector.cpp @@ -1,8 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> - +#include "fdselector.h" +#include "transport.h" +#include "transport_thread.h" FNET_FDSelector::FNET_FDSelector(FNET_Transport *transport, int fd, FNET_IFDSelectorHandler *handler, @@ -47,7 +47,7 @@ FNET_FDSelector::dispose() { Lock(); waitEvent(); - _handler = NULL; + _handler = nullptr; Unlock(); Owner()->Close(this, false); } @@ -55,14 +55,14 @@ FNET_FDSelector::dispose() FNET_FDSelector::~FNET_FDSelector() { - assert(_fdSocket.GetSocketEvent() == NULL); + assert(_fdSocket.GetSocketEvent() == nullptr); } void FNET_FDSelector::Close() { - SetSocketEvent(NULL); + SetSocketEvent(nullptr); } @@ -75,7 +75,7 @@ FNET_FDSelector::HandleReadEvent() Lock(); FNET_IFDSelectorHandler *handler = _handler; beforeEvent(); - if (handler != NULL) { + if (handler != nullptr) { handler->readEvent(this); } afterEvent(); @@ -93,7 +93,7 @@ FNET_FDSelector::HandleWriteEvent() Lock(); FNET_IFDSelectorHandler *handler = _handler; beforeEvent(); - if (handler != NULL) { + if (handler != nullptr) { handler->writeEvent(this); } afterEvent(); diff --git a/fnet/src/vespa/fnet/fdselector.h b/fnet/src/vespa/fnet/fdselector.h index 4d07baecdd0..f7468039f0b 100644 --- a/fnet/src/vespa/fnet/fdselector.h +++ b/fnet/src/vespa/fnet/fdselector.h @@ -2,6 +2,12 @@ #pragma once +#include "iocomponent.h" +#include "context.h" +#include <vespa/fastos/socket.h> + +class FNET_FDSelector; +class FNET_Transport; /** * Interface used to listen for events from a @ref FNET_FDSelector io diff --git a/fnet/src/vespa/fnet/fnet.h b/fnet/src/vespa/fnet/fnet.h index 7e859ea5e75..ee3021bf67f 100644 --- a/fnet/src/vespa/fnet/fnet.h +++ b/fnet/src/vespa/fnet/fnet.h @@ -6,17 +6,6 @@ #include <vespa/fastos/mutex.h> #include <vespa/fastos/cond.h> -// FEATURES - -#include "features.h" - -// DEFINES - -#define FNET_HAS_THREADS true - -typedef FastOS_Mutex FNET_Mutex; -typedef FastOS_Cond FNET_Cond; - // DEPRECATED #define DEPRECATED __attribute__((deprecated)) @@ -52,7 +41,6 @@ class FNET_Task; class FNET_Transport; class FNET_TransportThread; - // CONTEXT CLASS (union of types) #include "context.h" @@ -85,20 +73,3 @@ class FNET_TransportThread; #include "info.h" #include "signalshutdown.h" - -#define ASSERT_OBJECT(pt) \ - do { \ - if (pt == NULL || !pt->CheckObject()) { \ - fprintf(stderr, "%s:%d: ASSERT_OBJECT FAILED!\n", __FILE__, __LINE__); \ - abort(); \ - } \ - } while (false) - -#define ASSERT_OBJECT_NOLOCK(pt) \ - do { \ - if (pt == NULL || !pt->CheckObject_NoLock()) { \ - fprintf(stderr, "%s:%d: ASSERT_OBJECT FAILED!\n", __FILE__, __LINE__); \ - abort(); \ - } \ - } while (false) - diff --git a/fnet/src/vespa/fnet/frt/error.cpp b/fnet/src/vespa/fnet/frt/error.cpp index dc9af221bad..22bb619a67d 100644 --- a/fnet/src/vespa/fnet/frt/error.cpp +++ b/fnet/src/vespa/fnet/frt/error.cpp @@ -1,7 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/frt/frt.h> +#include "error.h" const char * FRT_GetErrorCodeName(uint32_t errorCode) diff --git a/fnet/src/vespa/fnet/frt/error.h b/fnet/src/vespa/fnet/frt/error.h index 994e303ae33..0162c00d249 100644 --- a/fnet/src/vespa/fnet/frt/error.h +++ b/fnet/src/vespa/fnet/frt/error.h @@ -2,6 +2,7 @@ #pragma once +#include <cstdint> enum { FRTE_NO_ERROR = 0, FRTE_RPC_FIRST = 100, diff --git a/fnet/src/vespa/fnet/frt/invoker.cpp b/fnet/src/vespa/fnet/frt/invoker.cpp index 7630c2de13a..a2f23f6aa36 100644 --- a/fnet/src/vespa/fnet/frt/invoker.cpp +++ b/fnet/src/vespa/fnet/frt/invoker.cpp @@ -51,7 +51,7 @@ FRT_RPCInvoker::FRT_RPCInvoker(FRT_Supervisor *supervisor, std::string methodName(_req->GetMethodName(), _req->GetMethodNameLen()); LOG(debug, "invoke(server) init: '%s'", methodName.c_str()); } - if (_method == NULL) { + if (_method == nullptr) { if (!req->IsError()) { // may be BAD_REQUEST req->SetError(FRTE_RPC_NO_SUCH_METHOD); } @@ -159,7 +159,7 @@ FRT_RPCAdapter::FRT_RPCAdapter(FNET_Scheduler *scheduler, : FNET_Task(scheduler), _req(req), _waiter(waiter), - _channel(NULL) + _channel(nullptr) { if (LOG_WOULD_LOG(debug)) { std::string methodName(_req->GetMethodName(), _req->GetMethodNameLen()); @@ -186,7 +186,7 @@ FRT_RPCAdapter::HandleAbort() if (!_req->GetCompletionToken()) { // too late return false; } - if (_channel != NULL) { + if (_channel != nullptr) { _channel->CloseAndFree(); } Kill(); @@ -202,7 +202,7 @@ FRT_RPCAdapter::PerformTask() if (!_req->GetCompletionToken()) { // too late return; } - if (_channel != NULL) { + if (_channel != nullptr) { _channel->CloseAndFree(); } if (!_req->IsError()) { diff --git a/fnet/src/vespa/fnet/frt/packets.cpp b/fnet/src/vespa/fnet/frt/packets.cpp index 0a3f63dc8bf..5e74d2de052 100644 --- a/fnet/src/vespa/fnet/frt/packets.cpp +++ b/fnet/src/vespa/fnet/frt/packets.cpp @@ -94,7 +94,7 @@ FRT_RPCRequestPacket::Print(uint32_t indent) vespalib::string s; s += vespalib::make_string("%*sFRT_RPCRequestPacket {\n", indent, ""); s += vespalib::make_string("%*s method name: %s\n", indent, "", - (_req->GetMethodName() != NULL) + (_req->GetMethodName() != nullptr) ? _req->GetMethodName() : "N/A"); s += vespalib::make_string("%*s params:\n", indent, ""); _req->GetParams()->Print(indent + 2); @@ -234,7 +234,7 @@ FRT_RPCErrorPacket::Print(uint32_t indent) s += vespalib::make_string("%*sFRT_RPCErrorPacket {\n", indent, ""); s += vespalib::make_string("%*s error code : %d\n", indent, "", _req->GetErrorCode()); s += vespalib::make_string("%*s error message: %s\n", indent, "", - (_req->GetErrorMessage() != NULL) + (_req->GetErrorMessage() != nullptr) ? _req->GetErrorMessage() : "N/A"); s += vespalib::make_string("%*s}\n", indent, ""); return s; @@ -248,8 +248,8 @@ FRT_PacketFactory::CreatePacket(uint32_t pcode, FNET_Context context) FRT_RPCRequest *req = ((FRT_RPCRequest *)context._value.VOIDP); uint32_t flags = (pcode >> 16) & 0xffff; - if (req == NULL || (flags & ~FLAG_FRT_RPC_SUPPORTED_MASK) != 0) - return NULL; + if (req == nullptr || (flags & ~FLAG_FRT_RPC_SUPPORTED_MASK) != 0) + return nullptr; vespalib::Stash & stash = req->getStash(); pcode &= 0xffff; // remove flags @@ -265,5 +265,5 @@ FRT_PacketFactory::CreatePacket(uint32_t pcode, FNET_Context context) case PCODE_FRT_RPC_ERROR: return &stash.create<FRT_RPCErrorPacket>(req, flags, false); } - return NULL; + return nullptr; } diff --git a/fnet/src/vespa/fnet/frt/rpcrequest.cpp b/fnet/src/vespa/fnet/frt/rpcrequest.cpp index bedb85e32ea..c68969d782f 100644 --- a/fnet/src/vespa/fnet/frt/rpcrequest.cpp +++ b/fnet/src/vespa/fnet/frt/rpcrequest.cpp @@ -15,12 +15,12 @@ FRT_RPCRequest::FRT_RPCRequest() _errorCode(FRTE_NO_ERROR), _errorMessageLen(0), _methodNameLen(0), - _errorMessage(NULL), - _methodName(NULL), - _detachedPT(NULL), - _abortHandler(NULL), - _returnHandler(NULL), - _cleanupHandler(NULL) + _errorMessage(nullptr), + _methodName(nullptr), + _detachedPT(nullptr), + _abortHandler(nullptr), + _returnHandler(nullptr), + _cleanupHandler(nullptr) { } FRT_RPCRequest::~FRT_RPCRequest() @@ -69,7 +69,7 @@ FRT_RPCRequest::SetMethodName(const char *methodName) { bool FRT_RPCRequest::Abort() { - if (_abortHandler == NULL) { + if (_abortHandler == nullptr) { return false; } return _abortHandler->HandleAbort(); @@ -82,16 +82,16 @@ FRT_RPCRequest::Return() { FNET_Connection * FRT_RPCRequest::GetConnection() { - if (_returnHandler == NULL) - return NULL; + if (_returnHandler == nullptr) + return nullptr; return _returnHandler->GetConnection(); } void FRT_RPCRequest::Cleanup() { - if (_cleanupHandler != NULL) { + if (_cleanupHandler != nullptr) { _cleanupHandler->HandleCleanup(); - _cleanupHandler = NULL; + _cleanupHandler = nullptr; } } @@ -105,13 +105,13 @@ FRT_RPCRequest::Reset() { _stash.clear(); _errorCode = FRTE_NO_ERROR; _errorMessageLen = 0; - _errorMessage = NULL; + _errorMessage = nullptr; _methodNameLen = 0; - _methodName = NULL; - _detachedPT = NULL; + _methodName = nullptr; + _detachedPT = nullptr; _completed = 0; - _abortHandler = NULL; - _returnHandler = NULL; + _abortHandler = nullptr; + _returnHandler = nullptr; } @@ -141,9 +141,9 @@ FRT_RPCRequest::Print(uint32_t indent) { printf("%*sFRT_RPCRequest {\n", indent, ""); printf("%*s method: %s\n", indent, "", - (_methodName != NULL)? _methodName : "(N/A)"); + (_methodName != nullptr)? _methodName : "(N/A)"); printf("%*s error(%d): %s\n", indent, "", _errorCode, - (_errorMessage != NULL) + (_errorMessage != nullptr) ? _errorMessage : FRT_GetDefaultErrorMessage(_errorCode)); printf("%*s params:\n", indent, ""); diff --git a/fnet/src/vespa/fnet/frt/rpcrequest.h b/fnet/src/vespa/fnet/frt/rpcrequest.h index 89611a9035a..2441fb081d3 100644 --- a/fnet/src/vespa/fnet/frt/rpcrequest.h +++ b/fnet/src/vespa/fnet/frt/rpcrequest.h @@ -102,12 +102,12 @@ public: const char *GetParamSpec() { const char *spec = _params.GetTypeString(); - return (spec != NULL) ? spec : ""; + return (spec != nullptr) ? spec : ""; } const char *GetReturnSpec() { const char *spec = _return.GetTypeString(); - return (spec != NULL) ? spec : ""; + return (spec != nullptr) ? spec : ""; } bool GetCompletionToken() { return (vespalib::Atomic::postInc(&_completed) == 0); } diff --git a/fnet/src/vespa/fnet/frt/supervisor.h b/fnet/src/vespa/fnet/frt/supervisor.h index 56c0abe6d5b..f58f4c7ae68 100644 --- a/fnet/src/vespa/fnet/frt/supervisor.h +++ b/fnet/src/vespa/fnet/frt/supervisor.h @@ -104,7 +104,7 @@ public: FRT_Target *Get2WayTarget(const char *spec, FNET_Context connContext = FNET_Context()); FRT_Target *GetTarget(int port); - FRT_RPCRequest *AllocRPCRequest(FRT_RPCRequest *tradein = NULL); + FRT_RPCRequest *AllocRPCRequest(FRT_RPCRequest *tradein = nullptr); // special hooks (implemented as RPC methods) void SetSessionInitHook(FRT_METHOD_PT method, FRT_Invokable *handler); diff --git a/fnet/src/vespa/fnet/frt/target.cpp b/fnet/src/vespa/fnet/frt/target.cpp index ee4d3e672fe..11e8515719e 100644 --- a/fnet/src/vespa/fnet/frt/target.cpp +++ b/fnet/src/vespa/fnet/frt/target.cpp @@ -1,14 +1,30 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/frt/frt.h> + +#include "target.h" +#include "supervisor.h" +#include <vespa/fnet/transport_thread.h> FRT_Target::~FRT_Target() { assert(_refcnt == 0); FNET_Connection * conn(_conn); - _conn = NULL; - if (conn != NULL) { + _conn = nullptr; + if (conn != nullptr) { conn->Owner()->Close(conn, /* needref */ false); } } +void +FRT_Target::InvokeAsync(FRT_RPCRequest *req, double timeout, FRT_IRequestWait *waiter) { + FRT_Supervisor::InvokeAsync(_scheduler, _conn, req, timeout, waiter); +} + +void +FRT_Target::InvokeVoid(FRT_RPCRequest *req) { + FRT_Supervisor::InvokeVoid(_conn, req); +} + +void +FRT_Target::InvokeSync(FRT_RPCRequest *req, double timeout) { + FRT_Supervisor::InvokeSync(_scheduler, _conn, req, timeout); +}
\ No newline at end of file diff --git a/fnet/src/vespa/fnet/frt/target.h b/fnet/src/vespa/fnet/frt/target.h index 62586da0e65..3b659d0505b 100644 --- a/fnet/src/vespa/fnet/frt/target.h +++ b/fnet/src/vespa/fnet/frt/target.h @@ -3,6 +3,11 @@ #pragma once #include <vespa/vespalib/util/atomic.h> +#include <vespa/fnet/connection.h> + +class FNET_Scheduler; +class FRT_RPCRequest; +class FRT_IRequestWait; class FRT_Target { @@ -35,22 +40,11 @@ public: bool IsValid() { - return ((_conn != NULL) && + return ((_conn != nullptr) && (_conn->GetState() <= FNET_Connection::FNET_CONNECTED)); } - void InvokeAsync(FRT_RPCRequest *req, double timeout, FRT_IRequestWait *waiter) - { - FRT_Supervisor::InvokeAsync(_scheduler, _conn, req, timeout, waiter); - } - - void InvokeVoid(FRT_RPCRequest *req) - { - FRT_Supervisor::InvokeVoid(_conn, req); - } - - void InvokeSync(FRT_RPCRequest *req, double timeout) - { - FRT_Supervisor::InvokeSync(_scheduler, _conn, req, timeout); - } + void InvokeAsync(FRT_RPCRequest *req, double timeout, FRT_IRequestWait *waiter); + void InvokeVoid(FRT_RPCRequest *req); + void InvokeSync(FRT_RPCRequest *req, double timeout); }; diff --git a/fnet/src/vespa/fnet/frt/values.cpp b/fnet/src/vespa/fnet/frt/values.cpp index 0d6ee4a8e97..7303f530e04 100644 --- a/fnet/src/vespa/fnet/frt/values.cpp +++ b/fnet/src/vespa/fnet/frt/values.cpp @@ -75,9 +75,9 @@ using fnet::LocalBlob; FRT_Values::FRT_Values(Stash * stash) : _maxValues(0), _numValues(0), - _typeString(NULL), - _values(NULL), - _blobs(NULL), + _typeString(nullptr), + _values(nullptr), + _blobs(nullptr), _stash(stash) { } @@ -87,7 +87,7 @@ LocalBlob::LocalBlob(const char *data, uint32_t len) : _data(Alloc::alloc(len)), _len(len) { - if (data != NULL) { + if (data != nullptr) { memcpy(_data.get(), data, len); } } @@ -95,19 +95,19 @@ LocalBlob::LocalBlob(const char *data, uint32_t len) : void FRT_Values::DiscardBlobs() { - while (_blobs != NULL) { + while (_blobs != nullptr) { BlobRef *ref = _blobs; _blobs = ref->_next; FRT_ISharedBlob *blob = ref->_blob; FRT_DataValue *value = ref->_value; - if (value == NULL) { + if (value == nullptr) { uint32_t idx = ref->_idx; assert(_numValues > idx); assert(_typeString[idx] == 'x'); value = &_values[idx]._data; } if ((value->_buf == blob->getData()) && (value->_len == blob->getLen())) { - value->_buf = NULL; + value->_buf = nullptr; value->_len = 0; } ref->discard(); @@ -347,7 +347,7 @@ FRT_Values::SetString(FRT_StringValue *value, const char *str) { void FRT_Values::SetData(FRT_DataValue *value, const char *buf, uint32_t len) { - char *mybuf = NULL; + char *mybuf = nullptr; if (len > SHARED_LIMIT) { LocalBlob *blob = &_stash->create<LocalBlob>(buf, len); _blobs = &_stash->create<BlobRef>(value, 0, blob, _blobs); diff --git a/fnet/src/vespa/fnet/frt/values.h b/fnet/src/vespa/fnet/frt/values.h index fafdab30a9d..d625d23046d 100644 --- a/fnet/src/vespa/fnet/frt/values.h +++ b/fnet/src/vespa/fnet/frt/values.h @@ -103,8 +103,8 @@ public: DiscardBlobs(); _maxValues = 0; _numValues = 0; - _typeString = NULL; - _values = NULL; + _typeString = nullptr; + _values = nullptr; } void EnsureFree(uint32_t need = 1); diff --git a/fnet/src/vespa/fnet/info.cpp b/fnet/src/vespa/fnet/info.cpp index 1ad3dbb784a..7b75a5f404b 100644 --- a/fnet/src/vespa/fnet/info.cpp +++ b/fnet/src/vespa/fnet/info.cpp @@ -1,18 +1,16 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> +#include "info.h" +#include <vespa/vespalib/component/vtag.h> + #include <vespa/log/log.h> LOG_SETUP(".fnet"); -#include <vespa/fnet/fnet.h> - uint32_t FNET_Info::_endian = FNET_Info::ENDIAN_UNKNOWN; -FNET_Info global_fnet_info_object; - FNET_Info::FNET_Info() { - uint8_t *pt = NULL; + uint8_t *pt = nullptr; uint64_t cmp = 0; uint32_t endian = ENDIAN_UNKNOWN; diff --git a/fnet/src/vespa/fnet/info.h b/fnet/src/vespa/fnet/info.h index cd293d30088..abb1d3583f5 100644 --- a/fnet/src/vespa/fnet/info.h +++ b/fnet/src/vespa/fnet/info.h @@ -2,6 +2,7 @@ #pragma once +#include <cstdint> /** * This class provides overall information about the FNET * implementation. @@ -58,4 +59,3 @@ public: **/ static void LogInfo(); }; - diff --git a/fnet/src/vespa/fnet/iocomponent.cpp b/fnet/src/vespa/fnet/iocomponent.cpp index c41a0826b83..f6154f04951 100644 --- a/fnet/src/vespa/fnet/iocomponent.cpp +++ b/fnet/src/vespa/fnet/iocomponent.cpp @@ -9,12 +9,12 @@ FNET_IOComponent::FNET_IOComponent(FNET_TransportThread *owner, FastOS_SocketInterface *mysocket, const char *spec, bool shouldTimeOut) - : _ioc_next(NULL), - _ioc_prev(NULL), + : _ioc_next(nullptr), + _ioc_prev(nullptr), _ioc_owner(owner), _ioc_counters(_ioc_owner->GetStatCounters()), _ioc_socket(mysocket), - _ioc_spec(NULL), + _ioc_spec(nullptr), _flags(shouldTimeOut), _ioc_timestamp(fastos::ClockSystem::now()), _ioc_cond(), @@ -23,7 +23,7 @@ FNET_IOComponent::FNET_IOComponent(FNET_TransportThread *owner, _ioc_directDataWriteCnt(0) { _ioc_spec = strdup(spec); - assert(_ioc_spec != NULL); + assert(_ioc_spec != nullptr); } @@ -104,7 +104,7 @@ FNET_IOComponent::SetSocketEvent(FastOS_SocketEvent *event) assert(rc); // XXX: error handling (void) rc; - if (event != NULL) { + if (event != nullptr) { _ioc_socket->EnableReadEvent(_flags._ioc_readEnabled); _ioc_socket->EnableWriteEvent(_flags._ioc_writeEnabled); } @@ -115,7 +115,7 @@ void FNET_IOComponent::EnableReadEvent(bool enabled) { _flags._ioc_readEnabled = enabled; - if (_ioc_socket->GetSocketEvent() != NULL) + if (_ioc_socket->GetSocketEvent() != nullptr) _ioc_socket->EnableReadEvent(enabled); } @@ -124,7 +124,7 @@ void FNET_IOComponent::EnableWriteEvent(bool enabled) { _flags._ioc_writeEnabled = enabled; - if (_ioc_socket->GetSocketEvent() != NULL) + if (_ioc_socket->GetSocketEvent() != nullptr) _ioc_socket->EnableWriteEvent(enabled); } diff --git a/fnet/src/vespa/fnet/iocomponent.h b/fnet/src/vespa/fnet/iocomponent.h index efd106e0473..d04e83830c3 100644 --- a/fnet/src/vespa/fnet/iocomponent.h +++ b/fnet/src/vespa/fnet/iocomponent.h @@ -270,7 +270,7 @@ public: /** * Assign a FastOS_SocketEvent to this component. Before deleting an - * IOC, one must assign NULL as the socket event. + * IOC, one must assign nullptr as the socket event. * * @param event the socket event to register with. **/ diff --git a/fnet/src/vespa/fnet/ipacketstreamer.h b/fnet/src/vespa/fnet/ipacketstreamer.h index 734ec74da8c..ad31506dc37 100644 --- a/fnet/src/vespa/fnet/ipacketstreamer.h +++ b/fnet/src/vespa/fnet/ipacketstreamer.h @@ -2,6 +2,11 @@ #pragma once +#include "context.h" + +class FNET_DataBuffer; +class FNET_Packet; + /** * Class used to do custom streaming of packets on network * connections. The application is responsible for implementing the @@ -15,7 +20,7 @@ public: /** * Destructor. No cleanup needed for base class. */ - virtual ~FNET_IPacketStreamer(void) { } + virtual ~FNET_IPacketStreamer() { } /** * This method is called to obtain information about the next packet @@ -58,7 +63,7 @@ public: * GetPacketInfo method are given as parameters to this method to * avoid the need to parse the packet header twice. * - * @return packet decoded from 'buf' or NULL on failure + * @return packet decoded from 'buf' or nullptr on failure * @param src buffer with the serialized packet * @param plen packet length as reported by @ref GetPacketInfo * @param pcode packet code as reported by @ref GetPacketInfo diff --git a/fnet/src/vespa/fnet/packet.cpp b/fnet/src/vespa/fnet/packet.cpp index c61ae2dc2a4..85172841822 100644 --- a/fnet/src/vespa/fnet/packet.cpp +++ b/fnet/src/vespa/fnet/packet.cpp @@ -1,10 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> +#include "packet.h" #include <vespa/vespalib/util/stringfmt.h> - vespalib::string FNET_Packet::Print(uint32_t indent) { diff --git a/fnet/src/vespa/fnet/packetqueue.cpp b/fnet/src/vespa/fnet/packetqueue.cpp index 1a2bd92fd96..795410c1105 100644 --- a/fnet/src/vespa/fnet/packetqueue.cpp +++ b/fnet/src/vespa/fnet/packetqueue.cpp @@ -1,8 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> - +#include "packetqueue.h" +#include "packet.h" +#include <vespa/fastos/time.h> void FNET_PacketQueue_NoLock::ExpandBuf(uint32_t needentries) @@ -13,7 +13,7 @@ FNET_PacketQueue_NoLock::ExpandBuf(uint32_t needentries) while (_bufsize < _bufused + needentries) _bufsize *= 2; _QElem *newbuf = static_cast<_QElem *>(malloc(sizeof(_QElem) * _bufsize)); - assert(newbuf != NULL); + assert(newbuf != nullptr); if (_bufused == 0) { // EMPTY // BUFFER: |....................| // USED: |....................| @@ -45,7 +45,7 @@ FNET_PacketQueue_NoLock::ExpandBuf(uint32_t needentries) FNET_PacketQueue_NoLock::FNET_PacketQueue_NoLock(uint32_t len, HP_RetCode hpRetCode) - : _buf(NULL), + : _buf(nullptr), _bufsize(len), _bufused(0), _in_pos(0), @@ -53,7 +53,7 @@ FNET_PacketQueue_NoLock::FNET_PacketQueue_NoLock(uint32_t len, _hpRetCode(hpRetCode) { _buf = static_cast<_QElem *>(malloc(sizeof(_QElem) * len)); - assert(_buf != NULL); + assert(_buf != nullptr); } @@ -77,7 +77,7 @@ void FNET_PacketQueue_NoLock::QueuePacket_NoLock(FNET_Packet *packet, FNET_Context context) { - if (packet == NULL) + if (packet == nullptr) return; EnsureFree(); _buf[_in_pos]._packet = packet; @@ -91,8 +91,8 @@ FNET_PacketQueue_NoLock::QueuePacket_NoLock(FNET_Packet *packet, FNET_Packet* FNET_PacketQueue_NoLock::DequeuePacket_NoLock(FNET_Context *context) { - assert(context != NULL); - FNET_Packet *packet = NULL; + assert(context != nullptr); + FNET_Packet *packet = nullptr; if (_bufused > 0) { packet = _buf[_out_pos]._packet; __builtin_prefetch(packet, 0); @@ -188,7 +188,7 @@ FNET_PacketQueue::HandlePacket(FNET_Packet *packet, void FNET_PacketQueue::QueuePacket(FNET_Packet *packet, FNET_Context context) { - assert(packet != NULL); + assert(packet != nullptr); Lock(); EnsureFree(); _buf[_in_pos]._packet = packet; // insert packet ref. @@ -205,7 +205,7 @@ FNET_PacketQueue::QueuePacket(FNET_Packet *packet, FNET_Context context) FNET_Packet* FNET_PacketQueue::DequeuePacket(FNET_Context *context) { - FNET_Packet *packet = NULL; + FNET_Packet *packet = nullptr; Lock(); _waitCnt++; while (_bufused == 0) @@ -224,7 +224,7 @@ FNET_PacketQueue::DequeuePacket(FNET_Context *context) FNET_Packet* FNET_PacketQueue::DequeuePacket(uint32_t maxwait, FNET_Context *context) { - FNET_Packet *packet = NULL; + FNET_Packet *packet = nullptr; FastOS_Time startTime; int waitTime; diff --git a/fnet/src/vespa/fnet/packetqueue.h b/fnet/src/vespa/fnet/packetqueue.h index b36b899a05f..47182494f0c 100644 --- a/fnet/src/vespa/fnet/packetqueue.h +++ b/fnet/src/vespa/fnet/packetqueue.h @@ -28,7 +28,7 @@ protected: FNET_Packet *_packet; FNET_Context _context; protected: - _QElem() : _packet(NULL), _context() {} + _QElem() : _packet(nullptr), _context() {} private: _QElem(const _QElem &); _QElem &operator=(const _QElem &); @@ -119,10 +119,10 @@ public: /** * Remove the first packet from the queue and return it. If the - * queue was empty, NULL is returned. NOTE: packet handover (invoked + * queue was empty, nullptr is returned. NOTE: packet handover (invoked * object TO caller). * - * @return first packet in queue or NULL. + * @return first packet in queue or nullptr. * @param context where to store the packet context. **/ FNET_Packet *DequeuePacket_NoLock(FNET_Context *context); @@ -268,7 +268,7 @@ public: * available on the queue, but for no more than 'maxwait' * milliseconds. NOTE: packet handover (invoked object TO caller) * - * @return a packet obtained from the queue or NULL. + * @return a packet obtained from the queue or nullptr. * @param maxwait maximum number of milliseconds before this * method call returns. * @param context where to store packet context. diff --git a/fnet/src/vespa/fnet/scheduler.cpp b/fnet/src/vespa/fnet/scheduler.cpp index 56426a5aa92..71f02754a92 100644 --- a/fnet/src/vespa/fnet/scheduler.cpp +++ b/fnet/src/vespa/fnet/scheduler.cpp @@ -15,16 +15,16 @@ FNET_Scheduler::FNET_Scheduler(FastOS_Time *sampler, _sampler(sampler), _currIter(0), _currSlot(0), - _currPt(NULL), - _tailPt(NULL), - _performing(NULL), + _currPt(nullptr), + _tailPt(nullptr), + _performing(nullptr), _waitTask(false) { for (int i = 0; i < NUM_SLOTS; i++) - _slots[i] = NULL; - _slots[NUM_SLOTS] = NULL; + _slots[i] = nullptr; + _slots[NUM_SLOTS] = nullptr; - if (now != NULL) { + if (now != nullptr) { _next = *now; } else { _next.SetNow(); @@ -43,7 +43,7 @@ FNET_Scheduler::~FNET_Scheduler() dump << " [slot=" << _currSlot << "][iter=" << _currIter << "]" << std::endl; for (int i = 0; i <= NUM_SLOTS; i++) { FNET_Task *pt = _slots[i]; - if (pt != NULL) { + if (pt != nullptr) { empty = false; FNET_Task *end = pt; do { @@ -126,7 +126,7 @@ FNET_Scheduler::Print(FILE *dst) fprintf(dst, " [slot=%d][iter=%d]\n", _currSlot, _currIter); for (int i = 0; i <= NUM_SLOTS; i++) { FNET_Task *pt = _slots[i]; - if (pt != NULL) { + if (pt != nullptr) { FNET_Task *end = pt; do { fprintf(dst, " FNET_Task { slot=%d, iter=%d }\n", @@ -143,7 +143,7 @@ FNET_Scheduler::Print(FILE *dst) void FNET_Scheduler::CheckTasks() { - if (_sampler != NULL) { + if (_sampler != nullptr) { _now = *_sampler; } else { _now.SetNow(); @@ -151,7 +151,7 @@ FNET_Scheduler::CheckTasks() // assume timely value propagation - if (_slots[NUM_SLOTS] == NULL && _now < _next) + if (_slots[NUM_SLOTS] == nullptr && _now < _next) return; Lock(); @@ -177,20 +177,20 @@ FNET_Scheduler::CheckTasks() void FNET_Scheduler::FirstTask(uint32_t slot) { _currPt = _slots[slot]; - _tailPt = (_currPt != NULL) ? - _currPt->_task_prev : NULL; + _tailPt = (_currPt != nullptr) ? + _currPt->_task_prev : nullptr; } void FNET_Scheduler::NextTask() { _currPt = (_currPt != _tailPt) ? - _currPt->_task_next : NULL; + _currPt->_task_next : nullptr; } void FNET_Scheduler::AdjustCurrPt() { _currPt = (_currPt != _tailPt) ? - _currPt->_task_next : NULL; + _currPt->_task_next : nullptr; } void @@ -202,7 +202,7 @@ void FNET_Scheduler::LinkIn(FNET_Task *task) { FNET_Task **head = &(_slots[task->_task_slot]); - if ((*head) == NULL) { + if ((*head) == nullptr) { (*head) = task; task->_task_next = task; task->_task_prev = task; @@ -224,15 +224,15 @@ FNET_Scheduler::LinkOut(FNET_Task *task) { AdjustTailPt(); if (task->_task_next == task) { - (*head) = NULL; + (*head) = nullptr; } else { task->_task_prev->_task_next = task->_task_next; task->_task_next->_task_prev = task->_task_prev; if ((*head) == task) (*head) = task->_task_next; } - task->_task_next = NULL; - task->_task_prev = NULL; + task->_task_next = nullptr; + task->_task_prev = nullptr; } void @@ -244,7 +244,7 @@ FNET_Scheduler::BeforeTask(FNET_Task *task) { void FNET_Scheduler::AfterTask() { Lock(); - _performing = NULL; + _performing = nullptr; if (_waitTask) { _waitTask = false; Broadcast(); @@ -262,7 +262,7 @@ FNET_Scheduler::WaitTask(FNET_Task *task) { void FNET_Scheduler::PerformTasks(uint32_t slot, uint32_t iter) { FirstTask(slot); - for (FNET_Task *task; (task = GetTask()) != NULL; ) { + for (FNET_Task *task; (task = GetTask()) != nullptr; ) { NextTask(); if (task->_task_iter == iter) { @@ -275,5 +275,5 @@ FNET_Scheduler::PerformTasks(uint32_t slot, uint32_t iter) { } bool FNET_Scheduler::IsActive(FNET_Task *task) { - return task->_task_next != NULL; + return task->_task_next != nullptr; }
\ No newline at end of file diff --git a/fnet/src/vespa/fnet/scheduler.h b/fnet/src/vespa/fnet/scheduler.h index 7636b16ae9a..c913f3bc4f2 100644 --- a/fnet/src/vespa/fnet/scheduler.h +++ b/fnet/src/vespa/fnet/scheduler.h @@ -74,8 +74,8 @@ public: * @param now if given, indicates the current time. This value is * used by the constructor to init internal variables. **/ - FNET_Scheduler(FastOS_Time *sampler = NULL, - FastOS_Time *now = NULL); + FNET_Scheduler(FastOS_Time *sampler = nullptr, + FastOS_Time *now = nullptr); virtual ~FNET_Scheduler(); diff --git a/fnet/src/vespa/fnet/signalshutdown.cpp b/fnet/src/vespa/fnet/signalshutdown.cpp index fc9a504bdea..480635f72a8 100644 --- a/fnet/src/vespa/fnet/signalshutdown.cpp +++ b/fnet/src/vespa/fnet/signalshutdown.cpp @@ -1,9 +1,16 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> +#include "signalshutdown.h" +#include "transport.h" #include <vespa/vespalib/util/signalhandler.h> +FNET_SignalShutDown::FNET_SignalShutDown(FNET_Transport &t) + : FNET_Task(t.GetScheduler()), + _transport(t) +{ + ScheduleNow(); +} + void FNET_SignalShutDown::PerformTask() { diff --git a/fnet/src/vespa/fnet/signalshutdown.h b/fnet/src/vespa/fnet/signalshutdown.h index 755f7a6080c..ba5e5a5bb29 100644 --- a/fnet/src/vespa/fnet/signalshutdown.h +++ b/fnet/src/vespa/fnet/signalshutdown.h @@ -2,6 +2,9 @@ #pragma once +#include "task.h" + +class FNET_Transport; /** * Utility class that will shut down a transport when the process gets * either INT or TERM. @@ -12,10 +15,8 @@ private: FNET_Transport &_transport; public: - FNET_SignalShutDown(FNET_Transport &t) : FNET_Task(t.GetScheduler()), _transport(t) { - ScheduleNow(); - } - virtual void PerformTask(); + FNET_SignalShutDown(FNET_Transport &t); + void PerformTask() override; /** * Set up signal handling to hook appropriate signals. diff --git a/fnet/src/vespa/fnet/simplepacketstreamer.cpp b/fnet/src/vespa/fnet/simplepacketstreamer.cpp index 46b782c16a0..b3d04ce170c 100644 --- a/fnet/src/vespa/fnet/simplepacketstreamer.cpp +++ b/fnet/src/vespa/fnet/simplepacketstreamer.cpp @@ -1,8 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> - +#include "simplepacketstreamer.h" +#include "databuffer.h" +#include "ipacketfactory.h" +#include "packet.h" FNET_SimplePacketStreamer::FNET_SimplePacketStreamer(FNET_IPacketFactory *factory) : _factory(factory) @@ -39,10 +40,10 @@ FNET_SimplePacketStreamer::Decode(FNET_DataBuffer *src, uint32_t plen, FNET_Packet *packet; packet = _factory->CreatePacket(pcode, context); - if (packet != NULL) { + if (packet != nullptr) { if (!packet->Decode(src, plen)) { packet->Free(); - packet = NULL; + packet = nullptr; } } else { src->DataToDead(plen); diff --git a/fnet/src/vespa/fnet/simplepacketstreamer.h b/fnet/src/vespa/fnet/simplepacketstreamer.h index b075206107b..57b96900791 100644 --- a/fnet/src/vespa/fnet/simplepacketstreamer.h +++ b/fnet/src/vespa/fnet/simplepacketstreamer.h @@ -4,6 +4,8 @@ #include "ipacketstreamer.h" +class FNET_IPacketFactory; + /** * This is a convenience class. Large applications may want to * implement the functionality offered by this class themselves to @@ -30,13 +32,10 @@ private: public: FNET_SimplePacketStreamer(FNET_IPacketFactory *factory); - virtual ~FNET_SimplePacketStreamer(); - - bool GetPacketInfo(FNET_DataBuffer *src, uint32_t *plen, - uint32_t *pcode, uint32_t *chid, - bool *broken); - FNET_Packet *Decode(FNET_DataBuffer *src, uint32_t plen, - uint32_t pcode, FNET_Context context); - void Encode(FNET_Packet *packet, uint32_t chid, FNET_DataBuffer *dst); + ~FNET_SimplePacketStreamer(); + + bool GetPacketInfo(FNET_DataBuffer *src, uint32_t *plen, uint32_t *pcode, uint32_t *chid, bool *broken) override; + FNET_Packet *Decode(FNET_DataBuffer *src, uint32_t plen, uint32_t pcode, FNET_Context context) override; + void Encode(FNET_Packet *packet, uint32_t chid, FNET_DataBuffer *dst) override; }; diff --git a/fnet/src/vespa/fnet/stats.cpp b/fnet/src/vespa/fnet/stats.cpp index 3c128c96c7c..10ae36f1ffb 100644 --- a/fnet/src/vespa/fnet/stats.cpp +++ b/fnet/src/vespa/fnet/stats.cpp @@ -1,9 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> +#include "stats.h" + #include <vespa/log/log.h> LOG_SETUP(".fnet"); -#include <vespa/fnet/fnet.h> FNET_StatCounters::FNET_StatCounters() : _eventLoopCnt(0), diff --git a/fnet/src/vespa/fnet/task.cpp b/fnet/src/vespa/fnet/task.cpp index 99a1f668189..1e3baef5e73 100644 --- a/fnet/src/vespa/fnet/task.cpp +++ b/fnet/src/vespa/fnet/task.cpp @@ -1,15 +1,14 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <vespa/fnet/fnet.h> - +#include "task.h" +#include "scheduler.h" FNET_Task::FNET_Task(FNET_Scheduler *scheduler) : _task_scheduler(scheduler), _task_slot(0), _task_iter(0), - _task_next(NULL), - _task_prev(NULL), + _task_next(nullptr), + _task_prev(nullptr), _killed(false) { } diff --git a/fnet/src/vespa/fnet/transport.h b/fnet/src/vespa/fnet/transport.h index 53f84d3a9a9..dc7b1d7f626 100644 --- a/fnet/src/vespa/fnet/transport.h +++ b/fnet/src/vespa/fnet/transport.h @@ -73,7 +73,7 @@ public: * may supply a hostname as well, like this: * 'tcp/mycomputer.mydomain:8001'. * - * @return the connector object, or NULL if listen failed. + * @return the connector object, or nullptr if listen failed. * @param spec string specifying how and where to listen. * @param streamer custom packet streamer. * @param serverAdapter object for custom channel creation. @@ -107,9 +107,9 @@ public: * @param connContext application context for the connection. **/ FNET_Connection *Connect(const char *spec, FNET_IPacketStreamer *streamer, - FNET_IPacketHandler *adminHandler = NULL, + FNET_IPacketHandler *adminHandler = nullptr, FNET_Context adminContext = FNET_Context(), - FNET_IServerAdapter *serverAdapter = NULL, + FNET_IServerAdapter *serverAdapter = nullptr, FNET_Context connContext = FNET_Context()); /** diff --git a/fnet/src/vespa/fnet/transport_thread.cpp b/fnet/src/vespa/fnet/transport_thread.cpp index 6b99c92ba73..6ded04822cf 100644 --- a/fnet/src/vespa/fnet/transport_thread.cpp +++ b/fnet/src/vespa/fnet/transport_thread.cpp @@ -8,6 +8,7 @@ #include "connection.h" #include "transport.h" #include <vespa/vespalib/util/sync.h> +#include <vespa/fastos/socket.h> #include <vespa/log/log.h> LOG_SETUP(".fnet"); @@ -52,7 +53,7 @@ SplitString(char *input, const char *sep, int &argc, char **argv, int maxargs) } if (*(argv[argc]) != '\0') argc++; - return NULL; // COMPLETE + return nullptr; // COMPLETE } #ifndef IAM_DOXYGEN @@ -69,20 +70,20 @@ FNET_TransportThread::AddComponent(FNET_IOComponent *comp) { if (comp->ShouldTimeOut()) { comp->_ioc_prev = _componentsTail; - comp->_ioc_next = NULL; - if (_componentsTail == NULL) { + comp->_ioc_next = nullptr; + if (_componentsTail == nullptr) { _componentsHead = comp; } else { _componentsTail->_ioc_next = comp; } _componentsTail = comp; - if (_timeOutHead == NULL) + if (_timeOutHead == nullptr) _timeOutHead = comp; _componentCnt++; } else { - comp->_ioc_prev = NULL; + comp->_ioc_prev = nullptr; comp->_ioc_next = _componentsHead; - if (_componentsHead == NULL) { + if (_componentsHead == nullptr) { _componentsTail = comp; } else { _componentsHead->_ioc_prev = comp; @@ -102,9 +103,9 @@ FNET_TransportThread::RemoveComponent(FNET_IOComponent *comp) _timeOutHead = comp->_ioc_next; if (comp == _componentsTail) _componentsTail = comp->_ioc_prev; - if (comp->_ioc_prev != NULL) + if (comp->_ioc_prev != nullptr) comp->_ioc_prev->_ioc_next = comp->_ioc_next; - if (comp->_ioc_next != NULL) + if (comp->_ioc_next != nullptr) comp->_ioc_next->_ioc_prev = comp->_ioc_prev; _componentCnt--; } @@ -125,7 +126,7 @@ FNET_TransportThread::AddDeleteComponent(FNET_IOComponent *comp) assert(!comp->_flags._ioc_delete); comp->_flags._ioc_added = false; comp->_flags._ioc_delete = true; - comp->_ioc_prev = NULL; + comp->_ioc_prev = nullptr; comp->_ioc_next = _deleteList; _deleteList = comp; } @@ -134,7 +135,7 @@ FNET_TransportThread::AddDeleteComponent(FNET_IOComponent *comp) void FNET_TransportThread::FlushDeleteList() { - while (_deleteList != NULL) { + while (_deleteList != nullptr) { FNET_IOComponent *tmp = _deleteList; _deleteList = tmp->_ioc_next; assert(tmp->_flags._ioc_delete); @@ -191,7 +192,7 @@ FNET_TransportThread::UpdateStats() double ms = _now.MilliSecs() - _statTime.MilliSecs(); _statTime = _now; for (FNET_IOComponent *comp = _componentsHead; - comp != NULL; comp = comp->_ioc_next) + comp != nullptr; comp = comp->_ioc_next) { comp->Lock(); comp->FlushDirectWriteStats(); @@ -217,11 +218,11 @@ extern "C" { { struct sigaction act; memset(&act, 0, sizeof(act)); - sigaction(SIGPIPE, NULL, &act); + sigaction(SIGPIPE, nullptr, &act); if (act.sa_handler == SIG_DFL) { memset(&act, 0, sizeof(act)); act.sa_handler = pipehandler; - sigaction(SIGPIPE, &act, NULL); + sigaction(SIGPIPE, &act, nullptr); LOG(warning, "missing signal handler for SIGPIPE (added no-op)"); } } @@ -238,13 +239,13 @@ FNET_TransportThread::FNET_TransportThread(FNET_Transport &owner_in) _statsTask(&_scheduler, this), _statTime(), _config(), - _componentsHead(NULL), - _timeOutHead(NULL), - _componentsTail(NULL), + _componentsHead(nullptr), + _timeOutHead(nullptr), + _componentsTail(nullptr), _componentCnt(0), - _deleteList(NULL), + _deleteList(nullptr), _socketEvent(), - _events(NULL), + _events(nullptr), _queue(), _myQueue(), _cond(), @@ -283,34 +284,34 @@ FNET_TransportThread::Listen(const char *spec, FNET_IPacketStreamer *streamer, assert(speclen < 1024); memcpy(tmp, spec, speclen); tmp[speclen] = '\0'; - if (SplitString(tmp, "/", argc, argv, 32) != NULL + if (SplitString(tmp, "/", argc, argv, 32) != nullptr || argc != 2) - return NULL; // wrong number of parameters + return nullptr; // wrong number of parameters // handle different connection types (currently only TCP/IP support) if (strcasecmp(argv[0], "tcp") == 0) { - if (SplitString(argv[1], ":", argc, argv, 32) != NULL + if (SplitString(argv[1], ":", argc, argv, 32) != nullptr || argc < 1 || argc > 2) - return NULL; // wrong number of parameters + return nullptr; // wrong number of parameters int port = atoi(argv[argc - 1]); // last param is port if (port < 0) - return NULL; + return nullptr; if (port == 0 && strcmp(argv[argc - 1], "0") != 0) - return NULL; + return nullptr; FNET_Connector *connector; connector = new FNET_Connector(this, streamer, serverAdapter, spec, port, - 500, NULL, (argc == 2) ? argv[0] : NULL); + 500, nullptr, (argc == 2) ? argv[0] : nullptr); if (connector->Init()) { connector->AddRef_NoLock(); Add(connector, /* needRef = */ false); return connector; } else { delete connector; - return NULL; + return nullptr; } } else { - return NULL; + return nullptr; } } @@ -330,19 +331,19 @@ FNET_TransportThread::Connect(const char *spec, FNET_IPacketStreamer *streamer, assert(speclen < 1024); memcpy(tmp, spec, speclen); tmp[speclen] = '\0'; - if (SplitString(tmp, "/", argc, argv, 32) != NULL + if (SplitString(tmp, "/", argc, argv, 32) != nullptr || argc != 2) - return NULL; // wrong number of parameters + return nullptr; // wrong number of parameters // handle different connection types (currently only TCP/IP support) if (strcasecmp(argv[0], "tcp") == 0) { - if (SplitString(argv[1], ":", argc, argv, 32) != NULL + if (SplitString(argv[1], ":", argc, argv, 32) != nullptr || argc != 2) - return NULL; // wrong number of parameters + return nullptr; // wrong number of parameters int port = atoi(argv[1]); if (port <= 0) - return NULL; + return nullptr; FastOS_Socket *mysocket = new FastOS_Socket(); mysocket->SetAddress(port, argv[0]); FNET_Connection *conn = new FNET_Connection(this, streamer, serverAdapter, @@ -354,10 +355,10 @@ FNET_TransportThread::Connect(const char *spec, FNET_IPacketStreamer *streamer, return conn; } else { delete conn; - return NULL; + return nullptr; } } else { - return NULL; + return nullptr; } } @@ -501,7 +502,7 @@ FNET_TransportThread::InitEventLoop() } _events = new FastOS_IOEvent[EVT_MAX]; - assert(_events != NULL); + assert(_events != nullptr); _now.SetNow(); _startTime = _now; @@ -514,9 +515,9 @@ FNET_TransportThread::InitEventLoop() bool FNET_TransportThread::EventLoopIteration() { - FNET_Packet *packet = NULL; + FNET_Packet *packet = nullptr; FNET_Context context; - FNET_IOComponent *component = NULL; + FNET_IOComponent *component = nullptr; int evt_cnt = 0; FastOS_IOEvent *events = _events; int msTimeout = FNET_Scheduler::SLOT_TICK; @@ -566,7 +567,7 @@ FNET_TransportThread::EventLoopIteration() CountEvent(_queue.FlushPackets_NoLock(&_myQueue)); Unlock(); - while ((packet = _myQueue.DequeuePacket_NoLock(&context)) != NULL) { + while ((packet = _myQueue.DequeuePacket_NoLock(&context)) != nullptr) { if (context._value.IOC->_flags._ioc_delete) { context._value.IOC->SubRef(); @@ -621,7 +622,7 @@ FNET_TransportThread::EventLoopIteration() for (int i = 0; i < evt_cnt; i++) { component = (FNET_IOComponent *) events[i]._eventAttribute; - if (component == NULL || component->_flags._ioc_delete) + if (component == nullptr || component->_flags._ioc_delete) continue; bool rc = true; @@ -642,7 +643,7 @@ FNET_TransportThread::EventLoopIteration() FastOS_Time t = _now; t.SubtractMilliSecs((double)_config._iocTimeOut); fastos::TimeStamp oldest(t); - while (_timeOutHead != NULL && + while (_timeOutHead != nullptr && oldest >= _timeOutHead->_ioc_timestamp) { component = _timeOutHead; @@ -673,7 +674,7 @@ FNET_TransportThread::EventLoopIteration() Unlock(); // discard remaining events - while ((packet = _myQueue.DequeuePacket_NoLock(&context)) != NULL) { + while ((packet = _myQueue.DequeuePacket_NoLock(&context)) != nullptr) { if (packet->GetCommand() == FNET_ControlPacket::FNET_CMD_EXECUTE) { context._value.EXECUTABLE->execute(); } else { @@ -683,7 +684,7 @@ FNET_TransportThread::EventLoopIteration() // close and remove all I/O Components component = _componentsHead; - while (component != NULL) { + while (component != nullptr) { assert(component == _componentsHead); FNET_IOComponent *tmp = component; component = component->_ioc_next; @@ -691,9 +692,9 @@ FNET_TransportThread::EventLoopIteration() tmp->Close(); tmp->SubRef(); } - assert(_componentsHead == NULL && - _componentsTail == NULL && - _timeOutHead == NULL && + assert(_componentsHead == nullptr && + _componentsTail == nullptr && + _timeOutHead == nullptr && _componentCnt == 0 && _queue.IsEmpty_NoLock() && _myQueue.IsEmpty_NoLock()); @@ -715,14 +716,14 @@ FNET_TransportThread::EventLoopIteration() bool FNET_TransportThread::Start(FastOS_ThreadPool *pool) { - return (pool != NULL && pool->NewThread(this)); + return (pool != nullptr && pool->NewThread(this)); } void FNET_TransportThread::Main() { - Run(NULL, NULL); + Run(nullptr, nullptr); } @@ -734,7 +735,7 @@ FNET_TransportThread::Run(FastOS_ThreadInterface *thisThread, void *) return; } while (EventLoopIteration()) { - if (thisThread != NULL && thisThread->GetBreakFlag()) + if (thisThread != nullptr && thisThread->GetBreakFlag()) ShutDown(false); } } diff --git a/fnet/src/vespa/fnet/transport_thread.h b/fnet/src/vespa/fnet/transport_thread.h index 41378111419..0f587a2fc6a 100644 --- a/fnet/src/vespa/fnet/transport_thread.h +++ b/fnet/src/vespa/fnet/transport_thread.h @@ -268,7 +268,7 @@ public: * may supply a hostname as well, like this: * 'tcp/mycomputer.mydomain:8001'. * - * @return the connector object, or NULL if listen failed. + * @return the connector object, or nullptr if listen failed. * @param spec string specifying how and where to listen. * @param streamer custom packet streamer. * @param serverAdapter object for custom channel creation. @@ -303,9 +303,9 @@ public: * @param connContext application context for the connection. **/ FNET_Connection *Connect(const char *spec, FNET_IPacketStreamer *streamer, - FNET_IPacketHandler *adminHandler = NULL, + FNET_IPacketHandler *adminHandler = nullptr, FNET_Context adminContext = FNET_Context(), - FNET_IServerAdapter *serverAdapter = NULL, + FNET_IServerAdapter *serverAdapter = nullptr, FNET_Context connContext = FNET_Context()); |