{
time: 0.223399,
cached: false,
possibilities: [
'ace',
// several words omitted
'lex',
'lexica',
'lexical',
'li',
'lice',
'lie',
'lilac',
'xi'
]
}myth4> ./scrabble-word-finder ieclxal
ace
lex
lexica
lexical
li
lice
lie
lilac
xi
myth4>struct subprocess_t {
pid_t pid;
int supplyfd;
int ingestfd;
};
subprocess_t subprocess(char *argv[],
bool supplyChildInput,
bool ingestChildOutput) throw (SubprocessException);static void publishScrabbleWords(int clientSocket) {
sockbuf sb(clientSocket);
iosockstream ss(&sb);
string letters = getLetters(ss); // extracts tail of path from GET <path> <protocol>
skipHeaders(ss); // skips everything else
const char *command[] = {"./scrabble-word-finder", letters.c_str(), NULL};
subprocess_t sp = subprocess(const_cast<char **>(command), false, true);
vector<string> formableWords = pullFormableWords(sp.ingestfd);
waitpid(sp.pid, NULL, 0);
ostringstream payload;
constructPayload(formableWords, payload); // posts JSON to payload
sendResponse(ss, payload.str()); // publishes HTTP response to ss out of payload
}