chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / serial.c
index dbd82066b4ab036d1ed3186df0ca9efa1ec0ccbe..e269c83b8e44073c641127d5b007f5fc2ce96fe1 100644 (file)
@@ -10,6 +10,27 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.12  2008/02/28 16:57:52  james
+ * *** empty log message ***
+ *
+ * Revision 1.11  2008/02/26 23:23:17  james
+ * *** empty log message ***
+ *
+ * Revision 1.10  2008/02/24 00:47:14  james
+ * *** empty log message ***
+ *
+ * Revision 1.9  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
+ * Revision 1.8  2008/02/23 13:05:58  staffcvs
+ * *** empty log message ***
+ *
+ * Revision 1.7  2008/02/15 23:52:12  james
+ * *** empty log message ***
+ *
+ * Revision 1.6  2008/02/15 19:51:30  james
+ * *** empty log message ***
+ *
  * Revision 1.5  2008/02/15 19:09:00  james
  * *** empty log message ***
  *
@@ -60,31 +81,14 @@ static char rcsid[] = "$Id$";
 #include <sys/stat.h>
 
 
-
-typedef struct
-{
-  int mode;
-  int i;
-
-  struct timeval last_stale_purge;
-  Filelist locks_to_check;
-  Filelist locks_held;
-} Serial_lock;
-
 typedef struct
 {
   TTY_SIGNATURE;
-  Serial_lock lock;
+  Serial_lock *lock;
   int fd;
 } Serial;
 
 
-static void
-serial_check_lock (Serial * t)
-{
-}
-
-
 static void
 serial_close (TTY * _t)
 {
@@ -93,19 +97,20 @@ serial_close (TTY * _t)
   if (!t)
     return;
 
+  tcflush (t->fd, TCIOFLUSH);
   close (t->fd);
   free (t);
 }
 
 
-
 static int
 serial_read (TTY * _t, void *buf, int len)
 {
   Serial *t = (Serial *) _t;
   int red, done = 0;
 
-  serial_check_lock (t);
+  t->blocked = serial_lock_check (t->lock);
+
   if (t->blocked)
     return 0;
 
@@ -130,12 +135,12 @@ serial_read (TTY * _t, void *buf, int len)
 
 
 static int
-ptty_write (TTY * _t, void *buf, int len)
+serial_write (TTY * _t, void *buf, int len)
 {
   int writ, done = 0;
   Serial *t = (Serial *) _t;
 
-  serial_check_lock (t);
+  t->blocked = serial_lock_check (t->lock);
   if (t->blocked)
     return 0;
 
@@ -159,7 +164,7 @@ ptty_write (TTY * _t, void *buf, int len)
 }
 
 TTY *
-serial_open (char *path)
+serial_open (char *path, int lock_mode)
 {
   Serial *t;
   pid_t child;
@@ -167,28 +172,48 @@ serial_open (char *path)
   struct winsize winsize = { 0 };
   struct termios termios;
   int fd;
+  Serial_lock *l;
 
+  l = serial_lock_new (path, lock_mode);
+  if (!l)
+    return NULL;
 
-  default_termios (&termios);
 
-  fd = open (path, O_RDWR);
+  fd = open (path, O_RDWR | O_NOCTTY | O_NONBLOCK);
 
   set_nonblocking (fd);
 
+
+  if (tcgetattr (fd, &termios))
+    {
+      close (fd);
+      return NULL;
+    }
+  default_termios (&termios);
+
+  if (tcsetattr (fd, TCSANOW, &termios))
+    {
+      close (fd);
+      return NULL;
+    }
+
   t = (Serial *) malloc (sizeof (Serial));
 
+  t->lock = l;
+
   strncpy (t->name, path, sizeof (t->name));
   t->name[sizeof (t->name) - 1] = 0;
 
   t->recv = serial_read;
-  //t->xmit = serial_write;
+  t->xmit = serial_write;
   t->close = serial_close;
   t->fd = fd;
   t->rfd = t->fd;
   t->wfd = t->fd;
-  t->size.x = VT102_COLS;
-  t->size.y = VT102_ROWS;
-  t->blocked = 0;
+  t->size.x = VT102_COLS_80;
+  t->size.y = VT102_ROWS_24;
+  t->blocked = serial_lock_check (t->lock);
+  t->hanging_up = 0;
 
   return (TTY *) t;
 }