Faspstream Manager C/C++ API  3.6.1
A C and C++ language interface to basic streaming over the fasp protocol
FaspStreamServer Class Reference

#include <FaspStreamServer.h>

Public Member Functions

FASPSTREAM_CPP_API FaspStreamServer (const std::string &appId, FaspConnectionChannel *channel=NULL)
 
FASPSTREAM_CPP_API bool startServer (bool killChild=false)
 
FASPSTREAM_CPP_API FaspInputStreamgetFaspInputStream ()
 
FASPSTREAM_CPP_API FaspOutputStreamgetFaspOutputStream ()
 
FASPSTREAM_CPP_API void cleanup ()
 
FASPSTREAM_CPP_API ~FaspStreamServer ()
 
FASPSTREAM_CPP_API void setFaspstreamPath (const std::string &faspstreamPath)
 
FASPSTREAM_CPP_API std::string getFaspstreamPath () const
 
FASPSTREAM_CPP_API int getPort () const
 
FASPSTREAM_CPP_API void setPort (int tcpPort)
 
FASPSTREAM_CPP_API int getMaxMemory () const
 
FASPSTREAM_CPP_API void setMaxMemory (int maxMem)
 
FASPSTREAM_CPP_API std::string getUsername () const
 
FASPSTREAM_CPP_API int getUdpPort () const
 
FASPSTREAM_CPP_API void setUdpPort (int port)
 
FASPSTREAM_CPP_API int getDatagramSize () const
 
FASPSTREAM_CPP_API void setDatagramSize (int size)
 
FASPSTREAM_CPP_API int getChunkSize () const
 
FASPSTREAM_CPP_API void setChunkSize (int size)
 
FASPSTREAM_CPP_API std::string getHostname () const
 
FASPSTREAM_CPP_API void setHostname (const std::string &name)
 
FASPSTREAM_CPP_API int getRateTarget () const
 
FASPSTREAM_CPP_API void setRateTarget (int target)
 
FASPSTREAM_CPP_API FASPSTREAM_CIPHER_TYPE getCipherType () const
 
FASPSTREAM_CPP_API void setCipherType (FASPSTREAM_CIPHER_TYPE type)
 
FASPSTREAM_CPP_API bool isLockTarget () const
 
FASPSTREAM_CPP_API void setLockTarget (bool target)
 
FASPSTREAM_CPP_API int getRateMinimum () const
 
FASPSTREAM_CPP_API void setRateMinimum (int minimum)
 
FASPSTREAM_CPP_API bool isLockMinimum () const
 
FASPSTREAM_CPP_API void setLockMinimum (bool lockMin)
 
FASPSTREAM_CPP_API FASPSTREAM_POLICY_TYPE getPolicy () const
 
FASPSTREAM_CPP_API void setPolicy (FASPSTREAM_POLICY_TYPE newPolicy)
 
FASPSTREAM_CPP_API bool isLockPolicy () const
 
FASPSTREAM_CPP_API void setLockPolicy (bool lock)
 
FASPSTREAM_CPP_API int getAggressiveness () const
 
FASPSTREAM_CPP_API void setAggressiveness (int aggressive)
 
FASPSTREAM_CPP_API int getForceSendMilliseconds () const
 
FASPSTREAM_CPP_API void setForceSendMilliseconds (int milliseconds)
 
FASPSTREAM_CPP_API void setTransferMode (FASPSTREAM_TRANSFER_MODE_TYPE transferMode)
 
FASPSTREAM_CPP_API FASPSTREAM_TRANSFER_MODE_TYPE getTransferMode () const
 
FASPSTREAM_CPP_API void setLogDirectory (std::string logDirectory)
 
FASPSTREAM_CPP_API std::string getLogDirectory () const
 
FASPSTREAM_CPP_API void setCommandToExecute (std::string commandToExecute)
 
FASPSTREAM_CPP_API std::string getCommandToExecute () const
 
FASPSTREAM_CPP_API void setLicense (std::string commandToExecute)
 
