/* call PR_Poll and call Netlib if necessary * * return FALSE if nothing to do. */ PUBLIC XP_Bool NET_PollSockets(void) { static PRIntervalTime interval = 0; register unsigned int itmp; if(net_calling_all_the_time_count) NET_ProcessNet(NULL, NET_EVERYTIME_TYPE); if(!interval) interval = PR_MillisecondsToInterval(1); if(1 > fd_set_size) return FALSE; itmp = PR_Poll(poll_desc_array, fd_set_size, interval); if(itmp < 1) return TRUE; /* potential for doing stuff in the future. */ /* for now call on all active sockets. */ /* if this is too much call only one, but reorder the list each time. */ for(itmp=0; itmp < fd_set_size; itmp++) { if(poll_desc_array[itmp].out_flags) NET_ProcessNet(poll_desc_array[itmp].fd, NET_SOCKET_FD); } return TRUE; }
void net_process_net_timer_callback(void *closure) { if(!NET_ProcessNet(NULL, NET_EVERYTIME_TYPE)) return; /* dont reset the timer */ if(net_calling_all_the_time_count) FE_SetTimeout(net_process_net_timer_callback, NULL, 1); }
void net_process_slow_net_timer_callback(void *closure) { if(!NET_ProcessNet(NULL, NET_EVERYTIME_TYPE)) net_slow_timer_on = FALSE; /* dont reset the timer */ else if (net_slow_timer_on) FE_SetTimeout(net_process_slow_net_timer_callback, NULL, SLOW_NETLIB_TIMER_INTERVAL_MILLISECONDS); }
LONG CHiddenFrame::OnForceIOSelect(WPARAM wParam, LPARAM lParam) { // Net dike. (see hiddenfr.h) // This code protects external message loops from the flood // of network messages we would normally handle, thus // keeping the app responsive while in a different // message loop. External message loops being loops // other than CNetscapeApp::NSPumpMessage. BOOL bDoHandle = TRUE; if(::GetMessageTime() != (LONG)theApp.GetMessageTime()) { // Message came from different message loop than one // found in CNetscapeApp::NSPumpMessage. BOOL bReposted = FALSE; // In the CNetscapeApp::NSPumpMessage this variable is // usually incremented on EVERY MESSAGE. Note the // difference here that we are incrementing it only // on receipt of a network message, causing a much // smaller window for these messages to get through. // A small counter-balance is that we are going to // repost the message, which causes this function // to be entered again at some later time (thus // incrementing the counter, etc). // CNetscapeApp::NSPumpMessage only peeks and // does not generate the overhead of yet another // message, unlike this suboptimal code. gNetFloodStage++; // 1 : NET_FLOWCONTROL, we force a network event to be // handled regardless of the queue state. if((gNetFloodStage % NET_FLOWCONTROL) != 0) { // See if there are messages not our own in the queue. MSG msg; if(::PeekMessage(&msg, NULL, 0, NET_MESSAGERANGE, PM_NOREMOVE)) { // There are, repost till next time. // We use a 1 millisecond timeout, based on what we know // timers actually do. Timers don't fire until the // queue is empty; thus the message will repost once // all other stuff is done. bDoHandle = FALSE; wfe_PostDelayedMessage(msg_ForceIOSelect, wParam, lParam, 1); } } } if(bDoHandle) { SelectType stType = (SelectType)wParam; PRFileDesc *iFD = (PRFileDesc *)lParam; int iNetlibType = NET_SOCKET_FD; if(stType == FileSelect) { iNetlibType = NET_LOCAL_FILE_FD; } else if(stType == NetlibSelect) { iNetlibType = NET_EVERYTIME_TYPE; } // Must be socket or have in select list to continue. // We don't check sockets here, as it is too difficult to // segregate them out into their different select NetLib // categories (see feselect.cpp). // // LJM removed call to HasSelect for nspr20 port // if(iNetlibType == NET_SOCKET_FD || selecttracker.HasSelect(stType, iFD)) { if(iNetlibType == NET_SOCKET_FD) { int iWantMore = 1; BOOL bCalledNetlib = FALSE; if(winfeInProcessNet == FALSE) { winfeInProcessNet = TRUE; iWantMore = NET_ProcessNet(iFD, iNetlibType); bCalledNetlib = TRUE; winfeInProcessNet = FALSE; } if(bCalledNetlib == FALSE) { // Wait to repost message, as we are in the callstack of netlib. // If a dialog is up, then we don't want to max the CPU by posting // of the same message over and over and the user can't hit // a button. wfe_PostDelayedMessage(msg_ForceIOSelect, wParam, lParam); } // LJM removed call to SSL_DataPending for NSPR20 port else if(0 != iWantMore && (NET_SOCKET_FD != iNetlibType)) { // Sockets don't need reposting if actually called netlib, // as they will post messages themselves when data is ready. // This is not true if they have SSL data buffered. // However, we do repost for files, as they are ready for more. PostMessage(msg_ForceIOSelect, wParam, lParam); } } } // Always handled. return(1); }