mirror of
https://github.com/gigablast/open-source-search-engine.git
synced 2024-10-04 04:07:13 +03:00
more fixes for inner loop code
This commit is contained in:
parent
ee070d9378
commit
0b230995ee
34
Loop.cpp
34
Loop.cpp
@ -159,8 +159,8 @@ static fd_set s_selectMaskExcept;
|
||||
|
||||
static int s_readFds[MAX_NUM_FDS];
|
||||
static long s_numReadFds = 0;
|
||||
//static int s_writeFds[MAX_NUM_FDS];
|
||||
//static long s_numWriteFds = 0;
|
||||
static int s_writeFds[MAX_NUM_FDS];
|
||||
static long s_numWriteFds = 0;
|
||||
|
||||
void Loop::unregisterCallback ( Slot **slots , int fd , void *state ,
|
||||
void (* callback)(int fd,void *state) ,
|
||||
@ -209,6 +209,10 @@ void Loop::unregisterCallback ( Slot **slots , int fd , void *state ,
|
||||
s_numWriteFds--;
|
||||
// remove from select mask too
|
||||
FD_CLR(fd,&s_selectMaskWrite);
|
||||
if ( g_conf.m_logDebugLoop )
|
||||
log("loop: clearing fd=%li from "
|
||||
"write #wrts=%li"
|
||||
,(long)fd,(long)s_numWriteFds);
|
||||
// FD_CLR(fd,&s_selectMaskExcept);
|
||||
break;
|
||||
}
|
||||
@ -243,6 +247,10 @@ void Loop::unregisterCallback ( Slot **slots , int fd , void *state ,
|
||||
// . HttpServer.cpp always calls this even if it did not register its
|
||||
// File's fd just to make sure.
|
||||
if ( silent ) return;
|
||||
|
||||
return;
|
||||
// sometimes the socket is abruptly closed and that calls the
|
||||
// unregisterWriteCallback() for us... so skip this
|
||||
log(LOG_LOGIC,
|
||||
"loop: unregisterCallback: callback not found (fd=%i).",fd);
|
||||
}
|
||||
@ -1881,18 +1889,18 @@ void Loop::doPoll ( ) {
|
||||
if ( g_conf.m_logDebugLoop)
|
||||
logf(LOG_DEBUG,"loop: Got %li fds waiting.",n);
|
||||
|
||||
for ( long i = 0 ; i < MAX_NUM_FDS ; i++ ) {
|
||||
// continue if not set for reading
|
||||
if ( FD_ISSET ( i , &readfds ) )
|
||||
log("loop: fd %li is on for read",i);
|
||||
if ( FD_ISSET ( i , &writefds ) )
|
||||
log("loop: fd %li is on for write",i);
|
||||
if ( FD_ISSET ( i , &exceptfds ) )
|
||||
log("loop: fd %li is on for except",i);
|
||||
// debug
|
||||
// for ( long i = 0 ; i < MAX_NUM_FDS ; i++ ) {
|
||||
// // continue if not set for reading
|
||||
// if ( FD_ISSET ( i , &readfds ) )
|
||||
// log("loop: fd %li is on for read",i);
|
||||
// if ( FD_ISSET ( i , &writefds ) )
|
||||
// log("loop: fd %li is on for write",i);
|
||||
// if ( FD_ISSET ( i , &exceptfds ) )
|
||||
// log("loop: fd %li is on for except",i);
|
||||
// // debug
|
||||
|
||||
// if niceness is not -1, handle it below
|
||||
}
|
||||
// // if niceness is not -1, handle it below
|
||||
// }
|
||||
|
||||
// . reset the need to poll flag if everything is caught up now
|
||||
// . let's take this out for now ... won't this leave some
|
||||
|
2
Loop.h
2
Loop.h
@ -223,7 +223,7 @@ class Loop {
|
||||
// . fd of MAX_NUM_FDS is used for sleep callbacks
|
||||
// . fd of MAX_NUM_FDS+1 is used for thread exit callbacks
|
||||
Slot *m_readSlots [MAX_NUM_FDS+2];
|
||||
//Slot *m_writeSlots [MAX_NUM_FDS+2];
|
||||
Slot *m_writeSlots [MAX_NUM_FDS+2];
|
||||
|
||||
// the minimal tick time in milliseconds (ms)
|
||||
long m_minTick;
|
||||
|
@ -1001,11 +1001,12 @@ TcpSocket *TcpServer::wrapSocket ( int sd , long niceness , bool isIncoming ) {
|
||||
if (!g_loop.registerReadCallback (sd,this,readSocketWrapper,niceness))
|
||||
goto hadError;
|
||||
// what does thie really mean? shouldn't we only register for write
|
||||
// if a write we did failed because the buffer was full?
|
||||
if(!g_loop.registerWriteCallback(sd,this,writeSocketWrapper,niceness)){
|
||||
g_loop.unregisterReadCallback(sd,this , readSocketWrapper );
|
||||
goto hadError;
|
||||
}
|
||||
// if a write we did failed because the buffer was full?.
|
||||
// let's do this after the connection request is accepted!
|
||||
//if(!g_loop.registerWriteCallback(sd,this,writeSocketWrapper,niceness)){
|
||||
// g_loop.unregisterReadCallback(sd,this , readSocketWrapper );
|
||||
// goto hadError;
|
||||
//}
|
||||
// return "s" on success
|
||||
return s;
|
||||
// otherwise, free "s" and return NULL
|
||||
@ -1820,7 +1821,23 @@ long TcpServer::connectSocket ( TcpSocket *s ) {
|
||||
goto connected;
|
||||
}
|
||||
// we blocked with the EINPROGRESS g_errno
|
||||
if ( g_errno == EINPROGRESS ) { g_errno = 0; return 0; }
|
||||
if ( g_errno == EINPROGRESS ) {
|
||||
// hopefully this will let us know when the socket is
|
||||
// connected and ready for writing to.
|
||||
if(!g_loop.registerWriteCallback(s->m_sd,
|
||||
this,
|
||||
writeSocketWrapper,
|
||||
s->m_niceness)){
|
||||
log("tcp: failed to reg write callback for sd=%i",
|
||||
s->m_sd);
|
||||
g_loop.unregisterReadCallback(s->m_sd,
|
||||
this ,
|
||||
readSocketWrapper );
|
||||
//goto hadError;
|
||||
}
|
||||
g_errno = 0;
|
||||
return 0;
|
||||
}
|
||||
// return -1 on real error
|
||||
if ( g_conf.m_logDebugTcp )
|
||||
log(LOG_INFO,"tcp: Failed to connect socket: %s, %s:%li",
|
||||
|
Loading…
Reference in New Issue
Block a user