Changeset 6619


Ignore:
Timestamp:
Nov 14, 2016 11:35:41 AM (7 years ago)
Author:
ldelgass
Message:

merge r6576:6577 from nanovis trunk (timeout option)

Location:
nanovis/branches/1.2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • nanovis/branches/1.2

  • nanovis/branches/1.2/Command.cpp

    r6392 r6619  
    23402340int
    23412341nv::processCommands(Tcl_Interp *interp,
    2342                     ReadBuffer *inBufPtr, int fdOut)
     2342                    ReadBuffer *inBufPtr,
     2343                    int fdOut,
     2344                    struct timeval *timeout)
    23432345{
    23442346    int ret = 1;
     
    23522354    FD_ZERO(&readFds);
    23532355    FD_SET(inBufPtr->file(), &readFds);
    2354     tvPtr = NULL;                       /* Wait for the first read. This is so
    2355                                          * that we don't spin when no data is
    2356                                          * available. */
     2356
     2357    bool polling = false;
     2358    if (timeout->tv_sec >= 0L) {
     2359        tv.tv_sec = timeout->tv_sec;
     2360        tv.tv_usec = timeout->tv_usec;
     2361        polling = tv.tv_sec == 0 && tv.tv_usec == 0;
     2362        tvPtr = &tv;
     2363    } else {
     2364        // Block until data available
     2365        tvPtr = NULL;
     2366        TRACE("Blocking on select()");
     2367    }
    23572368    while (inBufPtr->isLineAvailable() ||
    2358            (select(inBufPtr->file()+1, &readFds, NULL, NULL, tvPtr) > 0)) {
     2369           ((ret = select(inBufPtr->file()+1, &readFds, NULL, NULL, tvPtr)) > 0)) {
    23592370        size_t numBytes;
    23602371        unsigned char *buffer;
     
    23932404                }
    23942405            }
    2395         }
    2396 
     2406            if (status == TCL_OK) {
     2407                ret = 3;
     2408            }
     2409        }
     2410
     2411        polling = true;
    23972412        tv.tv_sec = tv.tv_usec = 0L;    /* On successive reads, we break out
    23982413                                         * if no data is available. */
    23992414        FD_SET(inBufPtr->file(), &readFds);
    24002415        tvPtr = &tv;
     2416    }
     2417    if (!polling && ret == 0 && timeout->tv_sec > 0L) {
     2418        // If idle timeout expired, disconnect
     2419        TRACE("Exiting server after timeout waiting for client command");
     2420        return -1;
    24012421    }
    24022422
  • nanovis/branches/1.2/Command.h

    r5603 r6619  
    1313
    1414#include <unistd.h>
     15#include <sys/time.h>
    1516
    1617#include <tcl.h>
     
    4445extern int processCommands(Tcl_Interp *interp,
    4546                           ReadBuffer *inBufPtr,
    46                            int fdOut);
     47                           int fdOut,
     48                           struct timeval *timeout);
    4749
    4850extern int handleError(Tcl_Interp *interp,
  • nanovis/branches/1.2/nanovisServer.cpp

    r6395 r6619  
    5757ResponseQueue *nv::g_queue = NULL;
    5858#endif
     59long nv::g_idleTimeout = -1L;
    5960
    6061#ifdef USE_THREADS
     
    385386
    386387#if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS)
    387     if (processCommands(NanoVis::interp, g_inBufPtr, g_fdOut) < 0) {
     388    struct timeval timeout;
     389    timeout.tv_sec = g_idleTimeout;
     390    timeout.tv_usec = 0L;
     391    if (processCommands(NanoVis::interp, g_inBufPtr, g_fdOut, &timeout) < 0) {
    388392        exitService(1);
    389393    }
     
    477481    const char *resourcePath = NULL;
    478482    while (1) {
    479         static struct option long_options[] = {
    480             {"debug",   no_argument,       NULL, 'd'},
    481             {"path",    required_argument, NULL, 'p'},
    482             {0, 0, 0, 0}
    483         };
    484         int option_index = 0;
    485         int c = getopt_long(argc, argv, "dp:i:o:", long_options, &option_index);
     483        int c = getopt(argc, argv, "dp:i:o:t:");
    486484        if (c == -1) {
    487485            break;
     
    507505            }
    508506        }
     507            break;
     508        case 't':
     509            // Idle timeout in seconds
     510            g_idleTimeout = atol(optarg);
    509511            break;
    510512        case '?':
  • nanovis/branches/1.2/nanovisServer.h

    r6393 r6619  
    5050    extern ResponseQueue *g_queue;
    5151#endif
     52    extern long g_idleTimeout;
    5253
    5354#ifdef KEEPSTATS
Note: See TracChangeset for help on using the changeset viewer.