1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_main.cpp
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
32 //-----------------------------------------------------------------------------
36 #include <sys/types.h>
43 extern "C" int yyparse( void );
45 #include "chuck_type.h"
46 #include "chuck_emit.h"
47 #include "chuck_instr.h"
49 #include "chuck_bbq.h"
50 #include "chuck_utils.h"
51 #include "chuck_errmsg.h"
52 #include "util_network.h"
55 #ifndef __PLATFORM_WIN32__
56 #define CHUCK_THREAD pthread_t
59 #include <netinet/in.h>
60 #include <arpa/inet.h>
62 #define CHUCK_THREAD HANDLE
67 #include "ugen_filter.h"
69 #include "ulib_machine.h"
70 #include "ulib_math.h"
75 #define CK_VERSION "1.1.5.6d"
78 #ifdef __PLATFORM_WIN32__
79 // 'C' specification necessary for windows to link properly
80 extern "C" a_Program g_program
;
82 extern a_Program g_program
;
86 Chuck_VM
* g_vm
= NULL
;
88 t_CKBOOL g_error
= FALSE
;
89 CHUCK_THREAD g_tid
= 0;
90 char g_host
[256] = "127.0.0.1";
92 #if defined(__MACOSX_CORE__)
93 t_CKINT g_priority
= 95;
94 #elif defined(__WINDOWS_DS__)
95 t_CKINT g_priority
= 0;
97 t_CKINT g_priority
= 0x7fffffff;
103 //-----------------------------------------------------------------------------
104 // name: signal_int()
106 //-----------------------------------------------------------------------------
107 void signal_int( int sig_num
)
111 Chuck_VM
* vm
= g_vm
;
113 fprintf( stderr
, "[chuck]: cleaning up...\n" );
115 stk_detach( 0, NULL
);
116 #ifndef __PLATFORM_WIN32__
117 // pthread_kill( g_tid, 2 );
118 if( g_tid
) pthread_cancel( g_tid
);
119 if( g_tid
) usleep( 50000 );
122 CloseHandle( g_tid
);
127 #ifndef __PLATFORM_WIN32__
128 // pthread_join( g_tid, NULL );
137 t_CKUINT g_sigpipe_mode
= 0;
138 //-----------------------------------------------------------------------------
139 // name: signal_pipe()
141 //-----------------------------------------------------------------------------
142 void signal_pipe( int sig_num
)
144 fprintf( stderr
, "[chuck]: sigpipe handled - broken pipe (no connection)...\n" );
145 if( g_sigpipe_mode
) exit( 1 );
151 //-----------------------------------------------------------------------------
154 //-----------------------------------------------------------------------------
155 FILE * open_cat( c_str fname
)
158 if( !(fd
= fopen( fname
, "rb" )) )
159 if( !strstr( fname
, ".ck" ) && !strstr( fname
, ".CK" ) )
161 strcat( fname
, ".ck" );
162 fd
= fopen( fname
, "rb" );
170 char filename
[1024] = "";
171 //-----------------------------------------------------------------------------
174 //-----------------------------------------------------------------------------
175 t_CKBOOL
parse( c_str fname
, FILE * fd
= NULL
)
177 t_CKBOOL ret
= FALSE
;
178 strcpy( filename
, fname
);
183 fd
= open_cat( filename
);
184 if( !fd
) strcpy( filename
, fname
);
188 ret
= EM_reset( filename
, fd
);
189 if( ret
== FALSE
) return FALSE
;
190 // TODO: clean g_program
192 ret
= (yyparse( ) == 0);
200 //-----------------------------------------------------------------------------
201 // name: type_check()
203 //-----------------------------------------------------------------------------
204 t_CKBOOL
type_check( t_Env env
, a_Program prog
)
206 t_CKBOOL ret
= FALSE
;
208 type_engine_begin( env
);
209 ret
= type_engine_check_prog( env
, g_program
);
217 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
221 t_CKBOOL
emit_code( Chuck_Emmission
* emit
, t_Env env
, a_Program prog
)
223 t_CKBOOL ret
= FALSE
;
225 ret
= emit_engine_emit_prog( emit
, g_program
);
226 type_engine_end( env
);
234 //-----------------------------------------------------------------------------
235 // name: dump_instr()
237 //-----------------------------------------------------------------------------
238 t_CKBOOL
dump_instr( Chuck_VM_Code
* code
)
240 fprintf( stderr
, "[chuck]: dumping src/shred '%s'...\n", code
->name
.c_str() );
241 fprintf( stderr
, "...\n" );
243 for( unsigned int i
= 0; i
< code
->num_instr
; i
++ )
244 fprintf( stderr
, "'%i' %s( %s )\n", i
,
245 code
->instr
[i
]->name(), code
->instr
[i
]->params() );
247 fprintf( stderr
, "...\n\n" );
255 //-----------------------------------------------------------------------------
256 // name: load_module()
258 //-----------------------------------------------------------------------------
259 t_CKBOOL
load_module( t_Env env
, f_ck_query query
, const char * name
, const char * nspc
)
261 Chuck_DLL
* dll
= NULL
;
264 dll
= new Chuck_DLL( name
);
266 if( !dll
->query() || !type_engine_add_dll( env
, dll
, nspc
) )
269 "[chuck]: internal error loading internal module '%s.%s'...\n",
272 fprintf( stderr
, " %s\n", dll
->last_error() );
283 //-----------------------------------------------------------------------------
286 //-----------------------------------------------------------------------------
289 fprintf( stderr
, "usage: chuck --[options|commands] [+-=^] file1 file2 file3 ...\n" );
290 fprintf( stderr
, " [options] = halt|loop|audio|silent|dump|nodump|about|\n" );
291 fprintf( stderr
, " srate<N>|bufsize<N>|bufnum<N>|dac<N>|adc<N>|\n" );
292 fprintf( stderr
, " remote<hostname>|port<N>\n" );
293 fprintf( stderr
, " [commands] = add|remove|replace|status|time|kill\n" );
294 fprintf( stderr
, " [+-=^] = shortcuts for add, remove, replace, status\n\n" );
295 fprintf( stderr
, "chuck version: %s\n", CK_VERSION
);
296 fprintf( stderr
, " http://chuck.cs.princeton.edu/\n\n" );
302 //-----------------------------------------------------------------------------
305 //-----------------------------------------------------------------------------
306 int send_file( const char * filename
, Net_Msg
& msg
, const char * op
)
311 strcpy( msg
.buffer
, "" );
312 //if( filename[0] != '/' )
314 // strcpy( msg.buffer, getenv("PWD") ? getenv("PWD") : "" );
315 // strcat( msg.buffer, getenv("PWD") ? "/" : "" );
317 strcat( msg
.buffer
, filename
);
320 fd
= open_cat( (char *)msg
.buffer
);
323 fprintf( stderr
, "[chuck]: cannot open file '%s' for [%s]...\n", filename
, op
);
327 if( !parse( (char *)msg
.buffer
, fd
) )
329 fprintf( stderr
, "[chuck]: skipping file '%s' for [%s]...\n", filename
, op
);
335 stat( msg
.buffer
, &fs
);
336 fseek( fd
, 0, SEEK_SET
);
338 //fprintf(stderr, "sending TCP file %s\n", msg.buffer );
339 // send the first packet
340 msg
.param2
= (t_CKUINT
)fs
.st_size
;
343 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
345 // send the whole thing
346 t_CKUINT left
= (t_CKUINT
)fs
.st_size
;
349 //fprintf(stderr,"file %03d bytes left ... ", left);
351 msg
.length
= left
> NET_BUFFER_SIZE
? NET_BUFFER_SIZE
: left
;
353 msg
.param3
= fread( msg
.buffer
, sizeof(char), msg
.length
, fd
);
355 left
-= msg
.param3
? msg
.param3
: 0;
357 //fprintf(stderr, "sending fread %03d length %03d...\n", msg.param3, msg.length );
360 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
365 //fprintf(stderr, "done.\n", msg.buffer );
372 //-----------------------------------------------------------------------------
375 //-----------------------------------------------------------------------------
376 FILE * recv_file( const Net_Msg
& msg
, ck_socket sock
)
381 t_CKUINT left
= msg
.param2
;
383 FILE * fd
= tmpfile();
387 if( !ck_recv( sock
, (char *)&buf
, sizeof(buf
) ) )
391 fwrite( buf
.buffer
, sizeof(char), buf
.length
, fd
);
392 }while( buf
.param2
);
405 //-----------------------------------------------------------------------------
406 // name: process_msg()
408 //-----------------------------------------------------------------------------
409 extern "C" t_CKUINT
process_msg( Net_Msg
* msg
, t_CKBOOL immediate
, void * data
)
411 Chuck_Msg
* cmd
= new Chuck_Msg
;
414 // fprintf( stderr, "UDP message recv...\n" );
415 if( msg
->type
== MSG_REPLACE
|| msg
->type
== MSG_ADD
)
417 // see if entire file is on the way
420 fd
= recv_file( *msg
, (ck_socket
)data
);
423 fprintf( stderr
, "[chuck]: incoming source transfer '%s' failed...\n",
430 if( !parse( msg
->buffer
, fd
) )
434 if( !type_check( g_env
, g_program
) )
438 Chuck_Emmission
* emit
= emit_engine_init( g_env
);
439 if( !emit_code( emit
, g_env
, g_program
) )
442 // transform the code
443 Chuck_VM_Code
* code
= emit_to_code( emit
);
444 code
->name
= msg
->buffer
;
445 cmd
->shred
= new Chuck_VM_Shred
;
446 cmd
->shred
->initialize( code
);
447 cmd
->shred
->name
= code
->name
;
448 emit_engine_addr_map( emit
, cmd
->shred
);
449 emit_engine_resolve();
450 emit_engine_shutdown( emit
);
452 // set the flags for the command
453 cmd
->type
= msg
->type
;
455 if( msg
->type
== MSG_REPLACE
)
456 cmd
->param
= msg
->param
;
458 else if( msg
->type
== MSG_STATUS
|| msg
->type
== MSG_REMOVE
|| msg
->type
== MSG_REMOVEALL
459 || msg
->type
== MSG_KILL
|| msg
->type
== MSG_TIME
)
461 cmd
->type
= msg
->type
;
462 cmd
->param
= msg
->param
;
466 fprintf( stderr
, "[chuck]: unrecognized incoming command from network: '%i'\n", cmd
->type
);
473 return g_vm
->process_msg( cmd
);
475 g_vm
->queue_msg( cmd
, 1 );
483 //-----------------------------------------------------------------------------
484 // name: load_internal_modules()
486 //-----------------------------------------------------------------------------
487 t_CKBOOL
load_internal_modules( t_Env env
)
490 load_module( env
, osc_query
, "osc", "global" );
491 load_module( env
, xxx_query
, "xxx", "global" );
492 load_module( env
, filter_query
, "filter", "global" );
493 load_module( env
, stk_query
, "stk", "global" );
496 load_module( env
, machine_query
, "machine", "machine" );
497 machine_init( g_vm
, process_msg
);
498 load_module( env
, libstd_query
, "std", "std" );
499 load_module( env
, libmath_query
, "math", "math" );
500 load_module( env
, net_query
, "net", "net" );
508 //-----------------------------------------------------------------------------
511 //-----------------------------------------------------------------------------
512 void * timer( void * p
)
515 t_CKUINT t
= *(t_CKUINT
*)p
;
518 fprintf( stderr
, "[chuck]: operation timed out...\n" );
525 //-----------------------------------------------------------------------------
528 //-----------------------------------------------------------------------------
529 void * cb( void * p
)
536 #ifndef __PLATFORM_WIN32__
538 signal( SIGPIPE
, signal_pipe
);
543 client
= ck_accept( g_sock
);
546 if( g_vm
) fprintf( stderr
, "[chuck]: socket error during accept()...\n" );
553 ck_recv_timeout( client
, 0, 5000000 );
554 n
= ck_recv( client
, (char *)&msg
, sizeof(msg
) );
556 if( n
!= sizeof(msg
) )
558 fprintf( stderr
, "[chuck]: 0-length packet...\n", (int)client
);
564 if( msg
.header
!= NET_HEADER
)
566 fprintf( stderr
, "[chuck]: header mismatch - possible endian lunacy...\n" );
571 while( msg
.type
!= MSG_DONE
)
575 if( !process_msg( &msg
, FALSE
, client
) )
578 strcpy( (char *)ret
.buffer
, EM_lasterror() );
579 while( msg
.type
!= MSG_DONE
&& n
)
581 n
= ck_recv( client
, (char *)&msg
, sizeof(msg
) );
589 strcpy( (char *)ret
.buffer
, "success" );
590 n
= ck_recv( client
, (char *)&msg
, sizeof(msg
) );
597 ck_send( client
, (char *)&ret
, sizeof(ret
) );
607 //-----------------------------------------------------------------------------
608 // name: send_connect()
610 //-----------------------------------------------------------------------------
613 g_sock
= ck_tcp_create( 0 );
616 fprintf( stderr
, "[chuck]: cannot open socket to send command...\n" );
620 if( strcmp( g_host
, "127.0.0.1" ) )
621 fprintf( stderr
, "[chuck]: connecting to %s on port %i via TCP...\n", g_host
, g_port
);
623 if( !ck_connect( g_sock
, g_host
, g_port
) )
625 fprintf( stderr
, "[chuck]: cannot open TCP socket on %s:%i...\n", g_host
, g_port
);
629 ck_send_timeout( g_sock
, 0, 2000000 );
637 //-----------------------------------------------------------------------------
640 //-----------------------------------------------------------------------------
641 int send_cmd( int argc
, char ** argv
, int & i
)
646 int tasks_total
= 0, tasks_done
= 0;
648 if( !strcmp( argv
[i
], "--add" ) || !strcmp( argv
[i
], "+" ) )
652 fprintf( stderr
, "[chuck]: not enough arguments following [add]...\n" );
656 if( !send_connect() ) return 0;
660 tasks_done
+= send_file( argv
[i
], msg
, "add" );
662 } while( ++i
< argc
);
667 else if( !strcmp( argv
[i
], "--remove" ) || !strcmp( argv
[i
], "-" ) )
671 fprintf( stderr
, "[chuck]: not enough arguments following [remove]...\n" );
675 if( !send_connect() ) return 0;
677 msg
.param
= atoi( argv
[i
] );
678 msg
.type
= MSG_REMOVE
;
680 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
681 } while( ++i
< argc
);
683 else if( !strcmp( argv
[i
], "--" ) )
685 if( !send_connect() ) return 0;
686 msg
.param
= 0xffffffff;
687 msg
.type
= MSG_REMOVE
;
689 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
691 else if( !strcmp( argv
[i
], "--replace" ) || !strcmp( argv
[i
], "=" ) )
695 fprintf( stderr
, "[chuck]: not enough arguments following [replace]...\n" );
700 msg
.param
= 0xffffffff;
702 msg
.param
= atoi( argv
[i
] );
706 fprintf( stderr
, "[chuck]: not enough arguments following [replace]...\n" );
710 if( !send_connect() ) return 0;
711 msg
.type
= MSG_REPLACE
;
712 if( !send_file( argv
[i
], msg
, "replace" ) )
715 else if( !strcmp( argv
[i
], "--removeall" ) || !strcmp( argv
[i
], "--remall" ) )
717 if( !send_connect() ) return 0;
718 msg
.type
= MSG_REMOVEALL
;
721 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
723 else if( !strcmp( argv
[i
], "--kill" ) )
725 if( !send_connect() ) return 0;
726 msg
.type
= MSG_REMOVEALL
;
729 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
731 msg
.param
= (i
+1)<argc
? atoi(argv
[++i
]) : 0;
733 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
735 else if( !strcmp( argv
[i
], "--time" ) )
737 if( !send_connect() ) return 0;
741 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
743 else if( !strcmp( argv
[i
], "--status" ) || !strcmp( argv
[i
], "^" ) )
745 if( !send_connect() ) return 0;
746 msg
.type
= MSG_STATUS
;
749 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
757 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
760 ck_recv_timeout( g_sock
, 0, 2000000 );
762 if( ck_recv( g_sock
, (char *)&msg
, sizeof(msg
) ) )
765 fprintf( stderr
, "[chuck(remote)]: operation %s\n", ( msg
.param
? "successful" : "failed (sorry)" ) );
767 fprintf( stderr
, "(reason): %s\n",
768 ( strstr( (char *)msg
.buffer
, ":" ) ? strstr( (char *)msg
.buffer
, ":" ) + 1 : (char *)msg
.buffer
) ) ;
772 fprintf( stderr
, "[chuck]: remote operation timed out...\n" );
785 ck_send( g_sock
, (char *)&msg
, sizeof(msg
) );
795 //-----------------------------------------------------------------------------
796 // name: next_power_2()
798 // thanks: to Niklas Werner / music-dsp
799 //-----------------------------------------------------------------------------
800 t_CKUINT
next_power_2( t_CKUINT n
)
803 for( ; n
&= n
-1; nn
= n
);
810 //-----------------------------------------------------------------------------
813 //-----------------------------------------------------------------------------
814 int main( int argc
, char ** argv
)
817 t_CKBOOL enable_audio
= TRUE
;
818 t_CKBOOL vm_halt
= TRUE
;
819 t_CKUINT srate
= SAMPLING_RATE_DEFAULT
;
820 t_CKUINT buffer_size
= BUFFER_SIZE_DEFAULT
;
821 t_CKUINT num_buffers
= 8;
824 t_CKBOOL set_priority
= FALSE
;
827 signal( SIGINT
, signal_int
);
828 #ifndef __PLATFORM_WIN32__
830 signal( SIGPIPE
, signal_pipe
);
833 for( i
= 1; i
< argc
; i
++ )
835 if( argv
[i
][0] == '-' || argv
[i
][0] == '+' ||
836 argv
[i
][0] == '=' || argv
[i
][0] == '^' || argv
[i
][0] == '@' )
838 if( !strcmp(argv
[i
], "--dump") || !strcmp(argv
[i
], "+d")
839 || !strcmp(argv
[i
], "--nodump") || !strcmp(argv
[i
], "-d") )
841 else if( !strcmp(argv
[i
], "--audio") || !strcmp(argv
[i
], "-a") )
843 else if( !strcmp(argv
[i
], "--silent") || !strcmp(argv
[i
], "-s") )
844 enable_audio
= FALSE
;
845 else if( !strcmp(argv
[i
], "--halt") || !strcmp(argv
[i
], "-t") )
847 else if( !strcmp(argv
[i
], "--loop") || !strcmp(argv
[i
], "-l") )
849 else if( !strncmp(argv
[i
], "--srate", 7) )
850 srate
= atoi( argv
[i
]+7 ) > 0 ? atoi( argv
[i
]+7 ) : srate
;
851 else if( !strncmp(argv
[i
], "-r", 2) )
852 srate
= atoi( argv
[i
]+2 ) > 0 ? atoi( argv
[i
]+2 ) : srate
;
853 else if( !strncmp(argv
[i
], "--bufsize", 9) )
854 buffer_size
= atoi( argv
[i
]+9 ) > 0 ? atoi( argv
[i
]+9 ) : buffer_size
;
855 else if( !strncmp(argv
[i
], "-b", 2) )
856 buffer_size
= atoi( argv
[i
]+2 ) > 0 ? atoi( argv
[i
]+2 ) : buffer_size
;
857 else if( !strncmp(argv
[i
], "--bufnum", 8) )
858 num_buffers
= atoi( argv
[i
]+8 ) > 0 ? atoi( argv
[i
]+8 ) : num_buffers
;
859 else if( !strncmp(argv
[i
], "-n", 2) )
860 num_buffers
= atoi( argv
[i
]+2 ) > 0 ? atoi( argv
[i
]+2 ) : num_buffers
;
861 else if( !strncmp(argv
[i
], "--dac", 5) )
862 dac
= atoi( argv
[i
]+5 ) > 0 ? atoi( argv
[i
]+5 ) : 0;
863 else if( !strncmp(argv
[i
], "--adc", 5) )
864 adc
= atoi( argv
[i
]+5 ) > 0 ? atoi( argv
[i
]+5 ) : 0;
865 else if( !strncmp(argv
[i
], "--level", 7) )
866 { g_priority
= atoi( argv
[i
]+7 ); set_priority
= TRUE
; }
867 else if( !strncmp(argv
[i
], "--remote", 8) )
868 strcpy( g_host
, argv
[i
]+8 );
869 else if( !strncmp(argv
[i
], "@", 1) )
870 strcpy( g_host
, argv
[i
]+1 );
871 else if( !strncmp(argv
[i
], "--port", 6) )
872 g_port
= atoi( argv
[i
]+6 );
873 else if( !strncmp(argv
[i
], "-p", 2) )
874 g_port
= atoi( argv
[i
]+2 );
875 else if( !strcmp(argv
[i
], "--help") || !strcmp(argv
[i
], "-h")
876 || !strcmp(argv
[i
], "--about") )
881 else if( a
= send_cmd( argc
, argv
, i
) )
885 fprintf( stderr
, "[chuck]: invalid flag '%s'\n", argv
[i
] );
895 buffer_size
= next_power_2( buffer_size
-1 );
896 // if audio then boost priority
897 if( !set_priority
&& !enable_audio
) g_priority
= 0x7fffffff;
899 Chuck_VM::our_priority
= g_priority
;
901 if ( !files
&& vm_halt
)
903 fprintf( stderr
, "[chuck]: no input files... (try --help)\n" );
908 Chuck_VM
* vm
= g_vm
= new Chuck_VM
;
909 if( !vm
->initialize( enable_audio
, vm_halt
, srate
, buffer_size
,
910 num_buffers
, dac
, adc
, g_priority
) )
912 fprintf( stderr
, "[chuck]: %s\n", vm
->last_error() );
916 // allocate the type system
917 g_env
= type_engine_init( vm
);
919 vm
->set_env( g_env
);
921 if( !load_internal_modules( g_env
) || g_error
)
924 Chuck_VM_Code
* code
= NULL
;
925 Chuck_VM_Shred
* shred
= NULL
;
926 t_CKBOOL dump
= FALSE
;
927 for( i
= 1; i
< argc
; i
++ )
929 if( argv
[i
][0] == '-' || argv
[i
][0] == '+' )
931 if( !strcmp(argv
[i
], "--dump") || !strcmp(argv
[i
], "+d" ) )
933 else if( !strcmp(argv
[i
], "--nodump") || !strcmp(argv
[i
], "-d" ) )
940 if( !parse( argv
[i
] ) )
944 if( !type_check( g_env
, g_program
) )
948 Chuck_Emmission
* emit
= emit_engine_init( g_env
);
949 if( !emit_code( emit
, g_env
, g_program
) )
952 // transform the code
953 code
= emit_to_code( emit
, dump
);
954 code
->name
= argv
[i
];
957 if( dump
) dump_instr( code
);
960 shred
= vm
->spork( code
, NULL
);
963 emit_engine_addr_map( emit
, shred
);
966 emit_engine_resolve( );
968 // cleanup the emitter
969 emit_engine_shutdown( emit
);
973 // emit_engine_resolve_globals();
976 g_sock
= ck_tcp_create( 1 );
977 if( !g_sock
|| !ck_bind( g_sock
, g_port
) || !ck_listen( g_sock
, 10 ) )
979 fprintf( stderr
, "[chuck]: cannot bind to tcp port %i...\n", g_port
);
985 #ifndef __PLATFORM_WIN32__
986 pthread_create( &g_tid
, NULL
, cb
, NULL
);
988 g_tid
= CreateThread(NULL
, 0, (LPTHREAD_START_ROUTINE
)cb
, NULL
, 0, 0);
1000 #ifndef __PLATFORM_WIN32__
1001 pthread_kill( g_tid
, 2 );
1003 CloseHandle( g_tid
);