aboutsummaryrefslogtreecommitdiffstats
path: root/fnet
diff options
context:
space:
mode:
authorHaavard <havardpe@yahoo-inc.com>2017-04-24 15:16:34 +0000
committerHaavard <havardpe@yahoo-inc.com>2017-04-24 15:16:34 +0000
commited6f24b7ef640108db13abb5b687912f3c7bcdcf (patch)
tree30287c87dc90ecac96186043aa12f53e68af34e7 /fnet
parent33f343a2303af39a0945964947bf421f37bd7ff7 (diff)
remove fdselector from fnet (not used)
Diffstat (limited to 'fnet')
-rw-r--r--fnet/CMakeLists.txt1
-rw-r--r--fnet/src/tests/fdselector/.gitignore4
-rw-r--r--fnet/src/tests/fdselector/CMakeLists.txt8
-rw-r--r--fnet/src/tests/fdselector/DESC1
-rw-r--r--fnet/src/tests/fdselector/FILES1
-rw-r--r--fnet/src/tests/fdselector/fdselector.cpp220
-rw-r--r--fnet/src/vespa/fnet/CMakeLists.txt1
-rw-r--r--fnet/src/vespa/fnet/fdselector.cpp102
-rw-r--r--fnet/src/vespa/fnet/fdselector.h221
-rw-r--r--fnet/src/vespa/fnet/fnet.h2
10 files changed, 0 insertions, 561 deletions
diff --git a/fnet/CMakeLists.txt b/fnet/CMakeLists.txt
index cc18e276a32..3136c8654e9 100644
--- a/fnet/CMakeLists.txt
+++ b/fnet/CMakeLists.txt
@@ -17,7 +17,6 @@ vespa_define_module(
src/tests/connection_spread
src/tests/databuffer
src/tests/examples
- src/tests/fdselector
src/tests/frt/method_pt
src/tests/frt/parallel_rpc
src/tests/frt/rpc
diff --git a/fnet/src/tests/fdselector/.gitignore b/fnet/src/tests/fdselector/.gitignore
deleted file mode 100644
index 68a9dea5652..00000000000
--- a/fnet/src/tests/fdselector/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-.depend
-Makefile
-fdselector_test
-fnet_fdselector_test_app
diff --git a/fnet/src/tests/fdselector/CMakeLists.txt b/fnet/src/tests/fdselector/CMakeLists.txt
deleted file mode 100644
index 578d2f4a10e..00000000000
--- a/fnet/src/tests/fdselector/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(fnet_fdselector_test_app TEST
- SOURCES
- fdselector.cpp
- DEPENDS
- fnet
-)
-vespa_add_test(NAME fnet_fdselector_test_app COMMAND fnet_fdselector_test_app)
diff --git a/fnet/src/tests/fdselector/DESC b/fnet/src/tests/fdselector/DESC
deleted file mode 100644
index 050e2a746d1..00000000000
--- a/fnet/src/tests/fdselector/DESC
+++ /dev/null
@@ -1 +0,0 @@
-Test selecting on external file descriptors in the FNET event loop.
diff --git a/fnet/src/tests/fdselector/FILES b/fnet/src/tests/fdselector/FILES
deleted file mode 100644
index d03840ead52..00000000000
--- a/fnet/src/tests/fdselector/FILES
+++ /dev/null
@@ -1 +0,0 @@
-fdselector.cpp
diff --git a/fnet/src/tests/fdselector/fdselector.cpp b/fnet/src/tests/fdselector/fdselector.cpp
deleted file mode 100644
index 0097334a9ce..00000000000
--- a/fnet/src/tests/fdselector/fdselector.cpp
+++ /dev/null
@@ -1,220 +0,0 @@
-// 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/fnet.h>
-
-
-struct Handler : public FNET_IFDSelectorHandler
-{
- int readEventCnt[2];
- int writeEventCnt[2];
-
- Handler()
- : readEventCnt(),
- writeEventCnt()
- {
- reset();
- }
- void readEvent(FNET_FDSelector *src) override
- {
- readEventCnt[src->getContext()._value.INT]++;
- }
- void writeEvent(FNET_FDSelector *src) override
- {
- writeEventCnt[src->getContext()._value.INT]++;
- }
- bool empty()
- {
- return ( readEventCnt[0] == 0
- && readEventCnt[1] == 0
- && writeEventCnt[0] == 0
- && writeEventCnt[1] == 0);
- }
- void reset()
- {
- readEventCnt[0] = 0;
- readEventCnt[1] = 0;
- writeEventCnt[0] = 0;
- writeEventCnt[1] = 0;
- }
-};
-
-
-struct State
-{
- int pipefd[2];
- FNET_Transport transport;
- Handler handler;
-
- void eventLoop(int cnt)
- {
- for (int i = 0; i < cnt; ++i) {
- transport.EventLoopIteration();
- }
- }
- bool checkEmpty()
- {
- eventLoop(1);
- return handler.empty();
- }
- void shutDown()
- {
- transport.ShutDown(false);
- for (;;) {
- if (!transport.EventLoopIteration()) {
- return;
- }
- }
- }
- State() : pipefd(), transport(), handler() {
- pipefd[0] = -1;
- pipefd[1] = -1;
- ASSERT_TRUE(pipe(pipefd) == 0);
- ASSERT_TRUE(transport.InitEventLoop());
- ASSERT_TRUE(handler.empty());
- }
- ~State() {
- shutDown();
- }
-};
-
-
-struct Selector : public FNET_FDSelector
-{
- static FastOS_Mutex mutex;
- static int ctorCnt;
- static int dtorCnt;
-
- Selector(State &state, uint32_t idx)
- : FNET_FDSelector(&state.transport, state.pipefd[idx],
- &state.handler, FNET_Context(idx))
- {
- mutex.Lock();
- ctorCnt++;
- mutex.Unlock();
- }
- ~Selector()
- {
- mutex.Lock();
- dtorCnt++;
- mutex.Unlock();
- }
-};
-
-FastOS_Mutex Selector::mutex;
-int Selector::ctorCnt = 0;
-int Selector::dtorCnt = 0;
-
-
-TEST_F("testEmptySelection", State()) {
- State &state = f1;
- Selector *sel_0 = new Selector(state, 0);
- Selector *sel_1 = new Selector(state, 1);
-
- state.eventLoop(5);
- EXPECT_TRUE(state.handler.empty());
-
- sel_0->dispose();
- sel_1->dispose();
-}
-
-
-TEST_F("testWriteEvent", State()) {
- State &state = f1;
- Selector *sel = new Selector(state, 1);
-
- sel->updateWriteSelection(true);
- state.eventLoop(10);
- EXPECT_TRUE(state.handler.writeEventCnt[1] > 7);
- state.handler.writeEventCnt[1] = 0;
- EXPECT_TRUE(state.handler.empty());
-
- sel->dispose();
- EXPECT_TRUE(state.checkEmpty());
-}
-
-
-TEST_F("testReadEvent", State()) {
- State &state = f1;
- char buf[16];
- char buf2[16];
- strcpy(buf, "test");
- strcpy(buf2, "bogus");
-
- Selector *sel = new Selector(state, 0);
-
- sel->updateReadSelection(true);
- EXPECT_TRUE(state.checkEmpty());
- EXPECT_TRUE(state.checkEmpty());
- EXPECT_TRUE(state.checkEmpty());
-
- int res = write(state.pipefd[1], buf, 5);
- EXPECT_TRUE(res == 5);
-
- state.eventLoop(10);
- EXPECT_TRUE(state.handler.readEventCnt[0] > 7);
- state.handler.readEventCnt[0] = 0;
- EXPECT_TRUE(state.handler.empty());
-
- res = read(state.pipefd[0], buf2, 10);
- EXPECT_TRUE(res == 5);
- EXPECT_TRUE(strcmp(buf, buf2) == 0);
-
- state.eventLoop(10);
- EXPECT_TRUE(state.handler.readEventCnt[0] < 4);
- state.handler.readEventCnt[0] = 0;
- EXPECT_TRUE(state.handler.empty());
-
- sel->dispose();
- EXPECT_TRUE(state.checkEmpty());
-}
-
-
-TEST_F("testDispose", State()) {
- State &state = f1;
- Selector *sel = new Selector(state, 1);
-
- sel->updateWriteSelection(true);
- state.eventLoop(10);
- EXPECT_TRUE(state.handler.writeEventCnt[1] > 7);
- state.handler.writeEventCnt[1] = 0;
- EXPECT_TRUE(state.handler.empty());
-
- sel->dispose();
- EXPECT_TRUE(state.checkEmpty());
-}
-
-
-TEST_F("testToggleEvent", State()) {
- State &state = f1;
- Selector *sel = new Selector(state, 1);
-
- sel->updateWriteSelection(true);
- state.eventLoop(10);
- EXPECT_TRUE(state.handler.writeEventCnt[1] > 7);
- state.handler.writeEventCnt[1] = 0;
- EXPECT_TRUE(state.handler.empty());
-
- sel->updateWriteSelection(false);
- state.eventLoop(10);
- EXPECT_TRUE(state.handler.writeEventCnt[1] < 4);
- state.handler.writeEventCnt[1] = 0;
- EXPECT_TRUE(state.handler.empty());
-
- sel->updateWriteSelection(true);
- state.eventLoop(10);
- EXPECT_TRUE(state.handler.writeEventCnt[1] > 7);
- state.handler.writeEventCnt[1] = 0;
- EXPECT_TRUE(state.handler.empty());
-
- sel->dispose();
- EXPECT_TRUE(state.checkEmpty());
-}
-
-TEST_MAIN() {
- ASSERT_TRUE(Selector::ctorCnt == 0);
- ASSERT_TRUE(Selector::dtorCnt == 0);
- TEST_RUN_ALL();
- EXPECT_TRUE(Selector::ctorCnt > 0);
- EXPECT_TRUE(Selector::dtorCnt > 0);
- EXPECT_TRUE(Selector::ctorCnt == Selector::dtorCnt);
-}
diff --git a/fnet/src/vespa/fnet/CMakeLists.txt b/fnet/src/vespa/fnet/CMakeLists.txt
index befe0f4ffa2..9d496d63b4d 100644
--- a/fnet/src/vespa/fnet/CMakeLists.txt
+++ b/fnet/src/vespa/fnet/CMakeLists.txt
@@ -10,7 +10,6 @@ vespa_add_library(fnet
controlpacket.cpp
databuffer.cpp
dummypacket.cpp
- fdselector.cpp
info.cpp
iocomponent.cpp
packet.cpp
diff --git a/fnet/src/vespa/fnet/fdselector.cpp b/fnet/src/vespa/fnet/fdselector.cpp
deleted file mode 100644
index d13f1d3c844..00000000000
--- a/fnet/src/vespa/fnet/fdselector.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "fdselector.h"
-#include "transport.h"
-#include "transport_thread.h"
-
-FNET_FDSelector::FNET_FDSelector(FNET_Transport *transport, int fd,
- FNET_IFDSelectorHandler *handler,
- FNET_Context context)
- : FNET_IOComponent(transport->select_thread(&fd, sizeof(fd)), &_fdSocket, FDSpec(fd).spec(), false),
- _fd(fd),
- _fdSocket(fd),
- _handler(handler),
- _context(context),
- _eventBusy(false),
- _eventWait(false)
-{
- AddRef_NoLock();
- Owner()->Add(this, false);
-}
-
-
-void
-FNET_FDSelector::updateReadSelection(bool wantRead)
-{
- if (wantRead) {
- Owner()->EnableRead(this);
- } else {
- Owner()->DisableRead(this);
- }
-}
-
-
-void
-FNET_FDSelector::updateWriteSelection(bool wantWrite)
-{
- if (wantWrite) {
- Owner()->EnableWrite(this);
- } else {
- Owner()->DisableWrite(this);
- }
-}
-
-
-void
-FNET_FDSelector::dispose()
-{
- Lock();
- waitEvent();
- _handler = nullptr;
- Unlock();
- Owner()->Close(this, false);
-}
-
-
-FNET_FDSelector::~FNET_FDSelector()
-{
- assert(_fdSocket.GetSocketEvent() == nullptr);
-}
-
-
-void
-FNET_FDSelector::Close()
-{
- SetSocketEvent(nullptr);
-}
-
-
-bool
-FNET_FDSelector::HandleReadEvent()
-{
- if (!_flags._ioc_readEnabled) {
- return true;
- }
- Lock();
- FNET_IFDSelectorHandler *handler = _handler;
- beforeEvent();
- if (handler != nullptr) {
- handler->readEvent(this);
- }
- afterEvent();
- Unlock();
- return true;
-}
-
-
-bool
-FNET_FDSelector::HandleWriteEvent()
-{
- if (!_flags._ioc_writeEnabled) {
- return true;
- }
- Lock();
- FNET_IFDSelectorHandler *handler = _handler;
- beforeEvent();
- if (handler != nullptr) {
- handler->writeEvent(this);
- }
- afterEvent();
- Unlock();
- return true;
-}
diff --git a/fnet/src/vespa/fnet/fdselector.h b/fnet/src/vespa/fnet/fdselector.h
deleted file mode 100644
index 7dee084fae4..00000000000
--- a/fnet/src/vespa/fnet/fdselector.h
+++ /dev/null
@@ -1,221 +0,0 @@
-// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#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
- * component.
- **/
-class FNET_IFDSelectorHandler
-{
-public:
- /**
- * This method is called by the transport thread when a read is
- * possible on the underlying filedescriptor of the given
- * selector.
- *
- * @param source the source of this event
- **/
- virtual void readEvent(FNET_FDSelector *source) = 0;
-
- /**
- * This method is called by the transport thread when a write is
- * possible on the underlying filedescriptor of the given
- * selector.
- *
- * @param source the source of this event
- **/
- virtual void writeEvent(FNET_FDSelector *source) = 0;
-
-protected:
- /**
- * Empty. Implemented just to keep gcc happy. Protected to avoid
- * destruction through interface pointer.
- **/
- virtual ~FNET_IFDSelectorHandler() {}
-};
-
-
-/**
- * This is an adapter class used to wait for read/write events on a
- * generic file descriptor. The file descriptor is owned by the
- * application, and no other operations than checking for read/write
- * availability will be performed on it. Objects of this class will be
- * hooked into the io component framework of FNET, and will therefore
- * have a lifetime controlled by reference counting. The way to use
- * this class is to pair it up with the @ref FNET_IFDSelectorHandler
- * interface. Let an object in the application inherit from the
- * selector handler interface. Create an fd selector using the
- * application handler. Appropriate events will be delivered to the
- * selector handler. When no more events are wanted, use the @ref
- * dispose method to get rid of the selector.
- **/
-class FNET_FDSelector : public FNET_IOComponent
-{
- FNET_FDSelector(const FNET_FDSelector&); // not used
- FNET_FDSelector& operator= (const FNET_FDSelector&); // not used
-public:
-#ifndef IAM_DOXYGEN
- class FDSpec
- {
- private:
- char _buf[64];
- public:
- FDSpec(int fd) : _buf() { sprintf(_buf, "fd/%d", fd); }
- const char *spec() const { return _buf; }
- };
-
- class FDSocket : public FastOS_Socket
- {
- public:
- FDSocket(int fd) : FastOS_Socket() { _socketHandle = fd; }
- bool valid() const { return _socketHandle != -1; }
- ~FDSocket() { _socketHandle = -1; }
- };
-#endif // DOXYGEN
-
-private:
- int _fd;
- FDSocket _fdSocket;
- FNET_IFDSelectorHandler *_handler;
- FNET_Context _context;
- bool _eventBusy;
- bool _eventWait;
-
- /**
- * If an event is being delivered, wait until that event is
- * delivered.
- **/
- void waitEvent()
- {
- while (_eventBusy) {
- _eventWait = true;
- Wait();
- }
- }
-
- /**
- * Called directly before an event is delivered to synchronize
- * with the @ref waitEvent method.
- **/
- void beforeEvent()
- {
- _eventBusy = true;
- Unlock();
- }
-
- /**
- * Called directly after an event is delivered to synchronize with
- * the @ref waitEvent method.
- **/
- void afterEvent()
- {
- Lock();
- _eventBusy = false;
- if (_eventWait) {
- _eventWait = false;
- Broadcast();
- }
- }
-
-public:
- /**
- * Construct a file descriptor selector. The created selector is
- * automatically added to one of the event loops controlled by the
- * transport object.
- *
- * @param transport the transport layer
- * @param fd the underlying file descriptor
- * @param handler the handler for this selector
- * @param context the application context for this selector
- **/
- FNET_FDSelector(FNET_Transport *transport, int fd,
- FNET_IFDSelectorHandler *handler,
- FNET_Context context = FNET_Context());
-
- /**
- * Obtain the file descriptor associated with this selector.
- *
- * @return file descriptor
- **/
- int getFD() { return _fd; }
-
- /**
- * Obtain the application context for this selector.
- *
- * @return the application context for this selector
- **/
- FNET_Context getContext() { return _context; }
-
- /**
- * Enable/disable read events. This method only acts as a proxy
- * that will notify the transport loop about the new selection.
- * When a selection is changed it may not take effect right away
- * (events already in the pipeline will still be delivered). This
- * means that the application must be able to handle events that
- * are delivered after events have been disabled.
- *
- * @param wantRead true if we want read events.
- **/
- void updateReadSelection(bool wantRead);
-
- /**
- * Enable/disable write events. This method only acts as a proxy
- * that will notify the transport loop about the new selection.
- * When a selection is changed it may not take effect right away
- * (events already in the pipeline will still be delivered). This
- * means that the application must be able to handle events that
- * are delivered after events have been disabled.
- *
- * @param wantWrite true if we want write events.
- **/
- void updateWriteSelection(bool wantWrite);
-
- /**
- * This method is used to dispose of this selector. If an event
- * callback is in progress when this method is called, it will
- * block until that callback is finished. This ensures that no
- * more events will be delivered from this selector after this
- * method has returned. This method also acts as an implicit
- * SubRef, invalidating the application pointer to this
- * object. Note: calling this method from either of the event
- * delivery methods in the selector handler interface will result
- * in a deadlock, since the calling thread will be waiting for
- * itself to complete the callback.
- **/
- void dispose();
-
-protected:
- /**
- * Destructor. Should not be invoked from the application. Use the
- * @ref dispose method to get rid of selector objects.
- **/
- ~FNET_FDSelector();
-
- /**
- * This method is called from the transport thread to close this
- * io component. This method performs internal cleanup related to
- * the io component framework used in FNET.
- **/
- void Close() override;
-
- /**
- * This method is called by the transport thread when the
- * underlying file descriptor is ready for reading.
- **/
- bool HandleReadEvent() override;
-
- /**
- * This method is called by the transport layer when the
- * underlying file descriptor is ready for writing.
- **/
- bool HandleWriteEvent() override;
-};
-
diff --git a/fnet/src/vespa/fnet/fnet.h b/fnet/src/vespa/fnet/fnet.h
index ee3021bf67f..864bc831344 100644
--- a/fnet/src/vespa/fnet/fnet.h
+++ b/fnet/src/vespa/fnet/fnet.h
@@ -28,7 +28,6 @@ class FNET_Context;
class FNET_ControlPacket;
class FNET_DataBuffer;
class FNET_DummyPacket;
-class FNET_FDSelector;
class FNET_Info;
class FNET_IOComponent;
class FNET_Packet;
@@ -69,7 +68,6 @@ class FNET_TransportThread;
#include "transport.h"
#include "connection.h"
#include "connector.h"
-#include "fdselector.h"
#include "info.h"
#include "signalshutdown.h"