Skip to content

Commit

Permalink
chore: make LocalPortForwarder use non-blocking sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Nov 17, 2024
1 parent 7a982c1 commit 5e590da
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 96 deletions.
44 changes: 39 additions & 5 deletions WebTunnel/include/Poco/WebTunnel/LocalPortForwarder.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,35 @@ class WebTunnel_API LocalPortForwarder
Poco::Timespan getRemoteTimeout() const;
/// Returns the timeout for the remote WebSocket connection.

void setCloseTimeout(Poco::Timespan timeout);
/// Sets the timeout for closing a connection.

Poco::Timespan getCloseTimeout() const;
/// Returns the timeout for closing a connection.

enum ConnectionFlags
{
CF_CLOSED_LOCAL = 0x01,
CF_CLOSED_REMOTE = 0x02,
CF_ERROR = 0x04
};

struct ConnectionPair
{
ConnectionPair(const Poco::Net::WebSocket& ws, const Poco::Net::StreamSocket ss, Poco::Timespan ts):
webSocket(ws),
streamSocket(ss),
closeTimeout(ts)
{
}

Poco::Net::WebSocket webSocket;
int webSocketFlags = 0;
Poco::Net::StreamSocket streamSocket;
int streamSocketFlags = 0;
Poco::Timespan closeTimeout;
};

protected:
void forward(Poco::Net::StreamSocket& socket);

Expand All @@ -155,17 +184,16 @@ class WebTunnel_API LocalPortForwarder
Poco::URI _remoteURI;
Poco::Timespan _localTimeout;
Poco::Timespan _remoteTimeout;
int _timeoutCount;
Poco::Timespan _closeTimeout;
WebSocketFactory::Ptr _pWebSocketFactory;
Poco::Net::ServerSocket _serverSocket;
Poco::Net::TCPServer _tcpServer;
Poco::SharedPtr<SocketDispatcher> _pDispatcher;
Poco::FastMutex _webSocketMutex;
Poco::Logger& _logger;

LocalPortForwarder();
LocalPortForwarder(const LocalPortForwarder&);
LocalPortForwarder& operator = (const LocalPortForwarder&);
LocalPortForwarder() = delete;
LocalPortForwarder(const LocalPortForwarder&) = delete;
LocalPortForwarder& operator = (const LocalPortForwarder&) = delete;

static const std::string SEC_WEBSOCKET_PROTOCOL;
static const std::string X_WEBTUNNEL_REMOTEPORT;
Expand Down Expand Up @@ -208,6 +236,12 @@ inline Poco::Timespan LocalPortForwarder::getRemoteTimeout() const
}


inline Poco::Timespan LocalPortForwarder::getCloseTimeout() const
{
return _closeTimeout;
}


} } // namespace Poco::WebTunnel


Expand Down
6 changes: 3 additions & 3 deletions WebTunnel/include/Poco/WebTunnel/RemotePortForwarder.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ class WebTunnel_API RemotePortForwarder
mutable Poco::FastMutex _mutex;
Poco::Logger& _logger;

RemotePortForwarder();
RemotePortForwarder(const RemotePortForwarder&);
RemotePortForwarder& operator = (const RemotePortForwarder&);
RemotePortForwarder() = delete;
RemotePortForwarder(const RemotePortForwarder&) = delete;
RemotePortForwarder& operator = (const RemotePortForwarder&) = delete;

friend class TunnelMultiplexer;
friend class TunnelDemultiplexer;
Expand Down
Loading

0 comments on commit 5e590da

Please sign in to comment.