From 15a4f1001043694f85560fad454171feb8cbf875 Mon Sep 17 00:00:00 2001 From: Katherine Chen Date: Thu, 5 Dec 2024 16:47:22 +1100 Subject: [PATCH] Pass in buf value --- vsock-bridge/include/config.h | 4 ++++ vsock-bridge/include/listener.h | 6 +++++- vsock-bridge/src/config.cpp | 16 ++++++++++++++++ vsock-bridge/src/vsock-bridge.cpp | 9 ++++++--- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/vsock-bridge/include/config.h b/vsock-bridge/include/config.h index a8cd0e3..2784435 100644 --- a/vsock-bridge/include/config.h +++ b/vsock-bridge/include/config.h @@ -32,6 +32,10 @@ namespace vsockproxy ServiceType _type = ServiceType::UNKNOWN; EndpointConfig _listenEndpoint; EndpointConfig _connectEndpoint; + int _acceptRcvBuf; + int _acceptSndBuf; + int _peerRcvBuf; + int _peerSndBuf; }; std::vector loadConfig(const std::string& filepath); diff --git a/vsock-bridge/include/listener.h b/vsock-bridge/include/listener.h index c4c39c8..8451351 100644 --- a/vsock-bridge/include/listener.h +++ b/vsock-bridge/include/listener.h @@ -70,8 +70,12 @@ namespace vsockio const int MAX_POLLER_EVENTS = 256; const int SO_BACKLOG = 64; - Listener(std::unique_ptr&& listenEndpoint, std::unique_ptr&& connectEndpoint, Dispatcher& dispatcher) + Listener(std::unique_ptr&& listenEndpoint, std::unique_ptr&& connectEndpoint, Dispatcher& dispatcher, int acceptRcvBuf, int acceptSndBuf, int peerRcvBuf, int peerSndBuf) : _fd(-1) + , _acceptRcvBuf(acceptRcvBuf) + , _acceptSndBuf(acceptSndBuf) + , _peerRcvBuf(peerRcvBuf) + , _peerSndBuf(peerSndBuf) , _listenEp(std::move(listenEndpoint)) , _connectEp(std::move(connectEndpoint)) , _events(new VsbEvent[MAX_POLLER_EVENTS]) diff --git a/vsock-bridge/src/config.cpp b/vsock-bridge/src/config.cpp index eaa4693..791e57d 100644 --- a/vsock-bridge/src/config.cpp +++ b/vsock-bridge/src/config.cpp @@ -251,6 +251,22 @@ namespace vsockproxy } cs._connectEndpoint = *endpoint; } + else if (line._key == "acceptRcvBuf") + { + cs._acceptRcvBuf = std::stoi(line._value); + } + else if (line._key == "acceptSndBuf") + { + cs._acceptSndBuf = std::stoi(line._value); + } + else if (line._key == "peerRcvBuf") + { + cs._peerRcvBuf = std::stoi(line._value); + } + else if (line._key == "peerSndBuf") + { + cs._peerSndBuf = std::stoi(line._value); + } } } } diff --git a/vsock-bridge/src/vsock-bridge.cpp b/vsock-bridge/src/vsock-bridge.cpp index ed7cd6d..eff9229 100644 --- a/vsock-bridge/src/vsock-bridge.cpp +++ b/vsock-bridge/src/vsock-bridge.cpp @@ -27,7 +27,7 @@ static std::unique_ptr createEndpoint(EndpointScheme scheme, const std } } -static std::unique_ptr createListener(Dispatcher& dispatcher, EndpointScheme inScheme, const std::string& inAddress, uint16_t inPort, EndpointScheme outScheme, const std::string& outAddress, uint16_t outPort) +static std::unique_ptr createListener(Dispatcher& dispatcher, EndpointScheme inScheme, const std::string& inAddress, uint16_t inPort, EndpointScheme outScheme, const std::string& outAddress, uint16_t outPort, int acceptRcvBuf, int acceptSndBuf, int peerRcvBuf, int peerSndBuf) { auto listenEp { createEndpoint(inScheme, inAddress, inPort) }; auto connectEp{ createEndpoint(outScheme, outAddress, outPort) }; @@ -44,7 +44,7 @@ static std::unique_ptr createListener(Dispatcher& dispatcher, Endpoint } else { - return std::make_unique(std::move(listenEp), std::move(connectEp), dispatcher); + return std::make_unique(std::move(listenEp), std::move(connectEp), dispatcher, acceptRcvBuf, acceptSndBuf, peerRcvBuf, peerSndBuf); } } @@ -68,7 +68,10 @@ static void startServices(const std::vector& services, int n /*inPort:*/ sd._listenEndpoint._port, /*outScheme:*/ sd._connectEndpoint._scheme, /*outAddress:*/ sd._connectEndpoint._address, - /*outPort:*/ sd._connectEndpoint._port + _acceptRcvBuf, + _acceptSndBuf, + _peerRcvBuf, + _peerSndBuf, ); if (!listener)