start a new stdin sender thread and pipe from sender to the search engine
| 4171 | |
| 4172 | // start a new stdin sender thread and pipe from sender to the search engine |
| 4173 | void Query::start_stdin() |
| 4174 | { |
| 4175 | // if standard input is searched, start thread to reproduce its text on demand |
| 4176 | if (flag_stdin) |
| 4177 | { |
| 4178 | // create a new pipe |
| 4179 | if (pipe(stdin_pipe_) < 0) |
| 4180 | { |
| 4181 | what_.assign("cannot create pipe"); |
| 4182 | // error at the end of the line, not within |
| 4183 | error_ = line_wsize(); |
| 4184 | return; |
| 4185 | } |
| 4186 | |
| 4187 | // and assign it to the source |
| 4188 | Static::source = fdopen(stdin_pipe_[0], "rb"); |
| 4189 | |
| 4190 | // run stdin_sender in the background to push buffered standard input down the pipe |
| 4191 | stdin_stop = false; |
| 4192 | stdin_thread_ = std::thread(Query::stdin_sender, stdin_pipe_[1]); |
| 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | // stop stdin sender thread |
| 4197 | void Query::stop_stdin() |