FASPSTREAM_CPP_API std::string getLicense () const
 
FASPSTREAM_CPP_API void setAcceptTimeout (int timeout)
 
FASPSTREAM_CPP_API int getAcceptTimeout () const
 
std::vector< std::string > getCommandline () const
 
void registerLogCallback (log_callback_f log_function)
 

Detailed Description

Use the FaspStreamServer class to wait for stream connections and then receive (read) or send (write) a stream of data. Note this class does not inherit from any of the C++ std::ios stream classes, and requires the user to implement a read()/write() loop.

Constructor & Destructor Documentation

FASPSTREAM_CPP_API FaspStreamServer::FaspStreamServer ( const std::string &  appId,
FaspConnectionChannel channel = NULL 
)

Does basic initialization of server's fields, sets defaults, etc.

The channel argument is optional and is only used when you would like to share a TCP connection so that our internal code can tunnel fasp control data on the TCP connection you share.

IMPORTANT: If you use the channel argument, the channel's destructor must fire after the server's destructor. Otherwise, the background thread that does the tunneling may cause a seg fault.

Parameters
appIda string identifier which is unique to this application
channelan implementation of the FaspConnectionChannel iface
FASPSTREAM_CPP_API FaspStreamServer::~FaspStreamServer ( )

Kills faspstream process if it is still alive. Does any remaining clean up.

Member Function Documentation

FASPSTREAM_CPP_API void FaspStreamServer::cleanup ( )

IMPORTANT: You should call this before the destructor fires. If the faspstream process is still working and destructor is called, it will be killed.

Closes input and output streams and waits for faspstream process to gracefully exit.

If you shared a TCP socket for fasp control data tunneling, the background thread will be terminated, and under normal conditions, your channel's close method will be invoked.

Throws a FaspStreamException if the exit status of the faspstream process is non-zero.

FASPSTREAM_CPP_API int FaspStreamServer::getAcceptTimeout ( ) const
FASPSTREAM_CPP_API int FaspStreamServer::getAggressiveness ( ) const
FASPSTREAM_CPP_API int FaspStreamServer::getChunkSize ( ) const
FASPSTREAM_CPP_API FASPSTREAM_CIPHER_TYPE FaspStreamServer::getCipherType ( ) const
std::vector<std::string> FaspStreamServer::getCommandline ( ) const

This method can be used to generate the command line arguments with which the faspstream child process will be invoked, it can be useful for debugging purposes but is not normally necessary.

FASPSTREAM_CPP_API std::string FaspStreamServer::getCommandToExecute ( ) const
FASPSTREAM_CPP_API int FaspStreamServer::getDatagramSize ( ) const
FASPSTREAM_CPP_API FaspInputStream& FaspStreamServer::getFaspInputStream ( )

Use these to get the underlying input and output streams connected to the faspstream process.

IMPORTANT: You should call these every time you try to do a read/write. We do a check each time you invoke these to ensure the faspstream is still open.

NOTE: If you are doing a "send", you need the output stream. If you are doing a "recv", you need the input stream.

FASPSTREAM_CPP_API FaspOutputStream& FaspStreamServer::getFaspOutputStream ( )
FASPSTREAM_CPP_API std::string FaspStreamServer::getFaspstreamPath ( ) const
FASPSTREAM_CPP_API int FaspStreamServer::getForceSendMilliseconds ( ) const
FASPSTREAM_CPP_API std::string FaspStreamServer::getHostname ( ) const
FASPSTREAM_CPP_API std::string FaspStreamServer::getLicense ( ) const
FASPSTREAM_CPP_API std::string FaspStreamServer::getLogDirectory ( ) const
FASPSTREAM_CPP_API int FaspStreamServer::getMaxMemory ( ) const
FASPSTREAM_CPP_API FASPSTREAM_POLICY_TYPE FaspStreamServer::getPolicy ( ) const
FASPSTREAM_CPP_API int FaspStreamServer::getPort ( ) const
FASPSTREAM_CPP_API int FaspStreamServer::getRateMinimum ( ) const
FASPSTREAM_CPP_API int FaspStreamServer::getRateTarget ( ) const
FASPSTREAM_CPP_API FASPSTREAM_TRANSFER_MODE_TYPE FaspStreamServer::getTransferMode ( ) const
FASPSTREAM_CPP_API int FaspStreamServer::getUdpPort ( ) const
FASPSTREAM_CPP_API std::string FaspStreamServer::getUsername ( ) const
FASPSTREAM_CPP_API bool FaspStreamServer::isLockMinimum ( ) const
FASPSTREAM_CPP_API bool FaspStreamServer::isLockPolicy ( ) const
FASPSTREAM_CPP_API bool FaspStreamServer::isLockTarget ( ) const
void FaspStreamServer::registerLogCallback ( log_callback_f  log_function)

