Changeset 6635


Ignore:
Timestamp:
Nov 15, 2016 12:59:43 AM (7 years ago)
Author:
ldelgass
Message:

merge from pymolproxy trunk

Location:
pymolproxy/branches/1.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pymolproxy/branches/1.0

  • pymolproxy/branches/1.0/pymolproxy.c

    r6628 r6635  
    104104static int pymolIsAlive = TRUE;
    105105static int statsFile = -1;
     106static long idleTimeout = -1L;
    106107
    107108#define READ_DEBUG  1
     
    121122#define VIEWPORT_PENDING        (1<<10)
    122123
    123 #define IO_TIMEOUT (30000)
    124124#define CLIENT_READ  STDIN_FILENO
    125125#define CLIENT_WRITE STDOUT_FILENO
     
    20642064    ERROR("pymol (%d) died unexpectedly", stats.pid);
    20652065    pymolIsAlive = FALSE;
    2066     /*DoExit(1);*/
    20672066}
    20682067
     
    22322231    }
    22332232
    2234     DEBUG("attempting to signal (SIGTERM) pymol server.");
     2233    DEBUG("Attempting to signal (SIGTERM) pymol server.");
    22352234    kill(-p->pid, SIGTERM); /* Kill process group */
    22362235    alarm(5);
     
    22662265    PymolProxy *p = clientData;
    22672266    Tcl_DString command;
     2267    fd_set readFds;
     2268    int ret = 1;
    22682269    struct timeval tv, *tvPtr;
     2270    int polling = 0;
    22692271
    22702272#if READ_DEBUG
     
    22732275    Tcl_DStringInit(&command);
    22742276    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        }
    22762288#if READ_DEBUG
    22772289        DEBUG("Start I/O set");
    22782290#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)) {
    22802294            size_t numBytes;
    22812295            const char *line;
     
    23022316                    DEBUG("TCL_BREAK found");
    23032317#endif
     2318                    ret = 2;
    23042319                    break;              /* This was caused by a "imgflush"
    23052320                                         * command. Break out of the read
    23062321                                         * loop and allow a new image to be
    23072322                                         * rendered. */
     2323                } else if (result != TCL_OK) {
     2324                    ret = 0;
     2325                } else {
     2326                    ret = 3;
    23082327                }
    23092328                if (p->flags & FORCE_UPDATE) {
     
    23142333                }
    23152334            }
     2335            polling = 1;
    23162336            tv.tv_sec = 0L;
    23172337            tv.tv_usec = 0L;            /* On successive reads, we break
    23182338                                         * out if no data is available. */
     2339            FD_SET(p->client.fd, &readFds);
    23192340            tvPtr = &tv;
    23202341        }
     
    23222343        DEBUG("Finish I/O set");
    23232344#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        }
    23242354        /* Handle all the pending setting changes now. */
    23252355        UpdateSettings(p);
     
    24342464    size_t numBytes;
    24352465
     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
    24362482    frecord = NULL;
    24372483    if (recording) {
     
    24512497    openlog("pymolproxy", LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER);
    24522498    DEBUG("Starting pymolproxy");
    2453 
    2454     InitProxy(&proxy, argv + 1);
     2499    DEBUG("Idle timeout: %ld", idleTimeout);
     2500
     2501    InitProxy(&proxy, argv + optind);
    24552502    if (pthread_create(&thread1, NULL, &ClientToServer, &proxy) < 0) {
    24562503        ERROR("Can't create reader thread: %s", strerror(errno));
Note: See TracChangeset for help on using the changeset viewer.