Changeset 5603
- Timestamp:
- May 22, 2015, 2:47:15 PM (9 years ago)
- Location:
- nanovis/branches/1.2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
nanovis/branches/1.2
- Property svn:mergeinfo changed
/trunk/packages/vizservers/nanovis merged: 3606
- Property svn:mergeinfo changed
-
nanovis/branches/1.2/Command.cpp
r5588 r5603 37 37 #include <unistd.h> /* Needed for getpid, gethostname, 38 38 * write, etc. */ 39 39 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS) 40 #include <fcntl.h> 41 #endif 40 42 #include <sstream> 41 43 … … 2236 2238 } 2237 2239 2240 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS) 2241 int 2242 nv::processCommands(Tcl_Interp *interp, FILE *inFile, int fdOut) 2243 { 2244 int ret = 0; 2245 int status = TCL_OK; 2246 2247 Tcl_DString cmdbuffer; 2248 Tcl_DStringInit(&cmdbuffer); 2249 2250 int flags = fcntl(0, F_GETFL, 0); 2251 fcntl(0, F_SETFL, flags & ~O_NONBLOCK); 2252 2253 // Read and execute as many commands as we can from stdin... 2254 bool isComplete = false; 2255 while ((!feof(inFile)) && (status == TCL_OK)) { 2256 // 2257 // Read the next command from the buffer. First time through we 2258 // block here and wait if necessary until a command comes in. 2259 // 2260 // BE CAREFUL: Read only one command, up to a newline. The "volume 2261 // data follows" command needs to be able to read the data 2262 // immediately following the command, and we shouldn't consume it 2263 // here. 2264 // 2265 while (!feof(inFile)) { 2266 int c = fgetc(inFile); 2267 char ch; 2268 if (c <= 0) { 2269 if (errno == EWOULDBLOCK) { 2270 break; 2271 } 2272 return -1; 2273 } 2274 ch = (char)c; 2275 Tcl_DStringAppend(&cmdbuffer, &ch, 1); 2276 if (ch == '\n') { 2277 isComplete = Tcl_CommandComplete(Tcl_DStringValue(&cmdbuffer)); 2278 if (isComplete) { 2279 break; 2280 } 2281 } 2282 } 2283 // no command? then we're done for now 2284 if (Tcl_DStringLength(&cmdbuffer) == 0) { 2285 break; 2286 } 2287 if (isComplete) { 2288 // back to original flags during command evaluation... 2289 fcntl(0, F_SETFL, flags & ~O_NONBLOCK); 2290 struct timeval start, finish; 2291 gettimeofday(&start, NULL); 2292 status = ExecuteCommand(interp, &cmdbuffer); 2293 gettimeofday(&finish, NULL); 2294 // non-blocking for next read -- we might not get anything 2295 fcntl(0, F_SETFL, flags | O_NONBLOCK); 2296 isComplete = false; 2297 g_stats.cmdTime += (MSECS_ELAPSED(start, finish) / 1.0e+3); 2298 g_stats.nCommands++; 2299 } 2300 } 2301 fcntl(0, F_SETFL, flags); 2302 2303 if (status != TCL_OK) { 2304 if (handleError(interp, status, fdOut) < 0) { 2305 return -1; 2306 } 2307 TRACE("Leaving on ERROR"); 2308 } 2309 2310 return ret; 2311 } 2312 2313 #endif 2314 2238 2315 /** 2239 2316 * \brief Execute commands from client in Tcl interpreter -
nanovis/branches/1.2/Command.h
r4937 r5603 37 37 extern bool SocketRead(char *bytes, size_t len); 38 38 39 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS) 40 extern int processCommands(Tcl_Interp *interp, 41 FILE *inBufPtr, 42 int fdOut); 43 #endif 39 44 extern int processCommands(Tcl_Interp *interp, 40 45 ReadBuffer *inBufPtr, -
nanovis/branches/1.2/nanovisServer.cpp
r5495 r5603 382 382 } 383 383 384 #if !defined(USE_NEW_EVENT_LOOP) && !defined(USE_THREADS)385 386 static int387 executeCommand(Tcl_Interp *interp, Tcl_DString *dsPtr)388 {389 int result;390 #ifdef WANT_TRACE391 char *str = Tcl_DStringValue(dsPtr);392 std::string cmd(str);393 cmd.erase(cmd.find_last_not_of(" \n\r\t")+1);394 TRACE("command %lu: '%s'", g_stats.nCommands+1, cmd.c_str());395 #endif396 397 result = Tcl_Eval(interp, Tcl_DStringValue(dsPtr));398 Tcl_DStringSetLength(dsPtr, 0);399 400 if (result != TCL_OK) {401 TRACE("Error: %d", result);402 }403 return result;404 }405 406 static int407 processCommands(Tcl_Interp *interp, FILE *inFile, int fdOut)408 {409 int ret = 0;410 int status = TCL_OK;411 412 Tcl_DString cmdbuffer;413 Tcl_DStringInit(&cmdbuffer);414 415 int flags = fcntl(0, F_GETFL, 0);416 fcntl(0, F_SETFL, flags & ~O_NONBLOCK);417 418 // Read and execute as many commands as we can from stdin...419 bool isComplete = false;420 while ((!feof(inFile)) && (status == TCL_OK)) {421 //422 // Read the next command from the buffer. First time through we423 // block here and wait if necessary until a command comes in.424 //425 // BE CAREFUL: Read only one command, up to a newline. The "volume426 // data follows" command needs to be able to read the data427 // immediately following the command, and we shouldn't consume it428 // here.429 //430 while (!feof(inFile)) {431 int c = fgetc(inFile);432 char ch;433 if (c <= 0) {434 if (errno == EWOULDBLOCK) {435 break;436 }437 return -1;438 }439 ch = (char)c;440 Tcl_DStringAppend(&cmdbuffer, &ch, 1);441 if (ch == '\n') {442 isComplete = Tcl_CommandComplete(Tcl_DStringValue(&cmdbuffer));443 if (isComplete) {444 break;445 }446 }447 }448 // no command? then we're done for now449 if (Tcl_DStringLength(&cmdbuffer) == 0) {450 break;451 }452 if (isComplete) {453 // back to original flags during command evaluation...454 fcntl(0, F_SETFL, flags & ~O_NONBLOCK);455 struct timeval start, finish;456 gettimeofday(&start, NULL);457 status = executeCommand(interp, &cmdbuffer);458 gettimeofday(&finish, NULL);459 // non-blocking for next read -- we might not get anything460 fcntl(0, F_SETFL, flags | O_NONBLOCK);461 isComplete = false;462 g_stats.cmdTime += (MSECS_ELAPSED(start, finish) / 1.0e+3);463 g_stats.nCommands++;464 CHECK_FRAMEBUFFER_STATUS();465 }466 }467 fcntl(0, F_SETFL, flags);468 469 if (status != TCL_OK) {470 if (handleError(interp, status, fdOut) < 0) {471 return -1;472 }473 TRACE("Leaving on ERROR");474 }475 476 return ret;477 }478 #endif479 480 384 static void 481 385 idle() … … 486 390 487 391 #if defined(USE_NEW_EVENT_LOOP) || defined(USE_THREADS) 488 if ( nv::processCommands(NanoVis::interp, g_inBufPtr, g_fdOut) < 0) {392 if (processCommands(NanoVis::interp, g_inBufPtr, g_fdOut) < 0) { 489 393 exitService(1); 490 394 }
Note: See TracChangeset
for help on using the changeset viewer.