Changeset 6635 for pymolproxy/branches/1.0/pymolproxy.c
- Timestamp:
- Nov 15, 2016, 12:59:43 AM (8 years ago)
- Location:
- pymolproxy/branches/1.0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pymolproxy/branches/1.0
- Property svn:mergeinfo changed
/pymolproxy/trunk merged: 4623,6616,6629,6631-6634
- Property svn:mergeinfo changed
-
pymolproxy/branches/1.0/pymolproxy.c
r6628 r6635 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 … … 121 122 #define VIEWPORT_PENDING (1<<10) 122 123 123 #define IO_TIMEOUT (30000)124 124 #define CLIENT_READ STDIN_FILENO 125 125 #define CLIENT_WRITE STDOUT_FILENO … … 2064 2064 ERROR("pymol (%d) died unexpectedly", stats.pid); 2065 2065 pymolIsAlive = FALSE; 2066 /*DoExit(1);*/2067 2066 } 2068 2067 … … 2232 2231 } 2233 2232 2234 DEBUG(" attempting to signal (SIGTERM) pymol server.");2233 DEBUG("Attempting to signal (SIGTERM) pymol server."); 2235 2234 kill(-p->pid, SIGTERM); /* Kill process group */ 2236 2235 alarm(5); … … 2266 2265 PymolProxy *p = clientData; 2267 2266 Tcl_DString command; 2267 fd_set readFds; 2268 int ret = 1; 2268 2269 struct timeval tv, *tvPtr; 2270 int polling = 0; 2269 2271 2270 2272 #if READ_DEBUG … … 2273 2275 Tcl_DStringInit(&command); 2274 2276 while (pymolIsAlive) { 2275 tvPtr = NULL; 2277 FD_ZERO(&readFds); 2278 FD_SET(p->client.fd, &readFds); 2279 2280 if (idleTimeout >= 0L) { 2281 tv.tv_sec = idleTimeout; 2282 tv.tv_usec = 0L; 2283 polling = (tv.tv_sec == 0 && tv.tv_usec == 0) ? 1 : 0; 2284 tvPtr = &tv; 2285 } else { 2286 tvPtr = NULL; 2287 } 2276 2288 #if READ_DEBUG 2277 2289 DEBUG("Start I/O set"); 2278 2290 #endif 2279 while ((pymolIsAlive) && (WaitForNextLine(&p->client, tvPtr))) { 2291 while (pymolIsAlive && 2292 (IsLineAvailable(&p->client) || 2293 (ret = select(p->client.fd+1, &readFds, NULL, NULL, tvPtr)) > 0)) { 2280 2294 size_t numBytes; 2281 2295 const char *line; … … 2302 2316 DEBUG("TCL_BREAK found"); 2303 2317 #endif 2318 ret = 2; 2304 2319 break; /* This was caused by a "imgflush" 2305 2320 * command. Break out of the read 2306 2321 * loop and allow a new image to be 2307 2322 * rendered. */ 2323 } else if (result != TCL_OK) { 2324 ret = 0; 2325 } else { 2326 ret = 3; 2308 2327 } 2309 2328 if (p->flags & FORCE_UPDATE) { … … 2314 2333 } 2315 2334 } 2335 polling = 1; 2316 2336 tv.tv_sec = 0L; 2317 2337 tv.tv_usec = 0L; /* On successive reads, we break 2318 2338 * out if no data is available. */ 2339 FD_SET(p->client.fd, &readFds); 2319 2340 tvPtr = &tv; 2320 2341 } … … 2322 2343 DEBUG("Finish I/O set"); 2323 2344 #endif 2345 if (ret < 0) { 2346 DEBUG("Error in select(): %s", strerror(errno)); 2347 goto done; 2348 } 2349 if (!polling && ret == 0 && idleTimeout > 0L) { 2350 // If idle timeout expired, disconnect 2351 DEBUG("Exiting server after timeout waiting for client command"); 2352 goto done; 2353 } 2324 2354 /* Handle all the pending setting changes now. */ 2325 2355 UpdateSettings(p); … … 2434 2464 size_t numBytes; 2435 2465 2466 while (1) { 2467 int c = getopt(argc, argv, "t:"); 2468 if (c == -1) { 2469 break; 2470 } 2471 switch (c) { 2472 case 't': 2473 idleTimeout = atol(optarg); 2474 break; 2475 case '?': 2476 break; 2477 default: 2478 return 1; 2479 } 2480 } 2481 2436 2482 frecord = NULL; 2437 2483 if (recording) { … … 2451 2497 openlog("pymolproxy", LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER); 2452 2498 DEBUG("Starting pymolproxy"); 2453 2454 InitProxy(&proxy, argv + 1); 2499 DEBUG("Idle timeout: %ld", idleTimeout); 2500 2501 InitProxy(&proxy, argv + optind); 2455 2502 if (pthread_create(&thread1, NULL, &ClientToServer, &proxy) < 0) { 2456 2503 ERROR("Can't create reader thread: %s", strerror(errno));
Note: See TracChangeset
for help on using the changeset viewer.