chiark / gitweb /
*** empty log message ***
[sympathy.git] / apps / sympathyd.c
index a535ac6a34c7a7bb38e63ca8c73ea0f87c5b3e26..2e45ed1b8d74f2c0eedbc4243608a9f0342a4693 100644 (file)
@@ -10,6 +10,15 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.5  2008/02/13 18:05:06  james
+ * *** empty log message ***
+ *
+ * Revision 1.4  2008/02/13 17:21:55  james
+ * *** empty log message ***
+ *
+ * Revision 1.3  2008/02/08 15:06:52  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/07 15:42:49  james
  * *** empty log message ***
  *
@@ -18,36 +27,85 @@ static char rcsid[] = "$Id$";
  *
  */
 
-#include "sympathy.h"
-#include "ipc.h"
+#include <sympathy.h>
 
-int main(int argc,char *argv[])
+#include "client.h"
+#include "clients.h"
+
+int main (int argc,char *argv[])
 {
-int fd;
-struct sockaddr_un sun={0};
+  fd_set rfds, wfds;
+  ANSI a = { 0 };
+  Context c;
+  Socket *s, *cs;
+  Clients *clients;
 
-fd=socket(PF_UNIX,SOCK_STREAM,0);
-if (fd<0) {
-       perror("socket");
-       exit(1);
-}
 
-sun.sun_family=AF_UNIX;
-strcpy(sun.sun_path,SOCKPATH);
+  s = socket_listen ("socket");
 
-unlink(SOCKPATH);
+  c.t = ptty_open (NULL, NULL);
+  c.v = vt102_new ();
+  c.h = history_new (200);
+  c.l = file_log_new ("log");
 
-if (bind(fd,(struct sockaddr *) &sun,sizeof(sun))<0)  {
-       perror("bind");
-       exit(1);
-}
+  terminal_register_handlers ();
+  a.terminal = terminal_open (0, 1);
 
-if (listen(fd,5)<0) {
-       perror("listen");
-       exit(1);
-}
+  ansi_reset (&a, NULL);
+
+  clients=clients_new();
+
+  for (;;)
+    {
+      struct timeval tv = { 0, 100000 };
+
+
+      FD_ZERO (&rfds);
+      FD_ZERO (&wfds);
+
+      tty_pre_select (c.t, &rfds,&wfds);
+      tty_pre_select (a.terminal, &rfds,&wfds);
+
+      socket_pre_select (s, &rfds, &wfds);
+
+      clients_pre_select (clients,&rfds,&wfds);
+
+      select (FD_SETSIZE, &rfds, NULL, NULL, &tv);
+
+      cs = socket_post_select (s, &rfds, &wfds);
+
+      if (cs)
+        {
+          /*New client connexion */
+          clients_new_client (clients, cs, &c);
+        }
+
+
+      clients_post_select (clients, &c, &rfds, &wfds);
+
+      if (FD_ISSET (c.t->rfd, &rfds))
+        {
+          char buf[1024];
+          int red;
+
+          red = c.t->recv (c.t, buf, sizeof (buf));
 
+          if (red < 0)
+            break;
 
+          if (red)
+            {
+              clients_output (clients, buf, red);
+              vt102_parse (&c, buf, red);
+            }
+        }
 
+      ansi_dispatch (&a, &c);
+      ansi_update (&a, &c);
+    }
 
+  clients_shutdown (clients);
+  ansi_terminal_reset (&a);
+  terminal_atexit ();
+  printf ("QUAT\n");
 }