Changeset 6568


Ignore:
Timestamp:
Nov 3, 2016, 10:57:57 PM (8 years ago)
Author:
ldelgass
Message:

Add optional idle timeout to vtkvis server. Allows server to close connection
and exit after a specified period without commands from the client.

Location:
vtkvis/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • vtkvis/trunk/RenderServer.cpp

    r6383 r6568  
    482482    signal(SIGPIPE, SIG_IGN);
    483483
     484    long idleTimeout = -1L;
    484485    while (1) {
    485         int c = getopt(argc, argv, "i:o:");
     486        int c = getopt(argc, argv, "i:o:t:");
    486487        if (c == -1) {
    487488            break;
     
    502503        }
    503504            break;
     505        case 't':
     506            // Idle timeout in seconds
     507            idleTimeout = atol(optarg);
     508            break;
    504509        case '?':
    505510            break;
     
    543548    g_inBufPtr = new ReadBuffer(g_fdIn, 1<<12);
    544549
     550    g_renderer->setIdleTimeout(idleTimeout);
     551
    545552    Tcl_Interp *interp = Tcl_CreateInterp();
    546553    ClientData clientData = NULL;
     
    563570    // Start main server loop
    564571    for (;;) {
    565         if (processCommands(interp, clientData, g_inBufPtr, g_fdOut) < 0)
     572        struct timeval timeout;
     573        g_renderer->getTimeout(&timeout);
     574        int cmdStatus = processCommands(interp, clientData, g_inBufPtr, g_fdOut, &timeout);
     575        if (cmdStatus < 0)
    566576            break;
    567577
     
    577587            g_stats.nFrameBytes += imgData->GetDataSize() * imgData->GetDataTypeSize();
    578588        } else {
    579             TRACE("No render required");
    580             sendAck(clientData, g_fdOut);
     589            if (cmdStatus > 1) {
     590                sendAck(clientData, g_fdOut);
     591            } else {
     592                TRACE("No render required and status = %d", cmdStatus);
     593            }
    581594        }
    582595
  • vtkvis/trunk/Renderer.cpp

    r6554 r6568  
    7676    _needsCameraClippingRangeReset(false),
    7777    _needsCameraReset(false),
     78    _idleTimeout(-1L),
    7879    _windowWidth(500),
    7980    _windowHeight(500),
     
    46464647
    46474648/**
     4649 * \brief Get a timeout for select()
     4650 *
     4651 * For now, this just returns the idle timeout, if set.
     4652 *
     4653 * Potentially, this could be used to set a timeout based on the "unused" frame
     4654 * time from the previous render based on a target frame rate (and polling if
     4655 * we broke frame).
     4656 */
     4657void Renderer::getTimeout(struct timeval *tv)
     4658{
     4659    tv->tv_sec = _idleTimeout;
     4660    tv->tv_usec = 0L;
     4661}
     4662
     4663/**
    46484664 * \brief Cause the rendering to render a new image if needed
    46494665 *
  • vtkvis/trunk/Renderer.h

    r4814 r6568  
    984984    void setWarpWarpScale(const DataSetId& id, double scale);
    985985
     986    void setIdleTimeout(long timeout)
     987    {
     988        TRACE("Setting idle timeout to %ld sec", timeout);
     989        _idleTimeout = timeout;
     990    }
     991
     992    long getIdleTimeout()
     993    {
     994        return _idleTimeout;
     995    }
     996
     997    void getTimeout(struct timeval *tv);
     998
    986999private:
    9871000    typedef std::tr1::unordered_map<DataSetId, DataSet *> DataSetHashmap;
     
    10861099    bool _needsCameraClippingRangeReset;
    10871100    bool _needsCameraReset;
     1101
     1102    long _idleTimeout;
    10881103
    10891104    int _windowWidth, _windowHeight;
  • vtkvis/trunk/RendererCmd.cpp

    r6384 r6568  
    1307013070                        ClientData clientData,
    1307113071                        ReadBuffer *inBufPtr,
    13072                         int fdOut)
     13072                        int fdOut,
     13073                        struct timeval *timeout)
    1307313074{
    1307413075    int ret = 1;
     
    1308213083    FD_ZERO(&readFds);
    1308313084    FD_SET(inBufPtr->file(), &readFds);
    13084     tvPtr = NULL;                       /* Wait for the first read. This is so
    13085                                          * that we don't spin when no data is
    13086                                          * available. */
    13087     while (inBufPtr->isLineAvailable() ||
    13088            (select(inBufPtr->file()+1, &readFds, NULL, NULL, tvPtr) > 0)) {
     13085
     13086    bool polling = false;
     13087    if (timeout->tv_sec >= 0L) {
     13088        tv.tv_sec = timeout->tv_sec;
     13089        tv.tv_usec = timeout->tv_usec;
     13090        polling = tv.tv_sec == 0 && tv.tv_usec == 0;
     13091        tvPtr = &tv;
     13092    } else {
     13093        // Block until data available
     13094        tvPtr = NULL;
     13095        TRACE("Blocking on select()");
     13096    }
     13097    while (inBufPtr->isLineAvailable() ||
     13098           ((ret = select(inBufPtr->file()+1, &readFds, NULL, NULL, tvPtr)) > 0)) {
    1308913099        size_t numBytes;
    1309013100        unsigned char *buffer;
     
    1312313133                }
    1312413134            }
     13135            if (status == TCL_OK) {
     13136                ret = 3;
     13137            }
    1312513138        }
    1312613139
     13140        polling = true;
    1312713141        tv.tv_sec = tv.tv_usec = 0L;    /* On successive reads, we break out
    1312813142                                         * if no data is available. */
    1312913143        FD_SET(inBufPtr->file(), &readFds);
    1313013144        tvPtr = &tv;
     13145    }
     13146    if (!polling && ret == 0 && timeout->tv_sec > 0L) {
     13147        // If idle timeout expired, disconnect
     13148        TRACE("Exiting server after timeout waiting for client command");
     13149        return -1;
    1313113150    }
    1313213151
  • vtkvis/trunk/RendererCmd.h

    r3621 r6568  
    99#define VTKVIS_RENDERERCMD_H
    1010
     11#include <sys/time.h>
    1112#include <cstdio>
    1213#include <tcl.h>
     
    2829                           ClientData clientData,
    2930                           ReadBuffer *inBufPtr,
    30                            int fdOut);
     31                           int fdOut,
     32                           struct timeval *timeout);
    3133
    3234extern int handleError(Tcl_Interp *interp,
Note: See TracChangeset for help on using the changeset viewer.