cURL / Mailing Lists / curl-library / Single Mail

curl-library

Using curl_multi_socket_action for multiplexing sockets

From: Todatry, Santhana <Santhana.Todatry_at_uscellular.com>
Date: Mon, 23 Jul 2012 00:12:03 -0500

My sincere apologies for missing the Subject of the email.

> Greetings and well wishes to all libcurl folks!
>
> This is my 1st posting!!
>
> BACKGROUND INFO ON MY APPLICATION:
>
> I have a working application (ivr_server) written in C, that gets called by web service A, and in turn, calls web services B and C (both HTTP) deployed on Oracle Service Bus (OSB). Ivr_server also calls another server process D. ivr_server is a single process, multiplexing asynchronous I/O over 4 TCP/IP sockets (for A, B, C and D), for every customer transaction.
>
> WHAT I NEED TO DO:
>
> Since web services B & C are to be deployed as HTTPS services. ivr_server needs to be SSL enabled, as well as, authenticate certificate from OSB.
>
> HOW MY APPLICATION CALLS WEB SERVICES B AND C:
>
> * Open a TCP/IP socket
> * Connect socket to OSB host and port.
> * Add socket to an array of sockets to be later polled for I/O events, using poll().
> * Prepare request message formatted with HTTP header and XML/SOAP envelope.
> * Write request message through socket.
> --------------------------
> * Wait on on event loop for I/O events on any of the sockets in the socket array.
> --------------------------
> * If there is a read event on the socket connected to OSB, read the response message.
> * Process the response.
>
> WILL THE FOLLOWING APPROACH WORK?
> ARE THERE FLAWS IN MY UNDERSTANDING OF EASY AND MULTI_SOCKET_ACTION APIs?
>
> main():
>
> curl_global_init(CURL_GLOBAL_ALL)
> curl_version_info() // to determine features supported by current version of libcurl
>
> // ------- Following logic gets called when there is a need to send request to web service B or C ----------------------
>
> EasyHandle = curl_easy_init()
>
> curl_easy_setopt( EasyHandle, CURLOPT_URL, "https://host_port_and_service_path_of_web_service" );
> curl_easy_setopt( EasyHandle, CURLOPT_SSL_VERIFYPEER, 1L ); // Tells IVR to verify ESB's certificate
> curl_easy_setopt( EasyHandle, CURLOPT_CAINFO, PeerCertificateFile ); // char *PeerCertificateFile holds ESB's certificates
> curl_easy_setopt( EasyHandle, CURLOPT_SSLVERSION, CURL_SSLVESION_DEFAULT ); // Or CURL_SSLVERSION_TLSv1
> curl_easy_setopt( EasyHandle, CURLOPT_HTTPPROXYTUNNEL, 1L ); // SSL via proxies require proxy tunneling (true?)
> curl_easy_setopt( EasyHandle, CURLOPT_POSTFIELDS, RequestData ); // char *RequestData will be HTTP POSTed to ESB
> curl_easy_setopt( EasyHandle, CURLOPT_WRITEFUNCTION, WriteFunction ); // WriteFunction will capture Response from ESB
>
> MultiHandle = curl_multi_init() // Create multi handle
> curl_multi_add_handle( MultiHandle, EasyHandle ); // Add only one easy handle to multi handle
>
> CURLcode = curl_easy_getinfo( EasyHandle, CURLINFO_LASTSOCKET, pOSBSocketFD ); // Fetch OSB's socket fd into long *pESBSocketFD
>
> WriteBitMask = 0; WriteBitMask |= CURL_CSELECT_OUT; // Prepare BitMask for write operation
> curl_multi_socket_action(MultiHandle, pOSBSocketFD, WriteBitMask, pRunningHandles); // POST RequestData to OSB socket
> // Add pOSBSocketFD to array of FDs for poll()ing
>
>
>
> poll() on all open sockets // Wait for I/O event on any socket
>
>
>
> // ------- Following logic gets called when poll() found that there is a response in OSB socket FD (from web service B or C) -----------
>
> ReadBitMask = 0; ReadBitMask |= CURL_CSELECT_IN; // Prepare BitMask for read operation
> curl_multi_socket_action(MultiHandle, pOSBSocketFD, ReadBitMask, pRunningHandles); // To read Response from OSB socket
>
> While ( (CurlMsg = curl_multi_info_read(MultiHandle, pMsgsInQueue)) ) // Check for messages in a loop>
> If (CurlMsg->msg != CURLMSG_DONE)
> // log CurlMsg->data.whatever
> Else
> curl_multi_remove_handle( MultiHandle, EasyHandle ); // Remove the only easy handle from multi handle
> curl_easy_cleanup( EasyHandle );
> curl_multi_cleanup( MultiHandle );
>
>
> // -------- Following logic gets called when process terminates
> curl_global_cleanup()
>
> -----------------------------------------------------------------------------------------
>
> Thanks in advance!!!
>
> Santhana Todatry
> Chicago, USA
>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-07-23