Changeset 3644 for trunk/packages/vizservers/pymolproxy/pymolproxy.c
- Timestamp:
- May 10, 2013 3:31:17 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/pymolproxy/pymolproxy.c
r3412 r3644 87 87 typedef struct { 88 88 pid_t child; /* Child process. */ 89 size_t n Frames; /* # of frames sent to client. */90 size_t n Bytes; /* # of bytes for all frames. */91 size_t n Commands; /* # 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 */ 92 92 double cmdTime; /* Elapsed time spend executing commands. */ 93 93 struct timeval start; /* Start of elapsed time. */ … … 115 115 * most recently received image from 116 116 * the pymol server to the least. */ 117 ssize_t n Written; /* Number of bytes of image data117 ssize_t numWritten; /* Number of bytes of image data 118 118 * already delivered.*/ 119 119 size_t bytesLeft; /* Number of bytes of image data left … … 335 335 * If insufficient data is in the buffer, then the channel is 336 336 * read for more data. If reading the channel results in a 337 * short read, NULL is returned and *n BytesPtr is set to337 * short read, NULL is returned and *numBytesPtr is set to 338 338 * BUFFER_CONTINUE. 339 339 */ 340 340 static char * 341 NextLine(ReadBuffer *readPtr, int *n BytesPtr)341 NextLine(ReadBuffer *readPtr, int *numBytesPtr) 342 342 { 343 343 int i; … … 361 361 p = readPtr->bytes + readPtr->mark; 362 362 i++; /* Include the newline. */ 363 *n BytesPtr = i - readPtr->mark;363 *numBytesPtr = i - readPtr->mark; 364 364 readPtr->mark = i; 365 365 #if READTRACE 366 Debug("Leaving NextLine(%.*s)\n", *n BytesPtr, p);366 Debug("Leaving NextLine(%.*s)\n", *numBytesPtr, p); 367 367 #endif 368 368 return p; … … 372 372 * more. Check first that last read wasn't a short read. */ 373 373 if (status == BUFFER_CONTINUE) { 374 *n BytesPtr = BUFFER_CONTINUE; /* No complete line just yet. */374 *numBytesPtr = BUFFER_CONTINUE; /* No complete line just yet. */ 375 375 return NULL; 376 376 } … … 378 378 status = FillBuffer(readPtr); 379 379 if (status == BUFFER_ERROR) { 380 *n BytesPtr = BUFFER_ERROR;380 *numBytesPtr = BUFFER_ERROR; 381 381 return NULL; /* EOF or error on read. */ 382 382 } … … 386 386 Debug("Leaving NextLine failed to read line\n"); 387 387 #endif 388 *n BytesPtr = BUFFER_CONTINUE;388 *numBytesPtr = BUFFER_CONTINUE; 389 389 return NULL; 390 390 } … … 398 398 */ 399 399 static int 400 ReadFollowingData(ReadBuffer *readPtr, char *out, int n Bytes)400 ReadFollowingData(ReadBuffer *readPtr, char *out, int numBytes) 401 401 { 402 402 #if READTRACE 403 Debug("Entering ReadFollowingData(%d)\n", n Bytes);403 Debug("Entering ReadFollowingData(%d)\n", numBytes); 404 404 #endif 405 while (n Bytes > 0) {405 while (numBytes > 0) { 406 406 int bytesLeft; 407 407 int status; … … 412 412 413 413 /* Pull bytes out of the buffer, updating the mark. */ 414 size = (bytesLeft > n Bytes) ? nBytes : bytesLeft;414 size = (bytesLeft > numBytes) ? numBytes : bytesLeft; 415 415 memcpy(out, readPtr->bytes + readPtr->mark, size); 416 416 readPtr->mark += size; 417 n Bytes -= size;417 numBytes -= size; 418 418 out += size; 419 419 } 420 if (n Bytes == 0) {420 if (numBytes == 0) { 421 421 /* Received requested # bytes. */ 422 422 #if READTRACE 423 Debug("Leaving ReadFollowingData(%d)\n", n Bytes);423 Debug("Leaving ReadFollowingData(%d)\n", numBytes); 424 424 #endif 425 425 return BUFFER_OK; … … 436 436 } 437 437 #if READTRACE 438 Debug("Leaving ReadFollowingData(%d)\n", n Bytes);438 Debug("Leaving ReadFollowingData(%d)\n", numBytes); 439 439 #endif 440 440 return BUFFER_OK; … … 463 463 length = strlen(match); 464 464 for (;;) { 465 int n Bytes;465 int numBytes; 466 466 char *line; 467 467 468 line = NextLine(&proxyPtr->server, &n Bytes);468 line = NextLine(&proxyPtr->server, &numBytes); 469 469 if (line != NULL) { 470 470 #if EXPECTTRACE 471 Debug("pymol says (read %d bytes):%.*s", n Bytes, nBytes, line);471 Debug("pymol says (read %d bytes):%.*s", numBytes, numBytes, line); 472 472 #endif 473 473 if ((c == line[0]) && (strncmp(line, match, length) == 0)) { 474 if (maxSize < n Bytes) {475 n Bytes = maxSize;474 if (maxSize < numBytes) { 475 numBytes = maxSize; 476 476 } 477 memcpy(out, line, n Bytes);477 memcpy(out, line, numBytes); 478 478 clear_error(proxyPtr); 479 479 #if EXPECTTRACE 480 Debug("Leaving Expect: got (%.*s)\n", n Bytes, out);480 Debug("Leaving Expect: got (%.*s)\n", numBytes, out); 481 481 #endif 482 482 return TCL_OK; … … 484 484 continue; 485 485 } 486 if (n Bytes == BUFFER_ERROR) {486 if (numBytes == BUFFER_ERROR) { 487 487 Tcl_AppendResult(proxyPtr->interp, 488 488 "error reading server to find match for \"", match, "\": ", … … 548 548 sprintf(buf, "pid=\"%d\" ", pid); 549 549 Tcl_DStringAppend(&ds, buf, -1); 550 sprintf(buf, "num_frames=\"%lu\" ", (unsigned long int)stats.n Frames);550 sprintf(buf, "num_frames=\"%lu\" ", (unsigned long int)stats.numFrames); 551 551 Tcl_DStringAppend(&ds, buf, -1); 552 sprintf(buf, "frame_bytes=\"%lu\" ", (unsigned long int)stats.n Bytes);552 sprintf(buf, "frame_bytes=\"%lu\" ", (unsigned long int)stats.numBytes); 553 553 Tcl_DStringAppend(&ds, buf, -1); 554 sprintf(buf, "num_commands=\"%lu\" ", (unsigned long int)stats.n Commands);554 sprintf(buf, "num_commands=\"%lu\" ", (unsigned long int)stats.numCommands); 555 555 Tcl_DStringAppend(&ds, buf, -1); 556 556 sprintf(buf, "cmd_time=\"%g\" ", stats.cmdTime); … … 637 637 638 638 stats.cmdTime += finish - start; 639 stats.n Commands++;639 stats.numCommands++; 640 640 return result; 641 641 } … … 662 662 } 663 663 proxyPtr->headPtr = imgPtr; 664 imgPtr->n Written = 0;664 imgPtr->numWritten = 0; 665 665 return imgPtr; 666 666 } … … 691 691 #endif 692 692 for (bytesLeft = imgPtr->bytesLeft; bytesLeft > 0; /*empty*/) { 693 ssize_t n Written;693 ssize_t numWritten; 694 694 #if WRITETRACE 695 695 Debug("WriteImage: try to write %d bytes.", bytesLeft); 696 696 #endif 697 n Written = write(fd, imgPtr->data + imgPtr->nWritten, bytesLeft);697 numWritten = write(fd, imgPtr->data + imgPtr->numWritten, bytesLeft); 698 698 #if WRITETRACE 699 Debug("WriteImage: wrote %d bytes.", n Written);699 Debug("WriteImage: wrote %d bytes.", numWritten); 700 700 #endif 701 if (n Written < 0) {701 if (numWritten < 0) { 702 702 ERROR("Error writing fd=%d, %s", fd, strerror(errno)); 703 703 return; 704 704 } 705 bytesLeft -= n Written;705 bytesLeft -= numWritten; 706 706 if (bytesLeft > 0) { 707 707 /* Wrote a short buffer, means we would block. */ 708 imgPtr->n Written += nWritten;708 imgPtr->numWritten += numWritten; 709 709 imgPtr->bytesLeft = bytesLeft; 710 710 return; 711 711 } 712 imgPtr->n Written += nWritten;712 imgPtr->numWritten += numWritten; 713 713 } 714 714 /* Check if image is on the head. */ … … 729 729 char expect[BUFSIZ]; 730 730 int result; 731 ssize_t n Written;731 ssize_t numWritten; 732 732 size_t length; 733 733 char *p; … … 747 747 /* Write the command out to the server. */ 748 748 length = strlen(buffer); 749 n Written = write(proxyPtr->sin, buffer, length);750 if (n Written != length) {749 numWritten = write(proxyPtr->sin, buffer, length); 750 if (numWritten != length) { 751 751 ERROR("short write to pymol (wrote=%d, should have been %d): %s", 752 n Written, length, strerror(errno));752 numWritten, length, strerror(errno)); 753 753 } 754 754 for (p = buffer; *p != '\0'; p++) { … … 1100 1100 PymolProxy *proxyPtr = clientData; 1101 1101 int state, defer, push; 1102 int n Bytes;1102 int numBytes; 1103 1103 int i, j; 1104 1104 … … 1123 1123 if (argc < 4) { 1124 1124 Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], 1125 " <data>|follows <model> <state> ?<n Bytes>?\"",1125 " <data>|follows <model> <state> ?<numBytes>?\"", 1126 1126 (char *)NULL); 1127 1127 return TCL_ERROR; … … 1132 1132 return TCL_ERROR; 1133 1133 } 1134 n Bytes = -1;1134 numBytes = -1; 1135 1135 if (strcmp(data, "follows") == 0) { 1136 1136 if (argc != 5) { 1137 1137 Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], 1138 " follows <model> <state> <n Bytes>\"", (char *)NULL);1138 " follows <model> <state> <numBytes>\"", (char *)NULL); 1139 1139 return TCL_ERROR; 1140 1140 } 1141 if (Tcl_GetInt(interp, argv[4], &n Bytes) != TCL_OK) {1141 if (Tcl_GetInt(interp, argv[4], &numBytes) != TCL_OK) { 1142 1142 return TCL_ERROR; 1143 1143 } 1144 if (n Bytes < 0) {1144 if (numBytes < 0) { 1145 1145 Tcl_AppendResult(interp, "bad value for # bytes \"", argv[4], 1146 1146 "\"", (char *)NULL); … … 1158 1158 1159 1159 allocated = NULL; 1160 if (n Bytes >= 0) {1161 allocated = malloc(sizeof(char) * n Bytes);1160 if (numBytes >= 0) { 1161 allocated = malloc(sizeof(char) * numBytes); 1162 1162 if (allocated == NULL) { 1163 1163 Tcl_AppendResult(interp, "can't allocate buffer for pdbdata.", … … 1165 1165 return TCL_ERROR; 1166 1166 } 1167 if (ReadFollowingData(&proxyPtr->client, allocated, n Bytes)1167 if (ReadFollowingData(&proxyPtr->client, allocated, numBytes) 1168 1168 != BUFFER_OK) { 1169 1169 Tcl_AppendResult(interp, "can't read pdbdata from client.", … … 1174 1174 data = allocated; 1175 1175 } else { 1176 n Bytes = strlen(data);1176 numBytes = strlen(data); 1177 1177 } 1178 1178 { 1179 1179 int f; 1180 ssize_t n Written;1180 ssize_t numWritten; 1181 1181 char fileName[200]; 1182 1182 … … 1189 1189 goto error; 1190 1190 } 1191 n Written = write(f, data, nBytes);1192 if (n Bytes != nWritten) {1191 numWritten = write(f, data, numBytes); 1192 if (numBytes != numWritten) { 1193 1193 Tcl_AppendResult(interp, "can't write PDB data to \"", 1194 1194 fileName, "\": ", Tcl_PosixError(interp), … … 1296 1296 { 1297 1297 char buffer[BUFSIZ]; 1298 int n Bytes=0;1298 int numBytes=0; 1299 1299 PymolProxy *proxyPtr = clientData; 1300 1300 size_t length; … … 1310 1310 return TCL_ERROR; 1311 1311 } 1312 if (sscanf(buffer, "png image follows: %d\n", &n Bytes) != 1) {1312 if (sscanf(buffer, "png image follows: %d\n", &numBytes) != 1) { 1313 1313 Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"", 1314 1314 (char *)NULL); 1315 1315 return TCL_ERROR; 1316 1316 } 1317 sprintf(buffer, "nv>image %d %d %d %d\n", n Bytes, proxyPtr->cacheId,1317 sprintf(buffer, "nv>image %d %d %d %d\n", numBytes, proxyPtr->cacheId, 1318 1318 proxyPtr->frame, proxyPtr->rockOffset); 1319 1319 length = strlen(buffer); 1320 imgPtr = NewImage(proxyPtr, n Bytes + length);1320 imgPtr = NewImage(proxyPtr, numBytes + length); 1321 1321 strcpy(imgPtr->data, buffer); 1322 if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, n Bytes)1322 if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, numBytes) 1323 1323 != BUFFER_OK) { 1324 ERROR("can't read %d bytes for \"image follows\" buffer: %s", n Bytes,1324 ERROR("can't read %d bytes for \"image follows\" buffer: %s", numBytes, 1325 1325 strerror(errno)); 1326 1326 return TCL_ERROR; … … 1329 1329 return TCL_ERROR; 1330 1330 } 1331 stats.n Frames++;1332 stats.n Bytes += nBytes;1331 stats.numFrames++; 1332 stats.numBytes += numBytes; 1333 1333 return proxyPtr->status; 1334 1334 } … … 1339 1339 { 1340 1340 char buffer[BUFSIZ]; 1341 int n Bytes=0;1341 int numBytes=0; 1342 1342 PymolProxy *proxyPtr = clientData; 1343 1343 size_t length; … … 1353 1353 return TCL_ERROR; 1354 1354 } 1355 if (sscanf(buffer, "ppm image follows: %d\n", &n Bytes) != 1) {1355 if (sscanf(buffer, "ppm image follows: %d\n", &numBytes) != 1) { 1356 1356 Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"", 1357 1357 (char *)NULL); 1358 1358 return TCL_ERROR; 1359 1359 } 1360 sprintf(buffer, "nv>image %d %d %d %d\n", n Bytes, proxyPtr->cacheId,1360 sprintf(buffer, "nv>image %d %d %d %d\n", numBytes, proxyPtr->cacheId, 1361 1361 proxyPtr->frame, proxyPtr->rockOffset); 1362 1362 length = strlen(buffer); 1363 imgPtr = NewImage(proxyPtr, n Bytes + length);1363 imgPtr = NewImage(proxyPtr, numBytes + length); 1364 1364 strcpy(imgPtr->data, buffer); 1365 if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, n Bytes)1365 if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, numBytes) 1366 1366 != BUFFER_OK) { 1367 ERROR("can't read %d bytes for \"image follows\" buffer: %s", n Bytes,1367 ERROR("can't read %d bytes for \"image follows\" buffer: %s", numBytes, 1368 1368 strerror(errno)); 1369 1369 return TCL_ERROR; … … 1374 1374 } 1375 1375 #endif 1376 stats.n Frames++;1377 stats.n Bytes += nBytes;1376 stats.numFrames++; 1377 stats.numBytes += numBytes; 1378 1378 return proxyPtr->status; 1379 1379 } … … 1385 1385 { 1386 1386 char buffer[800]; 1387 int n Bytes=0;1387 int numBytes=0; 1388 1388 PymolProxy *proxyPtr = clientData; 1389 1389 size_t length; … … 1425 1425 } 1426 1426 1427 if (sscanf(buffer, "png image follows: %d\n", &n Bytes) != 1) {1427 if (sscanf(buffer, "png image follows: %d\n", &numBytes) != 1) { 1428 1428 Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"", 1429 1429 (char *)NULL); 1430 1430 return TCL_ERROR; 1431 1431 } 1432 sprintf(buffer, "nv>image %d print \"%s\" %d\n", n Bytes, token,1432 sprintf(buffer, "nv>image %d print \"%s\" %d\n", numBytes, token, 1433 1433 proxyPtr->rockOffset); 1434 1434 Debug("header is png is (%s)\n", buffer); 1435 1435 length = strlen(buffer); 1436 imgPtr = NewImage(proxyPtr, n Bytes + length);1436 imgPtr = NewImage(proxyPtr, numBytes + length); 1437 1437 strcpy(imgPtr->data, buffer); 1438 if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, n Bytes)1438 if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, numBytes) 1439 1439 != BUFFER_OK) { 1440 ERROR("can't read %d bytes for \"image follows\" buffer: %s", n Bytes,1440 ERROR("can't read %d bytes for \"image follows\" buffer: %s", numBytes, 1441 1441 strerror(errno)); 1442 1442 return TCL_ERROR; … … 1446 1446 } 1447 1447 1448 stats.n Frames++;1449 stats.n Bytes += nBytes;1448 stats.numFrames++; 1449 stats.numBytes += numBytes; 1450 1450 return proxyPtr->status; 1451 1451 } … … 2195 2195 */ 2196 2196 if (pollFd[1].revents & POLLIN) { /* Server stdout */ 2197 int n Bytes;2197 int numBytes; 2198 2198 char *line; 2199 2199 … … 2201 2201 /* Don't care what's in the server output buffer. */ 2202 2202 FlushBuffer(&proxyPtr->server); 2203 line = NextLine(&proxyPtr->server, &n Bytes);2203 line = NextLine(&proxyPtr->server, &numBytes); 2204 2204 if (line != NULL) { 2205 Debug("STDOUT>%.*s", n Bytes, line);2206 INFO("Garbage found from pymol server: %.%s", n Bytes, line);2207 } else if (n Bytes == BUFFER_CONTINUE) {2205 Debug("STDOUT>%.*s", numBytes, line); 2206 INFO("Garbage found from pymol server: %.%s", numBytes, line); 2207 } else if (numBytes == BUFFER_CONTINUE) { 2208 2208 Debug("No data found on pymol stdout\n"); 2209 2209 continue; 2210 2210 } else { 2211 ERROR("can't read pymol stdout (n Bytes=%d): %s\n", nBytes,2211 ERROR("can't read pymol stdout (numBytes=%d): %s\n", numBytes, 2212 2212 strerror(errno)); 2213 2213 goto error; /* Get out on EOF or error. */ … … 2219 2219 Debug("Reading client stdout\n"); 2220 2220 for (;;) { 2221 int n Bytes;2221 int numBytes; 2222 2222 char *line; 2223 2223 2224 line = NextLine(&proxyPtr->client, &n Bytes);2224 line = NextLine(&proxyPtr->client, &numBytes); 2225 2225 if (line != NULL) { 2226 2226 const char *cmd; 2227 2227 2228 Tcl_DStringAppend(&clientCmds, line, n Bytes);2228 Tcl_DStringAppend(&clientCmds, line, numBytes); 2229 2229 cmd = Tcl_DStringValue(&clientCmds); 2230 2230 if (Tcl_CommandComplete(cmd)) { … … 2244 2244 continue; 2245 2245 } 2246 if (n Bytes == BUFFER_CONTINUE) {2246 if (numBytes == BUFFER_CONTINUE) { 2247 2247 break; 2248 2248 } 2249 ERROR("can't read client stdout (n Bytes=%d): %s\n", nBytes,2249 ERROR("can't read client stdout (numBytes=%d): %s\n", numBytes, 2250 2250 strerror(errno)); 2251 2251 goto error; /* Get out on EOF or error. */
Note: See TracChangeset
for help on using the changeset viewer.