@@ -57,8 +57,11 @@ var NODE_BIN = '/usr/local/bin/node';
5757var PYTHON2_BIN = '/usr/bin/python' ;
5858var PYTHON3_BIN = '/usr/local/bin/python3.3' ;
5959
60- var TIMEOUT_SECS = 3 ;
60+ var TIMEOUT_SECS = 5 ;
6161var JAVA_TIMEOUT_SECS = 15 ; // the Java backend is SUPER SLOW :/
62+ var CPP_TIMEOUT_SECS = 15 ; // the C/C++ backend is also SUPER SLOW :/
63+
64+ var MAX_BUFFER_SIZE = 10 * 1024 * 1024 ;
6265
6366
6467// bind() res and useJSONP before using
@@ -149,7 +152,7 @@ function exec_js_handler(useJSONP /* use bind first */, isTypescript /* use bind
149152
150153 child_process . execFile ( exeFile , args ,
151154 { timeout : TIMEOUT_SECS * 1000 /* milliseconds */ ,
152- maxBuffer : 5000 * 1024 /* 5MB data max */ ,
155+ maxBuffer : MAX_BUFFER_SIZE ,
153156 // make SURE docker gets the kill signal;
154157 // this signal seems to allow docker to clean
155158 // up after itself to --rm the container, but
@@ -199,7 +202,7 @@ function exec_java_handler(useJSONP /* use bind first */, req, res) {
199202
200203 child_process . execFile ( exeFile , args ,
201204 { timeout : JAVA_TIMEOUT_SECS * 1000 /* milliseconds */ ,
202- maxBuffer : 5000 * 1024 /* 10MB data max */ ,
205+ maxBuffer : MAX_BUFFER_SIZE ,
203206 // make SURE docker gets the kill signal;
204207 // this signal seems to allow docker to clean
205208 // up after itself to --rm the container, but
@@ -232,7 +235,41 @@ function exec_ruby_handler(useJSONP /* use bind first */, req, res) {
232235
233236 child_process . execFile ( exeFile , args ,
234237 { timeout : TIMEOUT_SECS * 1000 /* milliseconds */ ,
235- maxBuffer : 5000 * 1024 /* 5MB data max */ ,
238+ maxBuffer : MAX_BUFFER_SIZE ,
239+ // make SURE docker gets the kill signal;
240+ // this signal seems to allow docker to clean
241+ // up after itself to --rm the container, but
242+ // double-check with 'docker ps -a'
243+ killSignal : 'SIGINT' } ,
244+ postExecHandler . bind ( null , res , useJSONP ) ) ;
245+ }
246+
247+ app . get ( '/exec_c' , exec_cpp_handler . bind ( null , false , false ) ) ;
248+ app . get ( '/exec_c_jsonp' , exec_cpp_handler . bind ( null , false , true ) ) ;
249+ app . get ( '/exec_cpp' , exec_cpp_handler . bind ( null , true , false ) ) ;
250+ app . get ( '/exec_cpp_jsonp' , exec_cpp_handler . bind ( null , true , true ) ) ;
251+
252+ function exec_cpp_handler ( useCPP /* use bind first */ , useJSONP /* use bind first */ , req , res ) {
253+ var usrCod = req . query . user_script ;
254+
255+ var exeFile ;
256+ var args = [ ] ;
257+
258+ if ( USE_DOCKER_SANDBOX ) {
259+ // this needs to match the docker setup in Dockerfile
260+ exeFile = '/usr/bin/docker' ; // absolute path to docker executable
261+ args . push ( 'run' , '--rm' , '--user=netuser' , '--net=none' , '--cap-drop' , 'all' , 'pgbovine/opt-cpp-backend:v1' ,
262+ '/tmp/opt-cpp-backend/run-cpp-backend.sh' ,
263+ usrCod ,
264+ useCPP ? 'cpp' : 'c' ) ;
265+ } else {
266+ assert ( false ) ;
267+ // must use Docker
268+ }
269+
270+ child_process . execFile ( exeFile , args ,
271+ { timeout : CPP_TIMEOUT_SECS * 1000 /* milliseconds */ ,
272+ maxBuffer : MAX_BUFFER_SIZE ,
236273 // make SURE docker gets the kill signal;
237274 // this signal seems to allow docker to clean
238275 // up after itself to --rm the container, but
@@ -241,6 +278,8 @@ function exec_ruby_handler(useJSONP /* use bind first */, req, res) {
241278 postExecHandler . bind ( null , res , useJSONP ) ) ;
242279}
243280
281+
282+
244283function executePython ( pyVer , req , res ) {
245284 var parsedOptions = JSON . parse ( req . query . options_json ) ;
246285
@@ -277,7 +316,7 @@ function executePython(pyVer, req, res) {
277316
278317 child_process . execFile ( exeFile , args ,
279318 { timeout : TIMEOUT_SECS * 1000 /* milliseconds */ ,
280- maxBuffer : 5000 * 1024 /* 5MB data max */ ,
319+ maxBuffer : MAX_BUFFER_SIZE ,
281320 // make SURE docker gets the kill signal;
282321 // this signal seems to allow docker to clean
283322 // up after itself to --rm the container, but
0 commit comments