Public Member Functions | Static Public Member Functions | Data Fields

OneWayTunnel Struct Reference

A generic state machine that connects two virtual conections. More...

#include <I_OneWayTunnel.h>

Inherits Continuation.

Inherited by OneWayMultiTunnel.

Collaboration diagram for OneWayTunnel:
Collaboration graph
[legend]

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 OneWayTunnelOneWayTunnel_alloc ()
 Allocates a OneWayTunnel object.
static void OneWayTunnel_free (OneWayTunnel *)
 Deallocates a OneWayTunnel object.
static void SetupTwoWayTunnel (OneWayTunnel *east, OneWayTunnel *west)

Data Fields

VIOvioSource
VIOvioTarget
Continuationcont
Transform_fn manipulate_fn
int n_connections
int lerrno
bool single_buffer
bool close_source
bool close_target
bool tunnel_till_done
OneWayTunneltunnel_peer
 Non-NULL when this is one side of a two way tunnel.
bool free_vcs

Detailed Description

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.


Constructor & Destructor Documentation

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.


Member Function Documentation

void OneWayTunnel::close_source_vio ( int  result  ) 
void OneWayTunnel::close_target_vio ( int  result,
VIO vio = ONE_WAY_TUNNEL_CLOSE_ALL 
) [virtual]
void OneWayTunnel::connection_closed ( int  result  ) 
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.

Parameters:
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).

Parameters:
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)

Parameters:
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 (  ) 
OneWayTunnel * OneWayTunnel::OneWayTunnel_alloc (  )  [static]

Allocates a OneWayTunnel object.

Returns:
new 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 
)
void OneWayTunnel::transform ( MIOBufferAccessor in_buf,
MIOBufferAccessor out_buf 
) [virtual]

Field Documentation

Definition at line 209 of file I_OneWayTunnel.h.

Referenced by close_source_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().

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().


The documentation for this struct was generated from the following files: