Changeset 5603 for nanovis/branches/1.2/Command.cpp
- Timestamp:
- May 22, 2015 2:47:15 PM (9 years ago)
- Location:
- nanovis/branches/1.2
- Files:
-
- 2 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
Note: See TracChangeset
for help on using the changeset viewer.