rfbBool rfbProcessEvents(rfbScreenInfoPtr screen,long usec) { rfbClientIteratorPtr i; rfbClientPtr cl,clPrev; rfbBool result=FALSE; extern rfbClientIteratorPtr rfbGetClientIteratorWithClosed(rfbScreenInfoPtr rfbScreen); if(usec<0) usec=screen->deferUpdateTime*1000; rfbCheckFds(screen,usec); rfbHttpCheckFds(screen); i = rfbGetClientIteratorWithClosed(screen); cl=rfbClientIteratorHead(i); while(cl) { result = rfbUpdateClient(cl); clPrev=cl; cl=rfbClientIteratorNext(i); if(clPrev->sock==-1) { rfbClientConnectionGone(clPrev); result=TRUE; } } rfbReleaseClientIterator(i); return result; }
static void do_allinput(long usec) { static double last = 0.0; static int meas = 0; int n, f = 1, cnt = 0; long usec0; double now; if (!screen || !screen->clientHead) { return; } if (usec < 0) { usec = 0; } usec0 = usec; if (last == 0.0) { last = dnow(); } while ((n = rfbCheckFds(screen, usec)) > 0) { if (f) { fprintf(stderr, " *"); f = 0; } if (cnt++ > 30) { break; } meas += n; } fprintf(stderr, "-%d", cnt); now = dnow(); if (now > last + 2.0) { double rate = meas / (now - last); fprintf(stderr, "\n%.2f ", rate); meas = 0; last = dnow(); } }
//! this is called before every frame, used for polling for RFB messages void VncServer::preFrame() { const int wait_msec=1; if (m_delay) { usleep(m_delay); } if (m_numClients == 0) { for (size_t i=0; i<m_clientList.size(); ++i) { if (rfbReverseConnection(m_screen, const_cast<char *>(m_clientList[i].host.c_str()), m_clientList[i].port)) { break; } } } rfbCheckFds(m_screen, wait_msec*1000); rfbHttpCheckFds(m_screen); rfbClientIteratorPtr i = rfbGetClientIterator(m_screen); while (rfbClientPtr cl = rfbClientIteratorNext(i)) { if (rfbUpdateClient(cl)) { } } rfbReleaseClientIterator(i); }
void rfbCFD(long usec) { if (! screen) { return; } if (usec > USEC_MAX) { usec = USEC_MAX; } if (! use_threads) { rfbCheckFds(screen, usec); } }
void rfbCFD(long usec) { int uip0 = unixpw_in_progress; if (! screen) { return; } if (unixpw && unixpw_in_progress && !unixpw_in_rfbPE) { rfbLog("unixpw_in_rfbPE: skipping rfbCFD\n"); return; } if (usec > USEC_MAX) { usec = USEC_MAX; } if (! use_threads) { if (0 && all_input) { static int cnt = 0; int f = 1; while (rfbCheckFds(screen, usec) > 0) { if (f) { cnt++; f = 0; } fprintf(stderr, "-%d", cnt); } } else { if (all_input) { screen->handleEventsEagerly = TRUE; } else { screen->handleEventsEagerly = FALSE; } rfbCheckFds(screen, usec); } } if (unixpw && unixpw_in_progress && !uip0) { if (!unixpw_in_rfbPE) { rfbLog("rfbCFD: got new client in non-rfbPE\n"); ; /* this is new unixpw client */ } } }
void rfbProcessEvents(rfbScreenInfoPtr rfbScreen,long usec) { rfbClientIteratorPtr i; rfbClientPtr cl,clPrev; struct timeval tv; if(usec<0) usec=rfbScreen->rfbDeferUpdateTime*1000; rfbCheckFds(rfbScreen,usec); httpCheckFds(rfbScreen); #ifdef CORBA corbaCheckFds(rfbScreen); #endif i = rfbGetClientIterator(rfbScreen); cl=rfbClientIteratorNext(i); while(cl) { if(cl->sock>=0 && (!cl->onHold) && FB_UPDATE_PENDING(cl)) { if(cl->screen->rfbDeferUpdateTime == 0) { rfbSendFramebufferUpdate(cl,cl->modifiedRegion); } else if(cl->startDeferring.tv_usec == 0) { gettimeofday(&cl->startDeferring,NULL); if(cl->startDeferring.tv_usec == 0) cl->startDeferring.tv_usec++; } else { gettimeofday(&tv,NULL); if(tv.tv_sec < cl->startDeferring.tv_sec /* at midnight */ || ((tv.tv_sec-cl->startDeferring.tv_sec)*1000 +(tv.tv_usec-cl->startDeferring.tv_usec)/1000) > cl->screen->rfbDeferUpdateTime) { cl->startDeferring.tv_usec = 0; rfbSendFramebufferUpdate(cl,cl->modifiedRegion); } } } clPrev=cl; cl=rfbClientIteratorNext(i); if(clPrev->sock==-1) rfbClientConnectionGone(clPrev); } rfbReleaseClientIterator(i); }
void rfbCFD(long usec) { int uip0 = unixpw_in_progress; if (! screen) { return; } if (unixpw && unixpw_in_progress && !unixpw_in_rfbPE) { rfbLog("unixpw_in_rfbPE: skipping rfbCFD\n"); return; } if (usec > USEC_MAX) { usec = USEC_MAX; } if (debug_tiles > 2) { double tm = dnow(); fprintf(stderr, "rfbCFD(%d) t: %.4f\n", (int) usec, tm - x11vnc_start); } #if 0 fprintf(stderr, "handleEventsEagerly: %d\n", screen->handleEventsEagerly); #endif if (! use_threads) { if (all_input) { do_allinput(usec); } else { /* XXX how for cmdline? */ if (all_input) { screen->handleEventsEagerly = TRUE; } else { screen->handleEventsEagerly = FALSE; } rfbCheckFds(screen, usec); } } if (unixpw && unixpw_in_progress && !uip0) { if (!unixpw_in_rfbPE) { rfbLog("rfbCFD: got new client in non-rfbPE\n"); ; /* this is new unixpw client */ } } }
void rfbProcessEvents(rfbScreenInfoPtr rfbScreen,long usec) { rfbClientIteratorPtr i; rfbClientPtr cl,clPrev; if(usec<0) usec=rfbScreen->rfbDeferUpdateTime*1000; rfbCheckFds(rfbScreen,usec); i = rfbGetClientIterator(rfbScreen); cl=rfbClientIteratorHead(i); while(cl) { rfbUpdateClient(cl); clPrev=cl; cl=rfbClientIteratorNext(i); if(clPrev->sock==-1) rfbClientConnectionGone(clPrev); } rfbReleaseClientIterator(i); }
void check_allinput_rate(void) { static double last_all_input_check = 0.0, last_all_input_start = 0.0; static int set = 0; if (! set) { set = 1; last_all_input_check = dnow(); } else { int dt = 4; if (x11vnc_current > last_all_input_check + dt) { int n, nq = 0; while ((n = rfbCheckFds(screen, 0))) { nq += n; } fprintf(stderr, "nqueued: %d\n", nq); if (0 && nq > 25 * dt) { double rate = nq / dt; rfbLog("Client is sending %.1f extra requests per second for the\n", rate); rfbLog("past %d seconds! Switching to -allpinput mode. (queued: %d)\n", dt, nq); all_input = 1; } set = 0; } } }
void VncServer::encodeAndSend(int viewNum, int x0, int y0, int w, int h, const VncServer::ViewParameters ¶m, bool lastView) { //std::cerr << "encodeAndSend: view=" << viewNum << ", c=" << (void *)rgba(viewNum) << ", d=" << depth(viewNum) << std::endl; if (!m_resizeBlocked) { m_firstTile = true; } m_resizeBlocked = true; //vistle::StopWatch timer("encodeAndSend"); const int tileWidth = m_tileWidth, tileHeight = m_tileHeight; static int framecount=0; ++framecount; for (int y=y0; y<y0+h; y+=tileHeight) { for (int x=x0; x<x0+w; x+=tileWidth) { // depth auto dt = new(tbb::task::allocate_root()) EncodeTask(m_resultQueue, viewNum, x, y, std::min(tileWidth, x0+w-x), std::min(tileHeight, y0+h-y), depth(viewNum), m_imageParam, param); tbb::task::enqueue(*dt); ++m_queuedTiles; // color auto ct = new(tbb::task::allocate_root()) EncodeTask(m_resultQueue, viewNum, x, y, std::min(tileWidth, x0+w-x), std::min(tileHeight, y0+h-y), rgba(viewNum), m_imageParam, param); tbb::task::enqueue(*ct); ++m_queuedTiles; } } bool tileReady = false; do { VncServer::EncodeResult result; tileReady = false; if (m_resultQueue.try_pop(result)) { --m_queuedTiles; tileReady = true; if (result.message) { tileMsg &msg = *result.message; if (m_firstTile) { msg.flags |= rfbTileFirst; //std::cerr << "first tile: req=" << msg.requestNumber << std::endl; } m_firstTile = false; if (m_queuedTiles == 0 && lastView) { msg.flags |= rfbTileLast; //std::cerr << "last tile: req=" << msg.requestNumber << std::endl; } msg.frameNumber = framecount; rfbCheckFds(m_screen, 0); rfbHttpCheckFds(m_screen); rfbClientIteratorPtr i = rfbGetClientIterator(m_screen); while (rfbClientPtr cl = rfbClientIteratorNext(i)) { if (cl->clientData) { rfbUpdateClient(cl); if (rfbWriteExact(cl, (char *)&msg, sizeof(msg)) < 0) { rfbLogPerror("sendTileMessage: write header"); } if (result.payload && msg.size > 0) { if (rfbWriteExact(cl, result.payload, msg.size) < 0) { rfbLogPerror("sendTileMessage: write paylod"); } } } rfbUpdateClient(cl); } rfbReleaseClientIterator(i); } delete[] result.payload; delete result.message; } } while (m_queuedTiles > 0 && (tileReady || lastView)); if (lastView) { vassert(m_queuedTiles == 0); m_resizeBlocked = false; deferredResize(); } //sleep(1); }
rfbBool rfbProcessEvents(rfbScreenInfoPtr screen,long usec) { rfbClientIteratorPtr i; rfbClientPtr cl,clPrev; struct timeval tv; rfbBool result=FALSE; extern rfbClientIteratorPtr rfbGetClientIteratorWithClosed(rfbScreenInfoPtr rfbScreen); if(usec<0) usec=screen->deferUpdateTime*1000; rfbCheckFds(screen,usec); rfbHttpCheckFds(screen); i = rfbGetClientIteratorWithClosed(screen); cl=rfbClientIteratorHead(i); while(cl) { if (cl->sock >= 0 && !cl->onHold && FB_UPDATE_PENDING(cl) && !sraRgnEmpty(cl->requestedRegion)) { result=TRUE; if(screen->deferUpdateTime == 0) { rfbSendFramebufferUpdate(cl,cl->modifiedRegion); } else if(cl->startDeferring.tv_usec == 0) { gettimeofday(&cl->startDeferring,NULL); if(cl->startDeferring.tv_usec == 0) cl->startDeferring.tv_usec++; } else { gettimeofday(&tv,NULL); if(tv.tv_sec < cl->startDeferring.tv_sec /* at midnight */ || ((tv.tv_sec-cl->startDeferring.tv_sec)*1000 +(tv.tv_usec-cl->startDeferring.tv_usec)/1000) > screen->deferUpdateTime) { cl->startDeferring.tv_usec = 0; rfbSendFramebufferUpdate(cl,cl->modifiedRegion); } } } if (!cl->viewOnly && cl->lastPtrX >= 0) { if(cl->startPtrDeferring.tv_usec == 0) { gettimeofday(&cl->startPtrDeferring,NULL); if(cl->startPtrDeferring.tv_usec == 0) cl->startPtrDeferring.tv_usec++; } else { struct timeval tv; gettimeofday(&tv,NULL); if(tv.tv_sec < cl->startPtrDeferring.tv_sec /* at midnight */ || ((tv.tv_sec-cl->startPtrDeferring.tv_sec)*1000 +(tv.tv_usec-cl->startPtrDeferring.tv_usec)/1000) > cl->screen->deferPtrUpdateTime) { cl->startPtrDeferring.tv_usec = 0; cl->screen->ptrAddEvent(cl->lastPtrButtons, cl->lastPtrX, cl->lastPtrY, cl); cl->lastPtrX = -1; } } } clPrev=cl; cl=rfbClientIteratorNext(i); if(clPrev->sock==-1) { rfbClientConnectionGone(clPrev); result=TRUE; } } rfbReleaseClientIterator(i); return result; }