No announcement yet.

Close the socket while using YAJL

  • Filter
  • Time
  • Show
Clear All
new posts

  • Close the socket while using YAJL

    I have a working B2B web service that uses YAJL. It works correct for small incoming JSON payloads. The only problem is that the connection remains open while the program processes large payloads, which have thousands of line items that take several minutes to process, which causes a timeout.

    My code essentially does a version of these commands to send an acknowledgement of the request:

    yajl_addBool('success': true);
    yajl_writeStdout(200 : errMsg);

    I was expecting the socket to close during yajl_genClose(), but it doesn't close until the program ends. After the yajl_genClose function runs, the program processes the incoming JSON in what I am expecting to be "offline batch mode" since I (tried to) close the socket.

    I've seen this code that can close the socket manually, but that requires having a handle to the socket. Scott's YAJL routines internalize the socket handle, and I don't see a function in his code to retrieve it.

    D close PR 10I 0 ExtProc('close')
    D sock_desc 10I 0 value
    C                   callp     close(s)

    How do I force-close the socket using YAJL?


  • #2
    YAJL does not use sockets. None at all. It can't leave them open, it doesn't use them.


    • #3
      I believe he wants to send the HTTP response back to the caller while the program continues processing. I don't think it works that way. My guess is that he'll have to submit the work request to be done async (e.g. via data queues) and allow the CGI program to end.


      • #4
        Closing the socket wouldn't send the response back while it's processing... it'd kill the connection in the middle, causing the document to be broken.