mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-13 08:47:50 +01:00
this file owns thread creation now
This commit is contained in:
parent
5582b5be2c
commit
bf6837a9d0
2 changed files with 21 additions and 9 deletions
|
@ -106,23 +106,37 @@ handle_command( const char* buf, int sock )
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void*
|
static void*
|
||||||
ctrl_thread_main( void* arg )
|
ctrl_thread_main( void* arg )
|
||||||
{
|
{
|
||||||
ThreadData* localStorage = (ThreadData*)arg;
|
int socket = (int)arg;
|
||||||
|
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
char buf[512];
|
char buf[512];
|
||||||
ssize_t nGot = recv( localStorage->socket, buf, sizeof(buf)-1, 0 );
|
ssize_t nGot = recv( socket, buf, sizeof(buf)-1, 0 );
|
||||||
if ( nGot <= 1 ) { /* break when just \n comes in */
|
if ( nGot <= 1 ) { /* break when just \n comes in */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[nGot-2] = '\0'; /* kill \r\n stuff */
|
buf[nGot-2] = '\0'; /* kill \r\n stuff */
|
||||||
if ( !handle_command( buf, localStorage->socket ) ) {
|
if ( !handle_command( buf, socket ) ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close ( localStorage->socket );
|
close ( socket );
|
||||||
delete localStorage;
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
run_ctrl_thread( int ctrl_listener )
|
||||||
|
{
|
||||||
|
logf( "calling accept on socket %d\n", ctrl_listener );
|
||||||
|
|
||||||
|
sockaddr newaddr;
|
||||||
|
socklen_t siz = sizeof(newaddr);
|
||||||
|
int newSock = accept( ctrl_listener, &newaddr, &siz );
|
||||||
|
logf( "got one for ctrl: %d", newSock );
|
||||||
|
|
||||||
|
pthread_t thread;
|
||||||
|
int result = pthread_create( &thread, NULL,
|
||||||
|
ctrl_thread_main, (void*)newSock );
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
#ifndef _CTRL_H_
|
#ifndef _CTRL_H_
|
||||||
#define _CTRL_H_
|
#define _CTRL_H_
|
||||||
|
|
||||||
void* ctrl_thread_main( void* arg );
|
void run_ctrl_thread( int ctrl_listener );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue