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 ); logf( XW_LOGINFO, "making new cref: %d", id );
if ( !!ref ) { if ( !!ref ) {
logf( XW_LOGINFO, "using from free list" ); logf( XW_LOGVERBOSE1, "using from free list" );
ref->ReInit( cookie, connName, id ); ref->ReInit( cookie, connName, id );
} else { } else {
logf( XW_LOGINFO, "calling constructor" ); logf( XW_LOGVERBOSE1, "calling constructor" );
ref = new CookieRef( cookie, connName, id ); ref = new CookieRef( cookie, connName, id );
} }

View file

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

View file

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