Changeset 6629 for pymolproxy


Ignore:
Timestamp:
Nov 14, 2016 6:28:38 PM (8 years ago)
Author:
ldelgass
Message:

Add idle timeout option to pymolproxy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pymolproxy/trunk/pymolproxy.c

    r6617 r6629  
    104104static int pymolIsAlive = TRUE;
    105105static int statsFile = -1;
     106static long idleTimeout = -1L;
    106107
    107108#define READ_DEBUG  1
     
    22662267    PymolProxy *p = clientData;
    22672268    Tcl_DString command;
     2269    fd_set readFds;
     2270    int ret = 1;
    22682271    struct timeval tv, *tvPtr;
     2272    int polling = 0;
    22692273
    22702274#if READ_DEBUG
     
    22732277    Tcl_DStringInit(&command);
    22742278    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        }
    22762290#if READ_DEBUG
    22772291        DEBUG("Start I/O set");
    22782292#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)) {
    22802296            size_t numBytes;
    22812297            const char *line;
     
    23022318                    DEBUG("TCL_BREAK found");
    23032319#endif
     2320                    ret = 2;
    23042321                    break;              /* This was caused by a "imgflush"
    23052322                                         * command. Break out of the read
    23062323                                         * loop and allow a new image to be
    23072324                                         * rendered. */
     2325                } else if (result != TCL_OK) {
     2326                    ret = 0;
     2327                } else {
     2328                    ret = 3;
    23082329                }
    23092330                if (p->flags & FORCE_UPDATE) {
     
    23142335                }
    23152336            }
     2337            polling = 1;
    23162338            tv.tv_sec = 0L;
    23172339            tv.tv_usec = 0L;            /* On successive reads, we break
    23182340                                         * out if no data is available. */
     2341            FD_SET(p->client.fd, &readFds);
    23192342            tvPtr = &tv;
    23202343        }
     
    23222345        DEBUG("Finish I/O set");
    23232346#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        }
    23242356        /* Handle all the pending setting changes now. */
    23252357        UpdateSettings(p);
     
    24342466    size_t numBytes;
    24352467
     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
    24362484    frecord = NULL;
    24372485    if (recording) {
     
    24522500    DEBUG("Starting pymolproxy");
    24532501
    2454     InitProxy(&proxy, argv + 1);
     2502    InitProxy(&proxy, argv + optind);
    24552503    if (pthread_create(&thread1, NULL, &ClientToServer, &proxy) < 0) {
    24562504        ERROR("Can't create reader thread: %s", strerror(errno));
Note: See TracChangeset for help on using the changeset viewer.