Changeset 6620 for nanovis


Ignore:
Timestamp:
Nov 14, 2016, 3:00:15 PM (2 years ago)
Author:
ldelgass
Message:

remove old read loop in nanovis

Location:
nanovis/branches/1.2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • nanovis/branches/1.2/Command.cpp

    r6619 r6620  
    3737#include <unistd.h>                     /* Needed for getpid, gethostname,
    3838                                         * write, etc. */
    39 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS)
    40 #include <fcntl.h>
    41 #endif
     39
    4240#include <sstream>
    4341
     
    538536nv::GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes)
    539537{
    540 #if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS)
    541538    if (!SocketRead((char *)buf.bytes(), nBytes)) {
    542539        return TCL_ERROR;
    543540    }
    544541    buf.count(nBytes);
    545 #else
    546     char buffer[8096];
    547 
    548     clearerr(g_fIn);
    549     while (nBytes > 0) {
    550         unsigned int chunk;
    551         int nRead;
    552 
    553         chunk = (sizeof(buffer) < (unsigned int) nBytes) ?
    554             sizeof(buffer) : nBytes;
    555         nRead = fread(buffer, sizeof(char), chunk, g_fIn);
    556         if (ferror(g_fIn)) {
    557             Tcl_AppendResult(interp, "while reading data stream: ",
    558                              Tcl_PosixError(interp), (char*)NULL);
    559             return TCL_ERROR;
    560         }
    561         if (feof(g_fIn)) {
    562             Tcl_AppendResult(interp, "premature EOF while reading data stream",
    563                              (char*)NULL);
    564             return TCL_ERROR;
    565         }
    566         buf.append(buffer, nRead);
    567         nBytes -= nRead;
    568     }
    569 #endif
    570542    Rappture::Outcome err;
    571543    TRACE("Checking header [%.13s]", buf.bytes());
     
    22512223}
    22522224
    2253 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS)
    2254 int
    2255 nv::processCommands(Tcl_Interp *interp, FILE *inFile, int fdOut)
    2256 {
    2257     int ret = 0;
    2258     int status = TCL_OK;
    2259 
    2260     Tcl_DString cmdbuffer;
    2261     Tcl_DStringInit(&cmdbuffer);
    2262 
    2263     int flags = fcntl(0, F_GETFL, 0);
    2264     fcntl(0, F_SETFL, flags & ~O_NONBLOCK);
    2265 
    2266     //  Read and execute as many commands as we can from stdin...
    2267     bool isComplete = false;
    2268     while ((!feof(inFile)) && (status == TCL_OK)) {
    2269         //
    2270         //  Read the next command from the buffer.  First time through we
    2271         //  block here and wait if necessary until a command comes in.
    2272         //
    2273         //  BE CAREFUL: Read only one command, up to a newline.  The "volume
    2274         //  data follows" command needs to be able to read the data
    2275         //  immediately following the command, and we shouldn't consume it
    2276         //  here.
    2277         //
    2278         while (!feof(inFile)) {
    2279             int c = fgetc(inFile);
    2280             char ch;
    2281             if (c <= 0) {
    2282                 if (errno == EWOULDBLOCK) {
    2283                     break;
    2284                 }
    2285                 return -1;
    2286             }
    2287             ch = (char)c;
    2288             Tcl_DStringAppend(&cmdbuffer, &ch, 1);
    2289             if (ch == '\n') {
    2290                 isComplete = Tcl_CommandComplete(Tcl_DStringValue(&cmdbuffer));
    2291                 if (isComplete) {
    2292                     break;
    2293                 }
    2294             }
    2295         }
    2296         // no command? then we're done for now
    2297         if (Tcl_DStringLength(&cmdbuffer) == 0) {
    2298             break;
    2299         }
    2300         if (isComplete) {
    2301             // back to original flags during command evaluation...
    2302             fcntl(0, F_SETFL, flags & ~O_NONBLOCK);
    2303             struct timeval start, finish;
    2304             gettimeofday(&start, NULL);
    2305             status = ExecuteCommand(interp, &cmdbuffer);
    2306             gettimeofday(&finish, NULL);
    2307             // non-blocking for next read -- we might not get anything
    2308             fcntl(0, F_SETFL, flags | O_NONBLOCK);
    2309             isComplete = false;
    2310             g_stats.cmdTime += (MSECS_ELAPSED(start, finish) / 1.0e+3);
    2311             g_stats.nCommands++;
    2312         }
    2313     }
    2314     fcntl(0, F_SETFL, flags);
    2315 
    2316     if (status != TCL_OK) {
    2317         if (handleError(interp, status, fdOut) < 0) {
    2318             return -1;
    2319         }
    2320         TRACE("Leaving on ERROR");
    2321     }
    2322 
    2323     return ret;
    2324 }
    2325 
    2326 #endif
    2327 
    23282225/**
    23292226 * \brief Execute commands from client in Tcl interpreter
  • nanovis/branches/1.2/Command.h

    r6619 r6620  
    3838extern bool SocketRead(char *bytes, size_t len);
    3939
    40 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS)
    41 extern int processCommands(Tcl_Interp *interp,
    42                            FILE *inBufPtr,
    43                            int fdOut);
    44 #endif
    4540extern int processCommands(Tcl_Interp *interp,
    4641                           ReadBuffer *inBufPtr,
  • nanovis/branches/1.2/config.h

    r5394 r6620  
    4949#define KEEPSTATS
    5050
    51 //#define USE_NEW_EVENT_LOOP
    52 
    5351/*
    5452 * Controls whether DX data is downsampled.
  • nanovis/branches/1.2/nanovisServer.cpp

    r6619 r6620  
    5050int nv::g_fdIn = STDIN_FILENO;     ///< Input file descriptor
    5151int nv::g_fdOut = STDOUT_FILENO;   ///< Output file descriptor
    52 FILE *nv::g_fIn = NULL;            ///< Input file handle
    5352FILE *nv::g_fOut = NULL;           ///< Output file handle
    5453FILE *nv::g_fLog = NULL;           ///< Trace logging file handle
     
    315314initService()
    316315{
    317     g_fIn = fdopen(g_fdIn, "r");
    318316    // Create a stream associated with the output file descriptor
    319317    g_fOut = fdopen(g_fdOut, "w");
     
    385383    glutSetWindow(NanoVis::renderWindow);
    386384
    387 #if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS)
    388385    struct timeval timeout;
    389386    timeout.tv_sec = g_idleTimeout;
     
    392389        exitService(1);
    393390    }
    394 #else
    395     if (processCommands(NanoVis::interp, g_fIn, g_fdOut) < 0) {
    396         exitService(1);
    397     }
    398 #endif
    399391
    400392    NanoVis::update();
     
    417409    }
    418410
    419 #if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS)
    420411    if (g_inBufPtr->status() == ReadBuffer::ENDFILE) {
    421412        exitService(0);
    422413    }
    423 #else
    424     if (feof(g_fIn)) {
    425         exitService(0);
    426     }
    427 #endif
    428414
    429415    TRACE("Leave");
     
    547533    fflush(g_fOut);
    548534
    549 #if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS)
    550535    g_inBufPtr = new ReadBuffer(g_fdIn, 1<<12);
    551 #endif
    552536
    553537    Tcl_Interp *interp = Tcl_CreateInterp();
  • nanovis/branches/1.2/nanovisServer.h

    r6619 r6620  
    4343    extern int g_fdIn;             ///< Input file descriptor
    4444    extern int g_fdOut;            ///< Output file descriptor
    45     extern FILE *g_fIn;            ///< Input file handle
    4645    extern FILE *g_fOut;           ///< Output file handle
    4746    extern FILE *g_fLog;           ///< Trace logging file handle
Note: See TracChangeset for help on using the changeset viewer.