Changeset 6629
- Timestamp:
- Nov 14, 2016 6:28:38 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pymolproxy/trunk/pymolproxy.c
r6617 r6629 104 104 static int pymolIsAlive = TRUE; 105 105 static int statsFile = -1; 106 static long idleTimeout = -1L; 106 107 107 108 #define READ_DEBUG 1 … … 2266 2267 PymolProxy *p = clientData; 2267 2268 Tcl_DString command; 2269 fd_set readFds; 2270 int ret = 1; 2268 2271 struct timeval tv, *tvPtr; 2272 int polling = 0; 2269 2273 2270 2274 #if READ_DEBUG … … 2273 2277 Tcl_DStringInit(&command); 2274 2278 while (pymolIsAlive) { 2275 tvPtr = NULL; 2279 FD_ZERO(&readFds); 2280 FD_SET(p->client.fd, &readFds); 2281 2282 if (idleTimeout >= 0L) { 2283 tv.tv_sec = idleTimeout; 2284 tv.tv_usec = 0L; 2285 polling = (tv.tv_sec == 0 && tv.tv_usec == 0) ? 1 : 0; 2286 tvPtr = &tv; 2287 } else { 2288 tvPtr = NULL; 2289 } 2276 2290 #if READ_DEBUG 2277 2291 DEBUG("Start I/O set"); 2278 2292 #endif 2279 while ((pymolIsAlive) && (WaitForNextLine(&p->client, tvPtr))) { 2293 while (pymolIsAlive && 2294 (IsLineAvailable(&p->client) || 2295 (ret = select(p->client.fd+1, &readFds, NULL, NULL, tvPtr)) > 0)) { 2280 2296 size_t numBytes; 2281 2297 const char *line; … … 2302 2318 DEBUG("TCL_BREAK found"); 2303 2319 #endif 2320 ret = 2; 2304 2321 break; /* This was caused by a "imgflush" 2305 2322 * command. Break out of the read 2306 2323 * loop and allow a new image to be 2307 2324 * rendered. */ 2325 } else if (result != TCL_OK) { 2326 ret = 0; 2327 } else { 2328 ret = 3; 2308 2329 } 2309 2330 if (p->flags & FORCE_UPDATE) { … … 2314 2335 } 2315 2336 } 2337 polling = 1; 2316 2338 tv.tv_sec = 0L; 2317 2339 tv.tv_usec = 0L; /* On successive reads, we break 2318 2340 * out if no data is available. */ 2341 FD_SET(p->client.fd, &readFds); 2319 2342 tvPtr = &tv; 2320 2343 } … … 2322 2345 DEBUG("Finish I/O set"); 2323 2346 #endif 2347 if (ret < 0) { 2348 DEBUG("Error in select(): %s", strerror(errno)); 2349 goto done; 2350 } 2351 if (!polling && ret == 0 && idleTimeout > 0L) { 2352 // If idle timeout expired, disconnect 2353 DEBUG("Exiting server after timeout waiting for client command"); 2354 goto done; 2355 } 2324 2356 /* Handle all the pending setting changes now. */ 2325 2357 UpdateSettings(p); … … 2434 2466 size_t numBytes; 2435 2467 2468 while (1) { 2469 int c = getopt(argc, argv, "t:"); 2470 if (c == -1) { 2471 break; 2472 } 2473 switch (c) { 2474 case 't': 2475 idleTimeout = atol(optarg); 2476 break; 2477 case '?': 2478 break; 2479 default: 2480 return 1; 2481 } 2482 } 2483 2436 2484 frecord = NULL; 2437 2485 if (recording) { … … 2452 2500 DEBUG("Starting pymolproxy"); 2453 2501 2454 InitProxy(&proxy, argv + 1);2502 InitProxy(&proxy, argv + optind); 2455 2503 if (pthread_create(&thread1, NULL, &ClientToServer, &proxy) < 0) { 2456 2504 ERROR("Can't create reader thread: %s", strerror(errno));
Note: See TracChangeset
for help on using the changeset viewer.