Merge branch 'relay_proxy' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into relay_proxy

This commit is contained in:
eehouse@eehouse.org 2010-09-09 04:21:02 -07:00 committed by Andy2
commit a79f50053b
3 changed files with 32 additions and 11 deletions

View file

@ -513,10 +513,10 @@ CRefMgr::AddNew( const char* cookie, const char* connName, CookieID id )
logf( XW_LOGINFO, "making new cref: %d", id );
if ( !!ref ) {
logf( XW_LOGINFO, "using from free list" );
logf( XW_LOGVERBOSE1, "using from free list" );
ref->ReInit( cookie, connName, id );
} else {
logf( XW_LOGINFO, "calling constructor" );
logf( XW_LOGVERBOSE1, "calling constructor" );
ref = new CookieRef( cookie, connName, id );
}

View file

@ -197,14 +197,22 @@ printStats( FILE* fil, const CrefMgrInfo* info, bool isLocal )
fprintf( fil, "</table>" );
}
class HttpInstance {
public:
HttpInstance( int sock, HttpState* state ) {
m_sock = sock;
m_state = state;
}
int m_sock;
HttpState* m_state;
};
static void*
http_thread_main( void* arg )
{
HttpState* state = (HttpState*)arg;
sockaddr newaddr;
socklen_t siz = sizeof(newaddr);
int sock = accept( state->ctrl_sock, &newaddr, &siz );
HttpInstance* inst = (HttpInstance*)arg;
HttpState* state = inst->m_state;
int sock = inst->m_sock;
char buf[512];
ssize_t totalRead = 0;
@ -275,6 +283,8 @@ http_thread_main( void* arg )
}
close( sock );
delete inst;
return NULL;
} /* http_thread_main */
@ -282,13 +292,18 @@ void
run_http_thread( HttpState* state )
{
pthread_t thread;
int result = pthread_create( &thread, NULL,
http_thread_main, (void*)state );
sockaddr newaddr;
socklen_t siz = sizeof(newaddr);
int sock = accept( state->ctrl_sock, &newaddr, &siz );
HttpInstance* inst = new HttpInstance( sock, state );
int result = pthread_create( &thread, NULL, http_thread_main,
(void*)inst );
if ( 0 == result ) {
pthread_detach( thread );
} else {
/* logf( XW_LOGERROR, "%s: pthread_create failed: %s", __func__, */
/* strerror(errno) ); */
logf( XW_LOGERROR, "%s: pthread_create failed: %s", __func__,
strerror(errno) );
}
} /* run_http_thread */

View file

@ -238,7 +238,9 @@ XWThreadPool::real_tpool_main()
void
XWThreadPool::interrupt_poll()
{
#ifdef LOG_POLL
logf( XW_LOGINFO, __func__ );
#endif
unsigned char byt = 0;
int nSent = write( m_pipeWrite, &byt, 1 );
if ( nSent != 1 ) {
@ -304,7 +306,9 @@ XWThreadPool::real_listener()
logf( XW_LOGINFO, "polling %s nmillis=%d", log, nMillis );
#endif
int nEvents = poll( fds, nSockets, nMillis );
#ifdef LOG_POLL
logf( XW_LOGINFO, "back from poll: %d", nEvents );
#endif
if ( m_timeToDie ) {
break;
}
@ -317,7 +321,9 @@ XWThreadPool::real_listener()
}
if ( fds[0].revents != 0 ) {
#ifdef LOG_POLL
logf( XW_LOGINFO, "poll interrupted" );
#endif
assert( fds[0].revents == POLLIN );
unsigned char byt;
read( fds[0].fd, &byt, 1 );