From: jsancho Date: Tue, 26 Jul 2011 18:36:06 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=5529af7c3a48a6231247ae8d472f359b6c75e938;p=gacela.git --- diff --git a/src/gacela.c b/src/gacela.c index 3357b0c..10aee8d 100644 --- a/src/gacela.c +++ b/src/gacela.c @@ -270,6 +270,10 @@ main (int argc, char *argv[]) SCM pipes; int pid; + char *string = "prueba\n"; + int p[2]; + char buffer[150]; + // Checking arguments for (i = 1; i < argc; i++) { if (strcmp (argv[i], "--shell-mode") == 0) @@ -304,11 +308,46 @@ main (int argc, char *argv[]) //start_remote_client (host, port); return; else { + /* pipes = scm_pipe (); pid = fork (); + if (pid == 0) start_local_server (dirname (argv[0]), pipes); else gacela_client (SCM_CAR (pipes), SCM_CDR (pipes)); + */ + /* + if (pid == 0) { + scm_write (scm_from_locale_string ("prueba"), SCM_CDR (pipes)); + sleep (10); + } + else { + while (scm_char_ready_p (SCM_CAR (pipes)) == SCM_BOOL_F) { + sleep (1); + printf ("1\n"); + } + SCM buffer; + buffer = scm_read_line (SCM_CAR (pipes)); + printf ("%s\n", scm_to_locale_string (buffer)); + } + */ + FILE *stream; + pipe (p); + if (pid == 0) { + close (p[1]); + stream = fdopen (p[0], "w"); + fprintf (stream, "prueba\n"); + fclose (stream); + printf ("1\n"); + sleep (10); + } + else { + int c; + close (p[0]); + stream = fdopen (p[1], "r"); + while ((c = fgetc (stream)) != EOF) + putchar (c); + } } } diff --git a/src/gacela_server.scm b/src/gacela_server.scm index aae6c04..eff6954 100644 --- a/src/gacela_server.scm +++ b/src/gacela_server.scm @@ -57,25 +57,10 @@ (set! eval-from-clients (lambda () + (cond (pipes + (eval-from-client (car pipes) (cdr pipes)))) (for-each - (lambda (cli) - (let ((sock (car cli))) - (cond ((char-ready? sock) - (catch #t - (lambda () - (let ((exp (read sock))) - (format #t "~a~%" exp) - (cond ((eof-object? exp) - (close sock)) - (else - (format #t "~a~%" (primitive-eval (car exp))) - (format sock "~a" (primitive-eval (car exp))))))) - (lambda (key . args) - (let ((fmt (string-concatenate (list (cadr args) "~%"))) - (params (caddr args))) - (if params - (apply format (cons sock (cons fmt params))) - (format sock fmt))))))))) + (lambda (cli) (eval-from-client (car cli) (car cli))) clients))) (set! stop-server @@ -85,3 +70,21 @@ (set! server-socket #f))) (for-each (lambda (cli) (close (car cli))) clients) (set! clients '())))) + +(define (eval-from-client rec-channel send-channel) + (cond ((char-ready? rec-channel) + (catch #t + (lambda () + (let ((exp (read rec-channel))) + (format #t "~a~%" exp) + (cond ((eof-object? exp) + (close rec-channel)) + (else + (format #t "~a~%" (primitive-eval (car exp))) + (format send-channel "~a" (primitive-eval (car exp))))))) + (lambda (key . args) + (let ((fmt (string-concatenate (list (cadr args) "~%"))) + (params (caddr args))) + (if params + (apply format (cons send-channel (cons fmt params))) + (format send-channel fmt))))))))