A generic state machine that connects two virtual conections. More...
#include <I_OneWayTunnel.h>
Inherits Continuation.
Inherited by OneWayMultiTunnel.
Public Member Functions | |
OneWayTunnel () | |
virtual | ~OneWayTunnel () |
void | init (VConnection *vcSource, VConnection *vcTarget, Continuation *aCont=NULL, int size_estimate=0, ProxyMutex *aMutex=NULL, int64_t nbytes=TUNNEL_TILL_DONE, bool asingle_buffer=true, bool aclose_source=true, bool aclose_target=true, Transform_fn manipulate_fn=NULL, int water_mark=0) |
This init function sets up the read (calls do_io_read) and the write (calls do_io_write). | |
void | init (VConnection *vcSource, VConnection *vcTarget, Continuation *aCont, VIO *SourceVio, IOBufferReader *reader, bool aclose_source=true, bool aclose_target=true) |
This init function sets up only the write side. | |
void | init (Continuation *aCont, VIO *SourceVio, VIO *TargetVio, bool aclose_source=true, bool aclose_target=true) |
Use this init function if both the read and the write sides have already been setup. | |
OneWayTunnel (Continuation *aCont, Transform_fn manipulate_fn=NULL, bool aclose_source=false, bool aclose_target=false) | |
int | startEvent (int event, void *data) |
virtual void | transform (MIOBufferAccessor &in_buf, MIOBufferAccessor &out_buf) |
void | close_source_vio (int result) |
Result is -1 for any error. | |
virtual void | close_target_vio (int result, VIO *vio=ONE_WAY_TUNNEL_CLOSE_ALL) |
void | connection_closed (int result) |
virtual void | reenable_all () |
bool | last_connection () |
Static Public Member Functions | |
static OneWayTunnel * | OneWayTunnel_alloc () |
Allocates a OneWayTunnel object. | |
static void | OneWayTunnel_free (OneWayTunnel *) |
Deallocates a OneWayTunnel object. | |
static void | SetupTwoWayTunnel (OneWayTunnel *east, OneWayTunnel *west) |
Data Fields | |
VIO * | vioSource |
VIO * | vioTarget |
Continuation * | cont |
Transform_fn | manipulate_fn |
int | n_connections |
int | lerrno |
bool | single_buffer |
bool | close_source |
bool | close_target |
bool | tunnel_till_done |
OneWayTunnel * | tunnel_peer |
Non-NULL when this is one side of a two way tunnel. | |
bool | free_vcs |
A generic state machine that connects two virtual conections.
A OneWayTunnel is a module that connects two virtual connections, a source vc and a target vc, and copies the data between source and target. Once the tunnel is started using the init() call, it handles all the events from the source and target and optionally calls a continuation back when its done. On success it calls back the continuation with VC_EVENT_EOS, and with VC_EVENT_ERROR on failure.
If manipulate_fn is not NULL, then the tunnel acts as a filter, processing all data arriving from the source vc by the manipulate_fn function, before sending to the target vc. By default, the manipulate_fn is set to NULL, yielding the identity function. manipulate_fn takes a IOBuffer containing the data to be written into the target virtual connection which it may manipulate in any manner it sees fit.
Definition at line 65 of file I_OneWayTunnel.h.
OneWayTunnel::OneWayTunnel | ( | ) |
Definition at line 65 of file OneWayTunnel.cc.
OneWayTunnel::~OneWayTunnel | ( | ) | [virtual] |
Definition at line 96 of file OneWayTunnel.cc.
OneWayTunnel::OneWayTunnel | ( | Continuation * | aCont, | |
Transform_fn | manipulate_fn = NULL , |
|||
bool | aclose_source = false , |
|||
bool | aclose_target = false | |||
) |
Definition at line 100 of file OneWayTunnel.cc.
References ink_assert.
void OneWayTunnel::close_source_vio | ( | int | result | ) |
Result is -1 for any error.
Definition at line 325 of file OneWayTunnel.cc.
References VIO::buffer, MIOBufferAccessor::clear(), close_source, VConnection::do_io_close(), free_MIOBuffer(), free_vcs, last_connection(), lerrno, n_connections, single_buffer, VIO::vc_server, vioSource, and MIOBufferAccessor::writer().
Referenced by startEvent(), and OneWayMultiTunnel::startEvent().
void OneWayTunnel::close_target_vio | ( | int | result, | |
VIO * | vio = ONE_WAY_TUNNEL_CLOSE_ALL | |||
) | [virtual] |
Reimplemented in OneWayMultiTunnel.
Definition at line 342 of file OneWayTunnel.cc.
References VIO::buffer, MIOBufferAccessor::clear(), close_target, VConnection::do_io_close(), free_MIOBuffer(), free_vcs, last_connection(), lerrno, n_connections, single_buffer, VIO::vc_server, vioTarget, and MIOBufferAccessor::writer().
Referenced by startEvent().
void OneWayTunnel::connection_closed | ( | int | result | ) |
Definition at line 365 of file OneWayTunnel.cc.
References cont, Continuation::handleEvent(), OneWayTunnel_free(), VC_EVENT_EOS, and VC_EVENT_ERROR.
Referenced by startEvent(), and OneWayMultiTunnel::startEvent().
void OneWayTunnel::init | ( | VConnection * | vcSource, | |
VConnection * | vcTarget, | |||
Continuation * | aCont, | |||
VIO * | SourceVio, | |||
IOBufferReader * | reader, | |||
bool | aclose_source = true , |
|||
bool | aclose_target = true | |||
) |
This init function sets up only the write side.
It assumes that the read VConnection has already been setup.
vcSource | source VConnection. Prior to calling this init function, a do_io_read should have been called on this VConnection. The tunnel uses the same MIOBuffer and frees that buffer when the transfer is done (either successful or unsuccessful). | |
vcTarget | target VConnection. A do_io_write should not have been called on the vcTarget. The tunnel calls do_io_write on this VC. | |
aCont | The Continuation to call back when the tunnel finishes. If not specified, the tunnel deallocates itself without calling back anybody. | |
SourceVio | VIO of the vcSource. | |
reader | IOBufferReader that reads from the vcSource. This reader is provided to vcTarget. | |
aclose_source | if true, the tunnel closes vcSource at the end. If aCont is not specified, this should be set to true. | |
aclose_target | if true, the tunnel closes vcTarget at the end. If aCont is not specified, this should be set to true. |
Definition at line 164 of file OneWayTunnel.cc.
References close_source, close_target, cont, VConnection::do_io_write(), ink_assert, manipulate_fn, Continuation::mutex, MUTEX_LOCK, n_connections, new_ProxyMutex(), VIO::set_continuation(), SET_HANDLER, single_buffer, startEvent(), this_ethread(), TUNNEL_TILL_DONE, tunnel_till_done, vioSource, and vioTarget.
void OneWayTunnel::init | ( | VConnection * | vcSource, | |
VConnection * | vcTarget, | |||
Continuation * | aCont = NULL , |
|||
int | size_estimate = 0 , |
|||
ProxyMutex * | aMutex = NULL , |
|||
int64_t | nbytes = TUNNEL_TILL_DONE , |
|||
bool | asingle_buffer = true , |
|||
bool | aclose_source = true , |
|||
bool | aclose_target = true , |
|||
Transform_fn | manipulate_fn = NULL , |
|||
int | water_mark = 0 | |||
) |
This init function sets up the read (calls do_io_read) and the write (calls do_io_write).
vcSource | source VConnection. A do_io_read should not have been called on the vcSource. The tunnel calls do_io_read on this VC. | |
vcTarget | target VConnection. A do_io_write should not have been called on the vcTarget. The tunnel calls do_io_write on this VC. | |
aCont | continuation to call back when the tunnel finishes. If not specified, the tunnel deallocates itself without calling back anybody. Otherwise, its the callee's responsibility to deallocate the tunnel with OneWayTunnel_free. | |
size_estimate | size of the MIOBuffer to create for reading/writing to/from the VC's. | |
aMutex | lock that this tunnel will run under. If aCont is specified, the Continuation's lock is used instead of aMutex. | |
nbytes | number of bytes to transfer. | |
asingle_buffer | whether the same buffer should be used to read from vcSource and write to vcTarget. This should be set to true in most cases, unless the data needs be transformed. | |
aclose_source | if true, the tunnel closes vcSource at the end. If aCont is not specified, this should be set to true. | |
aclose_target | if true, the tunnel closes vcTarget at the end. If aCont is not specified, this should be set to true. | |
manipulate_fn | if specified, the tunnel calls this function with the input and the output buffer, whenever it gets new data in the input buffer. This function can transform the data in the input buffer | |
water_mark | watermark for the MIOBuffer used for reading. |
Definition at line 115 of file OneWayTunnel.cc.
References MIOBuffer::alloc_reader(), buffer_size_to_index(), close_source, close_target, cont, Debug, default_large_iobuffer_size, VConnection::do_io_read(), VConnection::do_io_write(), ink_assert, lerrno, manipulate_fn, Continuation::mutex, MUTEX_LOCK, n_connections, new_MIOBuffer, new_ProxyMutex(), SET_HANDLER, single_buffer, startEvent(), this_ethread(), tunnel_till_done, vioSource, vioTarget, and MIOBuffer::water_mark.
Referenced by SocksProxy::mainEvent(), CacheContinuation::replyOpEvent(), and CacheContinuation::setupReadBufTunnel().
void OneWayTunnel::init | ( | Continuation * | aCont, | |
VIO * | SourceVio, | |||
VIO * | TargetVio, | |||
bool | aclose_source = true , |
|||
bool | aclose_target = true | |||
) |
Use this init function if both the read and the write sides have already been setup.
The tunnel assumes that the read VC and the write VC are using the same buffer and frees that buffer when the transfer is done (either successful or unsuccessful)
aCont | The Continuation to call back when the tunnel finishes. If not specified, the tunnel deallocates itself without calling back anybody. | |
SourceVio | read VIO of the Source VC. | |
TargetVio | write VIO of the Target VC. | |
aclose_source | if true, the tunnel closes vcSource at the end. If aCont is not specified, this should be set to true. | |
aclose_target | if true, the tunnel closes vcTarget at the end. If aCont is not specified, this should be set to true. |
Definition at line 194 of file OneWayTunnel.cc.
References close_source, close_target, cont, ink_assert, manipulate_fn, Continuation::mutex, n_connections, new_ProxyMutex(), VIO::set_continuation(), SET_HANDLER, single_buffer, startEvent(), tunnel_till_done, vioSource, and vioTarget.
bool OneWayTunnel::last_connection | ( | ) |
Definition at line 387 of file OneWayTunnel.cc.
References n_connections.
Referenced by close_source_vio(), close_target_vio(), and OneWayMultiTunnel::close_target_vio().
OneWayTunnel * OneWayTunnel::OneWayTunnel_alloc | ( | ) | [static] |
Allocates a OneWayTunnel object.
Definition at line 73 of file OneWayTunnel.cc.
References OneWayTunnelAllocator.
Referenced by SocksProxy::mainEvent(), CacheContinuation::replyOpEvent(), and CacheContinuation::setupReadBufTunnel().
void OneWayTunnel::OneWayTunnel_free | ( | OneWayTunnel * | pOWT | ) | [static] |
Deallocates a OneWayTunnel object.
Definition at line 79 of file OneWayTunnel.cc.
References Continuation::mutex, and OneWayTunnelAllocator.
Referenced by connection_closed(), and CacheContinuation::tunnelClosedEvent().
void OneWayTunnel::reenable_all | ( | ) | [virtual] |
Reimplemented in OneWayMultiTunnel.
Definition at line 378 of file OneWayTunnel.cc.
References VIO::reenable(), vioSource, and vioTarget.
void OneWayTunnel::SetupTwoWayTunnel | ( | OneWayTunnel * | east, | |
OneWayTunnel * | west | |||
) | [static] |
Definition at line 87 of file OneWayTunnel.cc.
References ink_assert, Continuation::mutex, and tunnel_peer.
Referenced by SocksProxy::mainEvent().
int OneWayTunnel::startEvent | ( | int | event, | |
void * | data | |||
) |
Reimplemented in OneWayMultiTunnel.
Definition at line 237 of file OneWayTunnel.cc.
References VIO::buffer, close_source_vio(), close_target_vio(), connection_closed(), free_vcs, get_vc_event_name(), ink_assert, lerrno, VIO::nbytes, VIO::ndone, VIO::ntodo(), ONE_WAY_TUNNEL_EVENT_PEER_CLOSE, IOBufferReader::read_avail(), MIOBufferAccessor::reader(), VIO::reenable(), startEvent(), transform(), tunnel_peer, tunnel_till_done, VC_EVENT_ACTIVE_TIMEOUT, VC_EVENT_DONE, VC_EVENT_EOS, VC_EVENT_ERROR, VC_EVENT_INACTIVITY_TIMEOUT, VC_EVENT_READ_COMPLETE, VC_EVENT_READ_READY, VC_EVENT_WRITE_COMPLETE, VC_EVENT_WRITE_READY, vioSource, and vioTarget.
Referenced by init(), and startEvent().
void OneWayTunnel::transform | ( | MIOBufferAccessor & | in_buf, | |
MIOBufferAccessor & | out_buf | |||
) | [virtual] |
Definition at line 219 of file OneWayTunnel.cc.
References manipulate_fn, transfer_data(), and MIOBufferAccessor::writer().
Referenced by startEvent(), and OneWayMultiTunnel::startEvent().
Definition at line 209 of file I_OneWayTunnel.h.
Referenced by close_source_vio(), init(), and OneWayMultiTunnel::init().
Definition at line 210 of file I_OneWayTunnel.h.
Referenced by close_target_vio(), OneWayMultiTunnel::close_target_vio(), init(), and OneWayMultiTunnel::init().
Definition at line 203 of file I_OneWayTunnel.h.
Referenced by connection_closed(), init(), and OneWayMultiTunnel::init().
Definition at line 215 of file I_OneWayTunnel.h.
Referenced by close_source_vio(), close_target_vio(), and startEvent().
Definition at line 206 of file I_OneWayTunnel.h.
Referenced by close_source_vio(), close_target_vio(), init(), and startEvent().
Definition at line 204 of file I_OneWayTunnel.h.
Referenced by init(), OneWayMultiTunnel::init(), and transform().
Definition at line 205 of file I_OneWayTunnel.h.
Referenced by close_source_vio(), close_target_vio(), OneWayMultiTunnel::close_target_vio(), init(), OneWayMultiTunnel::init(), last_connection(), and OneWayMultiTunnel::startEvent().
Definition at line 208 of file I_OneWayTunnel.h.
Referenced by close_source_vio(), close_target_vio(), OneWayMultiTunnel::close_target_vio(), init(), and OneWayMultiTunnel::init().
Non-NULL when this is one side of a two way tunnel.
Definition at line 214 of file I_OneWayTunnel.h.
Referenced by SetupTwoWayTunnel(), and startEvent().
Definition at line 211 of file I_OneWayTunnel.h.
Referenced by init(), OneWayMultiTunnel::init(), startEvent(), and OneWayMultiTunnel::startEvent().
Definition at line 201 of file I_OneWayTunnel.h.
Referenced by close_source_vio(), CacheContinuation::handleDisposeEvent(), init(), OneWayMultiTunnel::init(), reenable_all(), OneWayMultiTunnel::reenable_all(), startEvent(), and OneWayMultiTunnel::startEvent().
Definition at line 202 of file I_OneWayTunnel.h.
Referenced by ChannelToCacheWriteVC(), close_target_vio(), CacheContinuation::handleDisposeEvent(), init(), reenable_all(), and startEvent().