libsigc++ and connecting a function as signal to another function as slot

602 views Asked by At

It's first time to using libsigc++ for signal slot, I have two functions that they are working fine, My scenario: I wrote a function as boolean function that if when socket has data for recv, it return true:

bool Socket::isDataReady()
{
    void *buffer = malloc (FRAMEBUFFER + 6);
    sockaddr_in from;
    socklen_t fromLength = sizeof( from );

    if (::recvfrom(this->socketFD,buffer,FRAMEBUFFER + 6, 0, (sockaddr *)&this->getSocketAddressStructureOfServer(), &fromLength ) == -1)
    {
        if (errno == EAGAIN || errno == EWOULDBLOCK)
            return false;
    }
    return true;

}

So , I wrote a function that is get data from net:

int Socket::readDatagrams(unsigned char *buffer, string &srcAddress, unsigned short int & srcPort)
{
    unsigned int maximumPacketSize = FRAMEBUFFER + 6;
    int returnValue ;
    sockaddr_in from;
    socklen_t fromLength = sizeof( from );
    int receivedBytes;

    fromLength = sizeof(this->getSocketAddressStructureOfServer());
    receivedBytes = recvfrom( this->socketFD, buffer, maximumPacketSize, 0, (sockaddr *)&this->getSocketAddressStructureOfServer(), &fromLength );

    returnValue = receivedBytes;
    if ( receivedBytes <= 0 )
        returnValue = -1;

    /// exporting data
    //
    srcAddress = inet_ntoa(this->getSocketAddressStructureOfServer().sin_addr);
    srcPort = ntohs( ( unsigned short int)this->getSocketAddressStructureOfServer().sin_port );


    return returnValue;
}

i have UDP server and initialize everything in constructor, So i need to tell whenever isDataReady() is true, readDatagram itself execute. How do write code with libsigc++? i read their tutorial , but its, tutorial didn't say about func as sig.

1

There are 1 answers

0
AudioBubble On BEST ANSWER

I know that you define

sigc::signal<bool> ptr;

in body of your class. Then if you want to connect in your class, call :

this->ptr.connect(sigc::mem_fun(*this,&NetworkSocket::createThread));

But i don't know about rest of story....