Poco SocketReactors for a Proxy Server

Posted by Genesis on Stack Overflow See other posts from Stack Overflow or by Genesis
Published on 2010-05-18T06:56:47Z Indexed on 2010/05/18 7:01 UTC
Read the original article Hit count: 600

Filed under:
|
|

Can anyone give me some idea of the best way to implement a non-blocking proxy server using a Poco Socket Reactor?

Currently I have a blocking implementation where if a readable notification arrives from the client I am writing what is read directly to the server, and if a readable notification arrives from the server I am writing what is read directly to the client. To achieve this I keep the thread that initiated the server connection alive but I would prefer to switch to non-blocking and have any threads which are used to initiate a connection removed once the server and client sockets are registered with the reactor and the SOCKS5 handshake is over.

With a SocketReactor one can register event handlers for a single socket but the trouble is I would need to store whatever is read from that socket in a global buffer until the corresponding server socket is ready to be written to as from my testing I dont seem to be able to just write directly to the server when client data arrives. I am thinking of using a struct that contains the client socket, server socket, client buffer and server buffer and whenever a writable notification comes along for either the client or server, finding the corresponding buffer and writing this.

Any thoughts?

© Stack Overflow or respective owner

Related posts about c++

Related posts about POCO