Changeset 6620 for nanovis/branches
- Timestamp:
- Nov 14, 2016 12:00:15 PM (7 years ago)
- Location:
- nanovis/branches/1.2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
nanovis/branches/1.2/Command.cpp
r6619 r6620 37 37 #include <unistd.h> /* Needed for getpid, gethostname, 38 38 * write, etc. */ 39 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS) 40 #include <fcntl.h> 41 #endif 39 42 40 #include <sstream> 43 41 … … 538 536 nv::GetDataStream(Tcl_Interp *interp, Rappture::Buffer &buf, int nBytes) 539 537 { 540 #if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS)541 538 if (!SocketRead((char *)buf.bytes(), nBytes)) { 542 539 return TCL_ERROR; 543 540 } 544 541 buf.count(nBytes); 545 #else546 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 #endif570 542 Rappture::Outcome err; 571 543 TRACE("Checking header [%.13s]", buf.bytes()); … … 2251 2223 } 2252 2224 2253 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS)2254 int2255 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 we2271 // block here and wait if necessary until a command comes in.2272 //2273 // BE CAREFUL: Read only one command, up to a newline. The "volume2274 // data follows" command needs to be able to read the data2275 // immediately following the command, and we shouldn't consume it2276 // 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 now2297 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 anything2308 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 #endif2327 2328 2225 /** 2329 2226 * \brief Execute commands from client in Tcl interpreter -
nanovis/branches/1.2/Command.h
r6619 r6620 38 38 extern bool SocketRead(char *bytes, size_t len); 39 39 40 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS)41 extern int processCommands(Tcl_Interp *interp,42 FILE *inBufPtr,43 int fdOut);44 #endif45 40 extern int processCommands(Tcl_Interp *interp, 46 41 ReadBuffer *inBufPtr, -
nanovis/branches/1.2/config.h
r5394 r6620 49 49 #define KEEPSTATS 50 50 51 //#define USE_NEW_EVENT_LOOP52 53 51 /* 54 52 * Controls whether DX data is downsampled. -
nanovis/branches/1.2/nanovisServer.cpp
r6619 r6620 50 50 int nv::g_fdIn = STDIN_FILENO; ///< Input file descriptor 51 51 int nv::g_fdOut = STDOUT_FILENO; ///< Output file descriptor 52 FILE *nv::g_fIn = NULL; ///< Input file handle53 52 FILE *nv::g_fOut = NULL; ///< Output file handle 54 53 FILE *nv::g_fLog = NULL; ///< Trace logging file handle … … 315 314 initService() 316 315 { 317 g_fIn = fdopen(g_fdIn, "r");318 316 // Create a stream associated with the output file descriptor 319 317 g_fOut = fdopen(g_fdOut, "w"); … … 385 383 glutSetWindow(NanoVis::renderWindow); 386 384 387 #if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS)388 385 struct timeval timeout; 389 386 timeout.tv_sec = g_idleTimeout; … … 392 389 exitService(1); 393 390 } 394 #else395 if (processCommands(NanoVis::interp, g_fIn, g_fdOut) < 0) {396 exitService(1);397 }398 #endif399 391 400 392 NanoVis::update(); … … 417 409 } 418 410 419 #if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS)420 411 if (g_inBufPtr->status() == ReadBuffer::ENDFILE) { 421 412 exitService(0); 422 413 } 423 #else424 if (feof(g_fIn)) {425 exitService(0);426 }427 #endif428 414 429 415 TRACE("Leave"); … … 547 533 fflush(g_fOut); 548 534 549 #if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS)550 535 g_inBufPtr = new ReadBuffer(g_fdIn, 1<<12); 551 #endif552 536 553 537 Tcl_Interp *interp = Tcl_CreateInterp(); -
nanovis/branches/1.2/nanovisServer.h
r6619 r6620 43 43 extern int g_fdIn; ///< Input file descriptor 44 44 extern int g_fdOut; ///< Output file descriptor 45 extern FILE *g_fIn; ///< Input file handle46 45 extern FILE *g_fOut; ///< Output file handle 47 46 extern FILE *g_fLog; ///< Trace logging file handle
Note: See TracChangeset
for help on using the changeset viewer.