Pthreads in the adapters

Asked by Vishnu Thejus Chiyyarath

Hello Alex,

I am trying to develop an eCAP adapter, which does header enrichment. So in short my adapter will get the client ip address and convert into an encrypted string and add that string as a value to a header (X-Encrypted). And I could do that successfully. But my problem is that - the external process does the conversion of ip address may get blocked (Note: the adapter communicates to it through TCP/IP) and in turn blocks other requests to the squid, which doesn’t requires this conversion. So to solve that issue, I introduced threads and it’s successfully downloading the requested content. But I am unhappy with certain stuffs.

Issues faced:
1. There is an unknown delay of few seconds for every transaction. Is it really valid to introduce threads into the adapters?
2. The Adapter::Xaction::stop() or Adapter::Xaction::~Xaction() are never been called after the Adapter::Xaction::start(). So could not release the resources.

Pasting some important part of the code:

void Adapter::Xaction::start() {
    Must(hostx);
    SampleLog ("Adapter: Xaction::start. Got a connection\n") ;
    if (hostx->virgin().body()) {
        receivingVb = opOn;
        hostx->vbMake(); // ask host to supply virgin body
    } else {
        // we are not interested in vb if there is not one
        receivingVb = opNever;
    }
    …..

    pthread_t th ;
    int ret ;
    ret = pthread_create (&th, NULL, (void*(*)(void*))&Adapter::Xaction::startThread, (void*)this) ;
    …
   pthread_detach(th) ;

}

// The thread function
void* Adapter::Xaction::startThread(Adapter::Xaction *xactionPtr)
{
            <Sanity check comes here>

           libecap::Area area = hostx->option (libecap::metaClientIp) ;
           std::string clientIP (area.start, area.size) ;

           <The code for the conversion, which MAY get blocked, comes here>

           < Header insertion (adaptation) code comes here>

           // Final call to inform that the adaptation is completed...
           lastHostCall()->useAdapted(adapted);

  }

Is this code valid? Please look into the same and help me out in solving the above 2 mentioned issues.

Thanks in advance,
Vishnu

Question information

Language:
English Edit question
Status:
Solved
For:
eCAP Edit question
Assignee:
No assignee Edit question
Solved by:
Alex Rousskov
Solved:
Last query:
Last reply:
Revision history for this message
Alex Rousskov (rousskov) said :
#1

Sorry, I cannot debug your code, but please see Question #181948 "Asynchronous processing of message content" for more information about eCAP and threads: https://answers.launchpad.net/ecap/+question/181948

Revision history for this message
Vishnu Thejus Chiyyarath (vishnuthejus) said :
#2

Sure. It seems like I could find some solution from that post.

Thanks,
Vishnu

Revision history for this message
Vishnu Thejus Chiyyarath (vishnuthejus) said :
#3

While going through the eCAP website (http://www.e-cap.org/Documentation), I’ve noticed that they are planning to add a support for “threaded adapters”. Any idea what is it supposed to be and when is it getting launched?

Thanks,
Vishnu

Revision history for this message
Best Alex Rousskov (rousskov) said :
#4

My response to question #181948 "Asynchronous processing of message content" summarizes major issues that need to be addressed for full threading support. Currently, there is not specific schedule to implement those features, but patches or sponsorship is welcomed.

Revision history for this message
Vishnu Thejus Chiyyarath (vishnuthejus) said :
#5

Thanks Alex Rousskov, that solved my question.