Faspstream Manager C/C++ API
3.6.1
A C and C++ language interface to basic streaming over the fasp protocol
|
#include <FaspStreamServer.h>
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.
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.
appId | a string identifier which is unique to this application |
channel | an implementation of the FaspConnectionChannel iface |
FASPSTREAM_CPP_API FaspStreamServer::~FaspStreamServer | ( | ) |
Kills faspstream process if it is still alive. Does any remaining clean up.
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)
log_callback | pointer 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.