Method for registering a logging callback

When a new log entry is available the function specified will be called (signature: void return, const char* argument). (Will not log if NULL, as is by default)

Parameters
log_callbackpointer to log function you have implemented

The simplest implementation of the callback might look like this:

static void log_function( char const *s ) {
  fprintf( stderr, "%s\n", s );
}

FASPSTREAM_CPP_API void FaspStreamServer::setAcceptTimeout ( int  timeout)
FASPSTREAM_CPP_API void FaspStreamServer::setAggressiveness ( int  aggressive)
FASPSTREAM_CPP_API void FaspStreamServer::setChunkSize ( int  size)
FASPSTREAM_CPP_API void FaspStreamServer::setCipherType ( FASPSTREAM_CIPHER_TYPE  type)
FASPSTREAM_CPP_API void FaspStreamServer::setCommandToExecute ( std::string  commandToExecute)
FASPSTREAM_CPP_API void FaspStreamServer::setDatagramSize ( int  size)
FASPSTREAM_CPP_API void FaspStreamServer::setFaspstreamPath ( const std::string &  faspstreamPath)
FASPSTREAM_CPP_API void FaspStreamServer::setForceSendMilliseconds ( int  milliseconds)
FASPSTREAM_CPP_API void FaspStreamServer::setHostname ( const std::string &  name)
FASPSTREAM_CPP_API void FaspStreamServer::setLicense ( std::string  commandToExecute)
FASPSTREAM_CPP_API void FaspStreamServer::setLockMinimum ( bool  lockMin)
FASPSTREAM_CPP_API void FaspStreamServer::setLockPolicy ( bool  lock)
FASPSTREAM_CPP_API void FaspStreamServer::setLockTarget ( bool  target)
FASPSTREAM_CPP_API void FaspStreamServer::setLogDirectory ( std::string  logDirectory)
FASPSTREAM_CPP_API void FaspStreamServer::setMaxMemory ( int  maxMem)
FASPSTREAM_CPP_API void FaspStreamServer::setPolicy ( FASPSTREAM_POLICY_TYPE  newPolicy)
FASPSTREAM_CPP_API void FaspStreamServer::setPort ( int  tcpPort)
FASPSTREAM_CPP_API void FaspStreamServer::setRateMinimum ( int  minimum)
FASPSTREAM_CPP_API void FaspStreamServer::setRateTarget ( int  target)
FASPSTREAM_CPP_API void FaspStreamServer::setTransferMode ( FASPSTREAM_TRANSFER_MODE_TYPE  transferMode)
FASPSTREAM_CPP_API void FaspStreamServer::setUdpPort ( int  port)
FASPSTREAM_CPP_API bool FaspStreamServer::startServer ( bool  killChild = false)

Starts the faspstream process in server mode, listening for an incoming client connection.

This method will not block to wait for an incoming connection, but returns immediately. (The faspstream process, meanwhile, is waiting for the incoming connection.)

You will not block until you try to do a read or write on the input/output streams. (This is because the faspstream process is still waiting for a client to connect and is not reading or writing from its stdin/stdout.)

The killChild parameter is currently not used.

Returns
whether (true) or not (false) the sub-process started correctly

The documentation for this class was generated from the following file: