Add talk_to_socket handler
authorLaurence Withers <lwithers@amethyst.(none)>
Wed, 22 Jul 2009 19:46:43 +0000 (19:46 +0000)
committerLaurence Withers <lwithers@amethyst.(none)>
Wed, 22 Jul 2009 19:46:43 +0000 (19:46 +0000)
commit353472953ada54d5e1b5d235ca472254478d17ad
treea761128a993525d30acc5950fb133e31e3302aff
parente0a3e5e4ff2b2d038df52936c5ccd4b3b40e198d
Add talk_to_socket handler

This handler talks directly to a daemon using a Unix SOCK_SEQPACKET socket,
allowing e.g. cookie handlers to be implemented without having to fork and
and execute an external program or script interpreter.

A little explanation of the functioning of talk_to_socket():

 1. We receive our argument as a string in the format of "HANDLER EXTRA_ARGS".
 2. Copy "HANDLER" into our Unix socket address structure and connect to that
    address (blocking). Error out if connection fails.
 3. Write "EXTRA_ARGS" to the socket. Error out if writing fails.
 4. Use poll() to wait for a response, timing out after 500ms of inactivity.
 5. Use ioctl(FIONREAD) to find out how long the pending datagram is.
 6. Allocate an appropriately sized buffer (len+1) and write a null at the
    end, so our output is always null-terminated no matter what.
 7. Read from socket into buffer. Error out if read fails.
 8. Close socket.
uzbl.c
uzbl.h