Changeset 2551 for branches


Ignore:
Timestamp:
Sep 21, 2011, 7:06:23 PM (13 years ago)
Author:
gah
Message:

initial buffered read implementation

Location:
branches/vtkvis_threaded
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/vtkvis_threaded/Makefile.in

    r2523 r2551  
    8484                ColorMap.cpp \
    8585                PPMWriter.cpp \
     86                ReadBuffer.cpp \
    8687                RpContour2D.cpp \
    8788                RpContour3D.cpp \
  • branches/vtkvis_threaded/RpVtkRenderServer.cpp

    r2498 r2551  
    2222
    2323#include "Trace.h"
     24#include "ReadBuffer.h"
    2425#include "RpVtkRenderServer.h"
    2526#include "RpVtkRendererCmd.h"
     
    4041FILE *Rappture::VtkVis::g_fLog = NULL; ///< Trace logging file handle
    4142Renderer *Rappture::VtkVis::g_renderer = NULL; ///< Main render worker
     43ReadBuffer *Rappture::VtkVis::g_inBufPtr;
    4244
    4345#define ELAPSED_TIME(t1, t2) \
     
    247249    vtkSmartPointer<vtkUnsignedCharArray> imgData =
    248250        vtkSmartPointer<vtkUnsignedCharArray>::New();
     251    ReadBuffer inBuf(fileno(g_fIn), 1<<12);
     252    g_inBufPtr = &inBuf;
    249253    for (;;) {
    250254        int ret;
    251255
    252         ret = processCommands(interp, g_fIn, g_fOut);
     256        ret = processCommands(interp, &inBuf, g_fOut);
    253257        if (ret < 0)
    254258            break;
     
    260264            TRACE("No render required");
    261265        }
    262         if (feof(g_fIn))
     266        if (inBuf.status() == ReadBuffer::ENDFILE)
    263267            break;
    264268    }   
     
    340344    vtkSmartPointer<vtkUnsignedCharArray> imgData =
    341345        vtkSmartPointer<vtkUnsignedCharArray>::New();
     346    ReadBuffer inBuf(fileno(g_fIn), 1<<12);
     347    g_inBufPtr = &inBuf;
    342348    while (1) {
    343         ret = processCommands(interp, g_fIn, g_fOut);
     349        ret = processCommands(interp, &inBuf, g_fOut);
    344350        if (ret < 0)
    345351            break;
     
    353359        }
    354360
    355         if (feof(g_fIn))
     361        if (inBuf.status() == ReadBuffer::ENDFILE)
    356362            break;
    357363    }
     
    371377    return 0;
    372378}
    373 
  • branches/vtkvis_threaded/RpVtkRenderServer.h

    r2523 r2551  
    2020extern FILE *g_fLog;
    2121extern Renderer *g_renderer;
     22extern ReadBuffer *g_inBufPtr;
    2223
    2324}
  • branches/vtkvis_threaded/RpVtkRendererCmd.cpp

    r2523 r2551  
    1919#include "Trace.h"
    2020#include "CmdProc.h"
     21#include "ReadBuffer.h"
    2122#include "RpVtkRendererCmd.h"
    2223#include "RpVtkRenderServer.h"
     
    6566#endif  /*USE_THREADS*/
    6667
    67 static size_t
    68 SocketRead(void *bytes, size_t len)
    69 {
    70 #ifdef notdef
    71     size_t ofs = 0;
    72     ssize_t bytesRead = 0;
    73     while ((bytesRead = read(g_fdIn, bytes + ofs, len - ofs)) > 0) {
    74         ofs += bytesRead;
    75         if (ofs == len)
    76             break;
    77     }
    78     TRACE("bytesRead: %lu", ofs);
    79     return ofs;
    80 #else
    81     size_t bytesRead = fread(bytes, 1, len, g_fIn);
    82     TRACE("bytesRead: %lu", bytesRead);
    83     return bytesRead;
    84 #endif
     68static bool
     69SocketRead(char *bytes, size_t len)
     70{
     71    ReadBuffer::BufferStatus status;
     72    status = g_inBufPtr->FollowingData((unsigned char *)bytes, len);
     73    TRACE("bytesRead: %lu", status);
     74    return (status == ReadBuffer::OK);
    8575}
    8676
     
    16881678    }
    16891679    char *data = (char *)malloc(nbytes);
    1690     size_t bytesRead = SocketRead(data, nbytes);
    1691     if (bytesRead < (size_t)nbytes) {
     1680    if (!SocketRead(data, nbytes)) {
    16921681        free(data);
    16931682        return TCL_ERROR;
     
    47674756    }
    47684757    char *data = (char *)malloc(nbytes);
    4769     size_t bytesRead = SocketRead(data, nbytes);
    4770     if (bytesRead < (size_t)nbytes) {
     4758    if (!SocketRead(data, nbytes)) {
    47714759        free(data);
    47724760        return TCL_ERROR;
     
    48164804    }
    48174805    char *data = (char *)malloc(nbytes);
    4818     size_t bytesRead = SocketRead(data, nbytes);
    4819     if (bytesRead < (size_t)nbytes) {
     4806    if (!SocketRead(data, nbytes)) {
    48204807        free(data);
    48214808        return TCL_ERROR;
     
    53645351 */
    53655352int
    5366 Rappture::VtkVis::processCommands(Tcl_Interp *interp, FILE *fin, FILE *fout)
     5353Rappture::VtkVis::processCommands(Tcl_Interp *interp, ReadBuffer *inBufPtr,
     5354                                  FILE *fout)
    53675355{
    53685356    int status = TCL_OK;
    5369 
    5370 #define BUFFERSIZE   ((1<<16)-1)
    5371     char buffer[BUFFERSIZE+1];
    53725357
    53735358    Tcl_DString command;
    53745359    Tcl_DStringInit(&command);
    5375 
    53765360    fd_set readFds;
    53775361    struct timeval tv, *tvPtr;
    53785362
    53795363    FD_ZERO(&readFds);
    5380     FD_SET(fileno(fin), &readFds);
     5364    FD_SET(inBufPtr->file(), &readFds);
    53815365    tvPtr = NULL;                       /* Initially there is no timeout. */
    5382     while (select(1, &readFds, NULL, NULL, tvPtr) > 0) {
    5383         if (fgets(buffer, BUFFERSIZE, fin) == NULL) {
    5384             /* Terminate the server if we can't
    5385              * communicate with the client
     5366    while ((inBufPtr->IsLineAvailable()) ||
     5367           ((select(1, &readFds, NULL, NULL, tvPtr) > 0))) {
     5368        size_t numBytes;
     5369        unsigned char *buffer;
     5370
     5371        if (inBufPtr->GetLine(&numBytes, &buffer) != ReadBuffer::OK) {
     5372            /* Terminate the server if we can't communicate with the client
    53865373             * anymore. */
    5387             if (feof(fin)) {
     5374            if (inBufPtr->status() == ReadBuffer::ENDFILE) {
    53885375                INFO("Exiting server on EOF from client");
    53895376                exit(0);
     
    53945381            }
    53955382        }
    5396         buffer[BUFFERSIZE] = '\0';
    5397         Tcl_DStringAppend(&command, buffer, -1);
     5383        Tcl_DStringAppend(&command, (char *)buffer, numBytes);
    53985384        if (Tcl_CommandComplete(Tcl_DStringValue(&command))) {
    53995385            status = ExecuteCommand(interp, &command);
     
    54065392        }
    54075393        tv.tv_sec = tv.tv_usec = 0L;
    5408         FD_SET(fileno(fin), &readFds);
     5394        FD_SET(inBufPtr->file(), &readFds);
    54095395        tvPtr = &tv;
    54105396    }
  • branches/vtkvis_threaded/RpVtkRendererCmd.h

    r2495 r2551  
    1111#include <cstdio>
    1212#include <tcl.h>
     13#include "ReadBuffer.h"
    1314
    1415namespace Rappture {
    1516namespace VtkVis {
    1617
    17 extern int processCommands(Tcl_Interp *interp, FILE *fin, FILE *fout);
     18extern int processCommands(Tcl_Interp *interp, ReadBuffer *inBufPtr,
     19        FILE *fout);
    1820extern void initTcl(Tcl_Interp *interp, ClientData clientData);
    1921extern void exitTcl(Tcl_Interp *interp);
Note: See TracChangeset for help on using the changeset viewer.