| 2333 | |
| 2334 | |
| 2335 | void Service::get(UCHAR* buffer, USHORT length, USHORT flags, USHORT timeout, USHORT* return_length) |
| 2336 | { |
| 2337 | #ifdef HAVE_GETTIMEOFDAY |
| 2338 | struct timeval start_time, end_time; |
| 2339 | GETTIMEOFDAY(&start_time); |
| 2340 | #else |
| 2341 | time_t start_time, end_time; |
| 2342 | time(&start_time); |
| 2343 | #endif |
| 2344 | |
| 2345 | *return_length = 0; |
| 2346 | svc_timeout = false; |
| 2347 | bool flagFirst = true; |
| 2348 | ULONG head = svc_stdout_head; |
| 2349 | |
| 2350 | while (length) |
| 2351 | { |
| 2352 | if ((empty(head) && (svc_flags & SVC_finished)) || checkForShutdown()) |
| 2353 | { |
| 2354 | break; |
| 2355 | } |
| 2356 | |
| 2357 | if (empty(head)) |
| 2358 | { |
| 2359 | if (svc_stdin_size_requested && (!(flags & GET_BINARY))) |
| 2360 | { |
| 2361 | // service needs data from user - notify him |
| 2362 | break; |
| 2363 | } |
| 2364 | |
| 2365 | if (flagFirst) |
| 2366 | { |
| 2367 | svc_sem_empty.release(); |
| 2368 | flagFirst = false; |
| 2369 | } |
| 2370 | |
| 2371 | if (flags & GET_ONCE) |
| 2372 | { |
| 2373 | break; |
| 2374 | } |
| 2375 | |
| 2376 | if (full()) |
| 2377 | { |
| 2378 | // buffer is full but LF is not present in it |
| 2379 | break; |
| 2380 | } |
| 2381 | |
| 2382 | UnlockGuard guard(this, FB_FUNCTION); |
| 2383 | svc_sem_full.tryEnter(1, 0); |
| 2384 | if (!guard.enter()) |
| 2385 | Arg::Gds(isc_bad_svc_handle).raise(); |
| 2386 | } |
| 2387 | #ifdef HAVE_GETTIMEOFDAY |
| 2388 | GETTIMEOFDAY(&end_time); |
| 2389 | const time_t elapsed_time = end_time.tv_sec - start_time.tv_sec; |
| 2390 | #else |
| 2391 | time(&end_time); |
| 2392 | const time_t elapsed_time = end_time - start_time; |