chiark / gitweb /
@@
[sympathy.git] / src / serial.c
index 429c2e3771652165ff34b27adb5202dd0d5742c0..bd4450cfa92738e7fc0c0e30e67124179aa647a6 100644 (file)
@@ -10,6 +10,15 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * 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 ***
+ *
  * Revision 1.4  2008/02/15 16:48:56  james
  * *** empty log message ***
  *
@@ -56,29 +65,15 @@ static char rcsid[] = "$Id$";
 #include <dirent.h>
 #include <sys/stat.h>
 
-#define NLOCKFILES     10
-
-typedef struct
-{
-  char *lockfiles[NLOCKFILES];
-  char *potential_lockfiles[NLOCKFILES];
-  struct timeval last_content_check;
-} 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)
 {
@@ -87,19 +82,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;
 
@@ -124,12 +120,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;
 
@@ -153,7 +149,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;
@@ -161,28 +157,35 @@ 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);
 
   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->blocked = serial_lock_check (t->lock);
+  t->hanging_up = 0;
 
   return (TTY *) t;
 }