ZNC trunk
Loading...
Searching...
No Matches
CCurlSock Class Referenceabstract

Csocket style wrapper around libcurl-multi. More...

#include <CurlSock.h>

Inheritance diagram for CCurlSock:
Collaboration diagram for CCurlSock:

Public Member Functions

 CCurlSock ()
virtual ~CCurlSock ()
virtual bool GatherFDsForSelect (std::map< int, int16_t > &miiReadyFds, long &iTimeoutMS)
 the hook we tie into to get events from csocket
virtual bool CheckFDs (const std::map< int, int16_t > &miiReadyFds)
 reimplement this to do nothing as its not needed
CURL * Retr (const CS_STRING &sURL, const CS_STRING &sReferrer="")
 initiates a GET style transfer, but the process doesn't get started until the next GatherFDsForSelect() is called
virtual bool GatherFDsForSelect (std::map< cs_sock_t, short > &miiReadyFds, long &iTimeoutMS)
 called before select, typically you don't need to reimplement this just add sockets via Add and let the default implementation have its way
virtual bool FDsThatTriggered (const std::map< cs_sock_t, short > &miiReadyFds)
 called when there are fd's belonging to this class that have triggered
virtual bool CheckFDs (const std::map< cs_sock_t, short > &miiReadyFds)
 gets called to diff miiReadyFds with m_miiMonitorFDs, and calls FDsThatTriggered when appropriate.
void Add (cs_sock_t iFD, short iMonitorEvents)
 adds a file descriptor to be monitored
void Remove (cs_sock_t iFD)
 removes this fd from monitoring
void DisableMonitor ()
 causes this monitor to be removed
bool IsEnabled () const

Protected Member Functions

virtual void OnCURLComplete (CURL *pCURL)=0
 called when the transfer associate with this CURL object is completed
virtual size_t OnHeader (CURL *pCURL, const char *pData, size_t uBytes)
 called as header information for the document is returned
virtual size_t OnBody (CURL *pCURL, const char *pData, size_t uBytes)
 called as the document is returned

Protected Attributes

std::map< cs_sock_t, short > m_miiMonitorFDs
bool m_bEnabled

Detailed Description

Csocket style wrapper around libcurl-multi.

http://curl.haxx.se/libcurl/c/libcurl-multi.html This isn't finished, but this is my basic approach. I added a means to which Csocket can monitor file descriptors it doesn't directly control. This class hooks into that by virtue of a callback "GatherFDsForSelect" and ties that libcurl-multi. When Csocket looks for fd's to monitor, this class calls "curl_multi_socket_action" which does a couple things ...

  • 1. Calls our CURL callback CCurlSock::SetupSock to let us know the FD's and what they should be monitored for
  • 2. Calls our CURL callback CCurlSock::SetupTimer which lets us know the maxium wait time for activity
  • 3. Process any handles that are in a ready state

The end point here is a non-blocking method to fetch documents via CURL within Csocket

Constructor & Destructor Documentation

◆ CCurlSock()

CCurlSock::CCurlSock ( )

◆ ~CCurlSock()

virtual CCurlSock::~CCurlSock ( )
virtual

Member Function Documentation

◆ Add()

void CSMonitorFD::Add ( cs_sock_t iFD,
short iMonitorEvents )
inlineinherited

adds a file descriptor to be monitored

Parameters
iFDthe file descriptor
iMonitorEventsbitset of events to monitor for (
See also
CSockManager::ECheckType)

References m_miiMonitorFDs.

◆ CheckFDs() [1/2]

virtual bool CCurlSock::CheckFDs ( const std::map< int, int16_t > & miiReadyFds)
inlinevirtual

reimplement this to do nothing as its not needed

References CSMonitorFD::m_bEnabled.

◆ CheckFDs() [2/2]

virtual bool CSMonitorFD::CheckFDs ( const std::map< cs_sock_t, short > & miiReadyFds)
virtualinherited

gets called to diff miiReadyFds with m_miiMonitorFDs, and calls FDsThatTriggered when appropriate.

Typically you don't need to reimplement this.

Parameters
miiReadyFdsthe map of all triggered fd's, not just the fd's from this class
Returns
returning false will remove this from monitoring

◆ DisableMonitor()

void CSMonitorFD::DisableMonitor ( )
inlineinherited

causes this monitor to be removed

References m_bEnabled.

◆ FDsThatTriggered()

virtual bool CSMonitorFD::FDsThatTriggered ( const std::map< cs_sock_t, short > & miiReadyFds)
inlinevirtualinherited

called when there are fd's belonging to this class that have triggered

Parameters
miiReadyFdsthe map of fd's with the bits that triggered them (
See also
CSockManager::ECheckType)
Returns
returning false will remove this from monitoring

◆ GatherFDsForSelect() [1/2]

virtual bool CCurlSock::GatherFDsForSelect ( std::map< int, int16_t > & miiReadyFds,
long & iTimeoutMS )
virtual

the hook we tie into to get events from csocket

◆ GatherFDsForSelect() [2/2]

virtual bool CSMonitorFD::GatherFDsForSelect ( std::map< cs_sock_t, short > & miiReadyFds,
long & iTimeoutMS )
virtualinherited

called before select, typically you don't need to reimplement this just add sockets via Add and let the default implementation have its way

Parameters
miiReadyFdsfill with fd's to monitor and the associated bit to check them for (
See also
CSockManager::ECheckType)
Parameters
iTimeoutMSthe timeout to change to, setting this to -1 (the default)
Returns
returning false will remove this from monitoring. The same effect can be had by setting m_bEnabled to false as it is returned from this

◆ IsEnabled()

bool CSMonitorFD::IsEnabled ( ) const
inlineinherited

References m_bEnabled.

◆ OnBody()

virtual size_t CCurlSock::OnBody ( CURL * pCURL,
const char * pData,
size_t uBytes )
inlineprotectedvirtual

called as the document is returned

◆ OnCURLComplete()

virtual void CCurlSock::OnCURLComplete ( CURL * pCURL)
protectedpure virtual

called when the transfer associate with this CURL object is completed

◆ OnHeader()

virtual size_t CCurlSock::OnHeader ( CURL * pCURL,
const char * pData,
size_t uBytes )
inlineprotectedvirtual

called as header information for the document is returned

◆ Remove()

void CSMonitorFD::Remove ( cs_sock_t iFD)
inlineinherited

removes this fd from monitoring

References m_miiMonitorFDs.

◆ Retr()

CURL * CCurlSock::Retr ( const CS_STRING & sURL,
const CS_STRING & sReferrer = "" )

initiates a GET style transfer, but the process doesn't get started until the next GatherFDsForSelect() is called

Parameters
sURLthe target document
sReferrerthe referring URL

Its important to check the man page on curl_easy_setopt for the various variables. Certain data is tracked and some is not.

  • CURLOPT_POSTFIELDS used to posting data. It is NOT copied by libcurl, so you have to track it until OnCURLComplete is called and the tranfer is complete
  • CURLOPT_HTTPPOST used for multipart post. The linked list passed to this needs to be tracked, and following OnCURLComplete you should set CURLOPT_HTTPPOST with null and then free your data

References CS_STRING.

Member Data Documentation

◆ m_bEnabled

bool CSMonitorFD::m_bEnabled
protectedinherited

◆ m_miiMonitorFDs

std::map< cs_sock_t, short > CSMonitorFD::m_miiMonitorFDs
protectedinherited

Referenced by Add(), and Remove().


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