}
void
-gacela_client (int rec_channel, int send_channel)
+gacela_client (SCM rec_channel, SCM send_channel)
{
int n;
- char buffer[256];
+ SCM buffer;
char *line;
char *history_path;
if (line && *line)
{
add_history (line);
- write (send_channel, "(", 1);
- n = write (send_channel, line, strlen (line));
- write (send_channel, ")", 1);
- if (n < 0)
- error("ERROR writing to socket");
-
- bzero (buffer, 256);
- n = read (rec_channel, buffer, sizeof (buffer));
- while (n == 0) {
+ scm_write (scm_from_locale_string (line), send_channel);
+ scm_force_output (send_channel);
+
+ while (scm_char_ready_p (rec_channel) == SCM_BOOL_F) {
if (ctrl_c) break;
- sleep (1);
- n = read (rec_channel, buffer, sizeof (buffer));
+ sleep (0.5);
}
- if (n < 0)
- error("ERROR reading from socket");
if (ctrl_c)
ctrl_c = 0;
- else
- printf ("%s\n", buffer);
+ else {
+ buffer = scm_read (rec_channel);
+ printf ("%s\n", scm_to_locale_string (buffer));
+ }
}
free (line);
}
init_gacela (void *data, int argc, char **argv)
{
// Guile configuration
- scm_c_eval_string ("(set-repl-prompt! \"gacela>\")");
+ scm_c_eval_string ("(set-repl-prompt! \"gacela> \")");
scm_c_eval_string ("(use-modules (ice-9 readline))");
scm_c_eval_string ("(activate-readline)");
scm_c_eval_string ("(use-modules (ice-9 optargs))");
scm_c_eval_string ("(start-server pipes)");
}
+/*
void
start_remote_client (char *hostname, int port)
{
close (sockfd);
}
}
+*/
+
+void
+start_remote_client (char *hostname, int port)
+{
+ SCM sockfd;
+ struct hostent *server;
+ struct sockaddr_in serv_addr;
+
+ server = gethostbyname (hostname);
+ bzero ((char *) &serv_addr, sizeof (serv_addr));
+ serv_addr.sin_family = AF_INET;
+ bcopy ((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
+ serv_addr.sin_port = htons (port);
+
+ //sockfd = scm_socket (AF_INET, SOCK_STREAM);
+ // scm_from_sockaddr (serv_addr, sizeof (serv_addr));
+ // scm_connect (sockfd, AF_INET, , scm_from_integer (port));
+}
int
main (int argc, char *argv[])
char *host;
int port = 0;
int i;
- SCM pipes;
+ SCM fd1, fd2;
int pid;
// Checking arguments
else if (mode == 2 && port != 0)
start_server (dirname (argv[0]), port);
else if (mode == 3 && port != 0)
- start_remote_client (host, port);
+ return;
+ //start_remote_client (host, port);
else {
- pipes = scm_pipe ();
+ fd1 = scm_pipe ();
+ fd2 = scm_pipe ();
pid = fork ();
- if (pid == 0)
- start_local_server (dirname (argv[0]), pipes);
- else
- gacela_client (scm_to_int (SCM_CAR (pipes)), scm_to_int (SCM_CDR (pipes)));
+
+ if (pid == 0) {
+ scm_close (SCM_CAR (fd1));
+ scm_close (SCM_CDR (fd2));
+ start_local_server (dirname (argv[0]), scm_cons (SCM_CAR (fd2), SCM_CDR (fd1)));
+ }
+ else {
+ scm_close (SCM_CDR (fd1));
+ scm_close (SCM_CAR (fd2));
+ gacela_client (SCM_CAR (fd1), SCM_CDR (fd2));
+ kill (pid, SIGKILL);
+ }
+
+ /*
+ SCM buffer;
+ if (pid == 0) {
+ printf ("Hijo: 0\n");
+ scm_write (scm_from_locale_string ("Hola mundo\n"), SCM_CDR (pipes));
+ scm_force_output (SCM_CDR (pipes));
+ printf ("Hijo: 1\n");
+ }
+ else {
+ printf ("Padre: 0\n");
+ buffer = scm_read (SCM_CAR (pipes));
+ printf ("%s\n", scm_to_locale_string (buffer));
+ printf ("Padre: 1\n");
+ }
+ */
}
}