Ignore:
Timestamp:
May 10, 2013 3:31:17 PM (11 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/pymolproxy/pymolproxy.c

    r3412 r3644  
    8787typedef struct {
    8888    pid_t child;                /* Child process. */
    89     size_t nFrames;             /* # of frames sent to client. */
    90     size_t nBytes;              /* # of bytes for all frames. */
    91     size_t nCommands;           /* # of commands executed */
     89    size_t numFrames;           /* # of frames sent to client. */
     90    size_t numBytes;            /* # of bytes for all frames. */
     91    size_t numCommands;         /* # of commands executed */
    9292    double cmdTime;             /* Elapsed time spend executing commands. */
    9393    struct timeval start;       /* Start of elapsed time. */
     
    115115                                         * most recently received image from
    116116                                         * the pymol server to the least. */
    117     ssize_t nWritten;                   /* Number of bytes of image data
     117    ssize_t numWritten;                 /* Number of bytes of image data
    118118                                         * already delivered.*/
    119119    size_t bytesLeft;                   /* Number of bytes of image data left
     
    335335 *      If insufficient data is in the buffer, then the channel is
    336336 *      read for more data.  If reading the channel results in a
    337  *      short read, NULL is returned and *nBytesPtr is set to
     337 *      short read, NULL is returned and *numBytesPtr is set to
    338338 *      BUFFER_CONTINUE.
    339339 */
    340340static char *
    341 NextLine(ReadBuffer *readPtr, int *nBytesPtr)
     341NextLine(ReadBuffer *readPtr, int *numBytesPtr)
    342342{
    343343    int i;
     
    361361                p = readPtr->bytes + readPtr->mark;
    362362                i++;                    /* Include the newline. */
    363                 *nBytesPtr = i - readPtr->mark;
     363                *numBytesPtr = i - readPtr->mark;
    364364                readPtr->mark = i;
    365365#if READTRACE
    366                 Debug("Leaving NextLine(%.*s)\n", *nBytesPtr, p);
     366                Debug("Leaving NextLine(%.*s)\n", *numBytesPtr, p);
    367367#endif
    368368                return p;
     
    372372         * more. Check first that last read wasn't a short read. */
    373373        if (status == BUFFER_CONTINUE) {
    374             *nBytesPtr = BUFFER_CONTINUE;  /* No complete line just yet. */
     374            *numBytesPtr = BUFFER_CONTINUE;  /* No complete line just yet. */
    375375            return NULL;
    376376        }
     
    378378        status = FillBuffer(readPtr);
    379379        if (status == BUFFER_ERROR) {
    380             *nBytesPtr = BUFFER_ERROR;
     380            *numBytesPtr = BUFFER_ERROR;
    381381            return NULL;        /* EOF or error on read. */
    382382        }
     
    386386    Debug("Leaving NextLine failed to read line\n");
    387387#endif
    388     *nBytesPtr = BUFFER_CONTINUE;
     388    *numBytesPtr = BUFFER_CONTINUE;
    389389    return NULL;
    390390}
     
    398398 */
    399399static int
    400 ReadFollowingData(ReadBuffer *readPtr, char *out, int nBytes)
     400ReadFollowingData(ReadBuffer *readPtr, char *out, int numBytes)
    401401{
    402402#if READTRACE
    403     Debug("Entering ReadFollowingData(%d)\n", nBytes);
     403    Debug("Entering ReadFollowingData(%d)\n", numBytes);
    404404#endif
    405     while (nBytes > 0) {
     405    while (numBytes > 0) {
    406406        int bytesLeft;
    407407        int status;
     
    412412
    413413            /* Pull bytes out of the buffer, updating the mark. */
    414             size = (bytesLeft >  nBytes) ? nBytes : bytesLeft;
     414            size = (bytesLeft >  numBytes) ? numBytes : bytesLeft;
    415415            memcpy(out, readPtr->bytes + readPtr->mark, size);
    416416            readPtr->mark += size;
    417             nBytes -= size;
     417            numBytes -= size;
    418418            out += size;
    419419        }
    420         if (nBytes == 0) {
     420        if (numBytes == 0) {
    421421            /* Received requested # bytes. */
    422422#if READTRACE
    423             Debug("Leaving ReadFollowingData(%d)\n", nBytes);
     423            Debug("Leaving ReadFollowingData(%d)\n", numBytes);
    424424#endif
    425425            return BUFFER_OK;
     
    436436    }
    437437#if READTRACE
    438     Debug("Leaving ReadFollowingData(%d)\n", nBytes);
     438    Debug("Leaving ReadFollowingData(%d)\n", numBytes);
    439439#endif
    440440    return BUFFER_OK;
     
    463463    length = strlen(match);
    464464    for (;;) {
    465         int nBytes;
     465        int numBytes;
    466466        char *line;
    467467
    468         line = NextLine(&proxyPtr->server, &nBytes);
     468        line = NextLine(&proxyPtr->server, &numBytes);
    469469        if (line != NULL) {
    470470#if EXPECTTRACE
    471             Debug("pymol says (read %d bytes):%.*s", nBytes, nBytes, line);
     471            Debug("pymol says (read %d bytes):%.*s", numBytes, numBytes, line);
    472472#endif
    473473            if ((c == line[0]) && (strncmp(line, match, length) == 0)) {
    474                 if (maxSize < nBytes) {
    475                     nBytes = maxSize;
     474                if (maxSize < numBytes) {
     475                    numBytes = maxSize;
    476476                }
    477                 memcpy(out, line, nBytes);
     477                memcpy(out, line, numBytes);
    478478                clear_error(proxyPtr);
    479479#if EXPECTTRACE
    480                 Debug("Leaving Expect: got (%.*s)\n", nBytes, out);
     480                Debug("Leaving Expect: got (%.*s)\n", numBytes, out);
    481481#endif
    482482                return TCL_OK;
     
    484484            continue;
    485485        }
    486         if (nBytes == BUFFER_ERROR) {
     486        if (numBytes == BUFFER_ERROR) {
    487487            Tcl_AppendResult(proxyPtr->interp,
    488488                "error reading server to find match for \"", match, "\": ",
     
    548548    sprintf(buf, "pid=\"%d\" ", pid);
    549549    Tcl_DStringAppend(&ds, buf, -1);
    550     sprintf(buf, "num_frames=\"%lu\" ", (unsigned long int)stats.nFrames);
     550    sprintf(buf, "num_frames=\"%lu\" ", (unsigned long int)stats.numFrames);
    551551    Tcl_DStringAppend(&ds, buf, -1);
    552     sprintf(buf, "frame_bytes=\"%lu\" ", (unsigned long int)stats.nBytes);
     552    sprintf(buf, "frame_bytes=\"%lu\" ", (unsigned long int)stats.numBytes);
    553553    Tcl_DStringAppend(&ds, buf, -1);
    554     sprintf(buf, "num_commands=\"%lu\" ", (unsigned long int)stats.nCommands);
     554    sprintf(buf, "num_commands=\"%lu\" ", (unsigned long int)stats.numCommands);
    555555    Tcl_DStringAppend(&ds, buf, -1);
    556556    sprintf(buf, "cmd_time=\"%g\" ", stats.cmdTime);
     
    637637
    638638    stats.cmdTime += finish - start;
    639     stats.nCommands++;
     639    stats.numCommands++;
    640640    return result;
    641641}
     
    662662    }
    663663    proxyPtr->headPtr = imgPtr;
    664     imgPtr->nWritten = 0;
     664    imgPtr->numWritten = 0;
    665665    return imgPtr;
    666666}
     
    691691#endif
    692692        for (bytesLeft = imgPtr->bytesLeft; bytesLeft > 0; /*empty*/) {
    693             ssize_t nWritten;
     693            ssize_t numWritten;
    694694#if WRITETRACE
    695695            Debug("WriteImage: try to write %d bytes.", bytesLeft);
    696696#endif
    697             nWritten = write(fd, imgPtr->data + imgPtr->nWritten, bytesLeft);
     697            numWritten = write(fd, imgPtr->data + imgPtr->numWritten, bytesLeft);
    698698#if WRITETRACE
    699             Debug("WriteImage: wrote %d bytes.", nWritten);
     699            Debug("WriteImage: wrote %d bytes.", numWritten);
    700700#endif
    701             if (nWritten < 0) {
     701            if (numWritten < 0) {
    702702                ERROR("Error writing fd=%d, %s", fd, strerror(errno));
    703703                return;
    704704            }
    705             bytesLeft -= nWritten;
     705            bytesLeft -= numWritten;
    706706            if (bytesLeft > 0) {
    707707                /* Wrote a short buffer, means we would block. */
    708                 imgPtr->nWritten += nWritten;
     708                imgPtr->numWritten += numWritten;
    709709                imgPtr->bytesLeft = bytesLeft;
    710710                return;
    711711            }
    712             imgPtr->nWritten += nWritten;
     712            imgPtr->numWritten += numWritten;
    713713        }
    714714        /* Check if image is on the head.  */
     
    729729    char expect[BUFSIZ];
    730730    int result;
    731     ssize_t nWritten;
     731    ssize_t numWritten;
    732732    size_t length;
    733733    char *p;
     
    747747    /* Write the command out to the server. */
    748748    length = strlen(buffer);
    749     nWritten = write(proxyPtr->sin, buffer, length);
    750     if (nWritten != length) {
     749    numWritten = write(proxyPtr->sin, buffer, length);
     750    if (numWritten != length) {
    751751        ERROR("short write to pymol (wrote=%d, should have been %d): %s",
    752               nWritten, length, strerror(errno));
     752              numWritten, length, strerror(errno));
    753753    }
    754754    for (p = buffer; *p != '\0'; p++) {
     
    11001100    PymolProxy *proxyPtr = clientData;
    11011101    int state, defer, push;
    1102     int nBytes;
     1102    int numBytes;
    11031103    int i, j;
    11041104
     
    11231123    if (argc < 4) {
    11241124        Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0],
    1125                          " <data>|follows <model> <state> ?<nBytes>?\"",
     1125                         " <data>|follows <model> <state> ?<numBytes>?\"",
    11261126                         (char *)NULL);
    11271127        return TCL_ERROR;
     
    11321132        return TCL_ERROR;
    11331133    }
    1134     nBytes = -1;
     1134    numBytes = -1;
    11351135    if (strcmp(data, "follows") == 0) {
    11361136        if (argc != 5) {
    11371137            Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0],
    1138                          " follows <model> <state> <nBytes>\"", (char *)NULL);
     1138                         " follows <model> <state> <numBytes>\"", (char *)NULL);
    11391139            return TCL_ERROR;
    11401140        }
    1141         if (Tcl_GetInt(interp, argv[4], &nBytes) != TCL_OK) {
     1141        if (Tcl_GetInt(interp, argv[4], &numBytes) != TCL_OK) {
    11421142            return TCL_ERROR;
    11431143        }
    1144         if (nBytes < 0) {
     1144        if (numBytes < 0) {
    11451145            Tcl_AppendResult(interp, "bad value for # bytes \"", argv[4],
    11461146                         "\"", (char *)NULL);
     
    11581158
    11591159    allocated = NULL;
    1160     if (nBytes >= 0) {
    1161         allocated = malloc(sizeof(char) * nBytes);
     1160    if (numBytes >= 0) {
     1161        allocated = malloc(sizeof(char) * numBytes);
    11621162        if (allocated == NULL) {
    11631163            Tcl_AppendResult(interp, "can't allocate buffer for pdbdata.",
     
    11651165            return TCL_ERROR;
    11661166        }
    1167         if (ReadFollowingData(&proxyPtr->client, allocated, nBytes)
     1167        if (ReadFollowingData(&proxyPtr->client, allocated, numBytes)
    11681168            != BUFFER_OK) {
    11691169            Tcl_AppendResult(interp, "can't read pdbdata from client.",
     
    11741174        data = allocated;
    11751175    } else {
    1176         nBytes = strlen(data);
     1176        numBytes = strlen(data);
    11771177    }
    11781178    {
    11791179        int f;
    1180         ssize_t nWritten;
     1180        ssize_t numWritten;
    11811181        char fileName[200];
    11821182
     
    11891189            goto error;
    11901190        }
    1191         nWritten = write(f, data, nBytes);
    1192         if (nBytes != nWritten) {
     1191        numWritten = write(f, data, numBytes);
     1192        if (numBytes != numWritten) {
    11931193            Tcl_AppendResult(interp, "can't write PDB data to \"",
    11941194                             fileName, "\": ", Tcl_PosixError(interp),
     
    12961296{
    12971297    char buffer[BUFSIZ];
    1298     int nBytes=0;
     1298    int numBytes=0;
    12991299    PymolProxy *proxyPtr = clientData;
    13001300    size_t length;
     
    13101310        return TCL_ERROR;
    13111311    }
    1312     if (sscanf(buffer, "png image follows: %d\n", &nBytes) != 1) {
     1312    if (sscanf(buffer, "png image follows: %d\n", &numBytes) != 1) {
    13131313        Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"",
    13141314                         (char *)NULL);
    13151315        return TCL_ERROR;
    13161316    }
    1317     sprintf(buffer, "nv>image %d %d %d %d\n", nBytes, proxyPtr->cacheId,
     1317    sprintf(buffer, "nv>image %d %d %d %d\n", numBytes, proxyPtr->cacheId,
    13181318            proxyPtr->frame, proxyPtr->rockOffset);
    13191319    length = strlen(buffer);
    1320     imgPtr = NewImage(proxyPtr, nBytes + length);
     1320    imgPtr = NewImage(proxyPtr, numBytes + length);
    13211321    strcpy(imgPtr->data, buffer);
    1322     if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, nBytes)
     1322    if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, numBytes)
    13231323        != BUFFER_OK) {
    1324         ERROR("can't read %d bytes for \"image follows\" buffer: %s", nBytes,
     1324        ERROR("can't read %d bytes for \"image follows\" buffer: %s", numBytes,
    13251325              strerror(errno));
    13261326        return  TCL_ERROR;
     
    13291329        return TCL_ERROR;
    13301330    }
    1331     stats.nFrames++;
    1332     stats.nBytes += nBytes;
     1331    stats.numFrames++;
     1332    stats.numBytes += numBytes;
    13331333    return proxyPtr->status;
    13341334}
     
    13391339{
    13401340    char buffer[BUFSIZ];
    1341     int nBytes=0;
     1341    int numBytes=0;
    13421342    PymolProxy *proxyPtr = clientData;
    13431343    size_t length;
     
    13531353        return TCL_ERROR;
    13541354    }
    1355     if (sscanf(buffer, "ppm image follows: %d\n", &nBytes) != 1) {
     1355    if (sscanf(buffer, "ppm image follows: %d\n", &numBytes) != 1) {
    13561356        Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"",
    13571357                         (char *)NULL);
    13581358        return TCL_ERROR;
    13591359    }
    1360     sprintf(buffer, "nv>image %d %d %d %d\n", nBytes, proxyPtr->cacheId,
     1360    sprintf(buffer, "nv>image %d %d %d %d\n", numBytes, proxyPtr->cacheId,
    13611361            proxyPtr->frame, proxyPtr->rockOffset);
    13621362    length = strlen(buffer);
    1363     imgPtr = NewImage(proxyPtr, nBytes + length);
     1363    imgPtr = NewImage(proxyPtr, numBytes + length);
    13641364    strcpy(imgPtr->data, buffer);
    1365     if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, nBytes)
     1365    if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, numBytes)
    13661366        != BUFFER_OK) {
    1367         ERROR("can't read %d bytes for \"image follows\" buffer: %s", nBytes,
     1367        ERROR("can't read %d bytes for \"image follows\" buffer: %s", numBytes,
    13681368              strerror(errno));
    13691369        return  TCL_ERROR;
     
    13741374    }
    13751375#endif
    1376     stats.nFrames++;
    1377     stats.nBytes += nBytes;
     1376    stats.numFrames++;
     1377    stats.numBytes += numBytes;
    13781378    return proxyPtr->status;
    13791379}
     
    13851385{
    13861386    char buffer[800];
    1387     int nBytes=0;
     1387    int numBytes=0;
    13881388    PymolProxy *proxyPtr = clientData;
    13891389    size_t length;
     
    14251425    }
    14261426
    1427     if (sscanf(buffer, "png image follows: %d\n", &nBytes) != 1) {
     1427    if (sscanf(buffer, "png image follows: %d\n", &numBytes) != 1) {
    14281428        Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"",
    14291429                         (char *)NULL);
    14301430        return TCL_ERROR;
    14311431    }
    1432     sprintf(buffer, "nv>image %d print \"%s\" %d\n", nBytes, token,
     1432    sprintf(buffer, "nv>image %d print \"%s\" %d\n", numBytes, token,
    14331433            proxyPtr->rockOffset);
    14341434    Debug("header is png is (%s)\n", buffer);
    14351435    length = strlen(buffer);
    1436     imgPtr = NewImage(proxyPtr, nBytes + length);
     1436    imgPtr = NewImage(proxyPtr, numBytes + length);
    14371437    strcpy(imgPtr->data, buffer);
    1438     if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, nBytes)
     1438    if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, numBytes)
    14391439        != BUFFER_OK) {
    1440         ERROR("can't read %d bytes for \"image follows\" buffer: %s", nBytes,
     1440        ERROR("can't read %d bytes for \"image follows\" buffer: %s", numBytes,
    14411441              strerror(errno));
    14421442        return  TCL_ERROR;
     
    14461446    }
    14471447
    1448     stats.nFrames++;
    1449     stats.nBytes += nBytes;
     1448    stats.numFrames++;
     1449    stats.numBytes += numBytes;
    14501450    return proxyPtr->status;
    14511451}
     
    21952195         */
    21962196        if (pollFd[1].revents & POLLIN) { /* Server stdout */
    2197             int nBytes;
     2197            int numBytes;
    21982198            char *line;
    21992199           
     
    22012201            /* Don't care what's in the server output buffer. */
    22022202            FlushBuffer(&proxyPtr->server);
    2203             line = NextLine(&proxyPtr->server, &nBytes);
     2203            line = NextLine(&proxyPtr->server, &numBytes);
    22042204            if (line != NULL) {
    2205                 Debug("STDOUT>%.*s", nBytes, line);
    2206                 INFO("Garbage found from pymol server: %.%s", nBytes, line);
    2207             } else if (nBytes == BUFFER_CONTINUE) {
     2205                Debug("STDOUT>%.*s", numBytes, line);
     2206                INFO("Garbage found from pymol server: %.%s", numBytes, line);
     2207            } else if (numBytes == BUFFER_CONTINUE) {
    22082208                Debug("No data found on pymol stdout\n");
    22092209                continue;
    22102210            } else {
    2211                 ERROR("can't read pymol stdout (nBytes=%d): %s\n", nBytes,
     2211                ERROR("can't read pymol stdout (numBytes=%d): %s\n", numBytes,
    22122212                      strerror(errno));
    22132213                goto error;             /* Get out on EOF or error. */
     
    22192219            Debug("Reading client stdout\n");
    22202220            for (;;) {
    2221                 int nBytes;
     2221                int numBytes;
    22222222                char *line;
    22232223               
    2224                 line = NextLine(&proxyPtr->client, &nBytes);
     2224                line = NextLine(&proxyPtr->client, &numBytes);
    22252225                if (line != NULL) {
    22262226                    const char *cmd;
    22272227
    2228                     Tcl_DStringAppend(&clientCmds, line, nBytes);
     2228                    Tcl_DStringAppend(&clientCmds, line, numBytes);
    22292229                    cmd = Tcl_DStringValue(&clientCmds);
    22302230                    if (Tcl_CommandComplete(cmd)) {
     
    22442244                    continue;
    22452245                }
    2246                 if (nBytes == BUFFER_CONTINUE) {
     2246                if (numBytes == BUFFER_CONTINUE) {
    22472247                    break;
    22482248                }
    2249                 ERROR("can't read client stdout (nBytes=%d): %s\n", nBytes,
     2249                ERROR("can't read client stdout (numBytes=%d): %s\n", numBytes,
    22502250                      strerror(errno));
    22512251                goto error;             /* Get out on EOF or error. */
Note: See TracChangeset for help on using the changeset viewer.