refactor: add a async read/write variant to device ops, with allow async io to be...
[lunaix-os.git] / lunaix-os / hal / term / lcntls / lcntl.c
index 435983040885070ed27120fa18263a17d38e0289..aab02c097974552ffd2eeeaaf2e5a8121adb7c00 100644 (file)
@@ -21,25 +21,7 @@ raise_sig(struct term* at_term, struct linebuffer* lbuf, int sig)
     lbuf->sflags |= LSTATE_SIGRAISE;
 }
 
-static inline int
-lcntl_invoke_slaves(struct term* tdev, struct linebuffer* lbuf, char c)
-{
-    int allow_more = 0;
-    struct term_lcntl *lcntl, *n;
-    llist_for_each(lcntl, n, &tdev->lcntl_stack, lcntls)
-    {
-        allow_more = lcntl->process_and_put(tdev, lbuf, c);
-        if (!allow_more) {
-            break;
-        }
-
-        line_flip(lbuf);
-    }
-
-    return allow_more;
-}
-
-static inline int optimize("ipa-cp-clone")
+static inline int must_inline optimize("-fipa-cp-clone")
 lcntl_transform_seq(struct term* tdev, struct linebuffer* lbuf, bool out)
 {
     struct rbuffer* raw = lbuf->current;
@@ -52,6 +34,9 @@ lcntl_transform_seq(struct term* tdev, struct linebuffer* lbuf, bool out)
     char c;
     bool should_flush = false;
 
+    int (*lcntl_slave_put)(struct term*, struct linebuffer*, char) =
+        tdev->lcntl->process_and_put;
+
 #define EOL tdev->cc[_VEOL]
 #define EOF tdev->cc[_VEOF]
 #define ERASE tdev->cc[_VERASE]
@@ -126,6 +111,8 @@ lcntl_transform_seq(struct term* tdev, struct linebuffer* lbuf, bool out)
             raise_sig(tdev, lbuf, SIGSTOP);
         } else if (c == ERASE) {
             rbuffer_erase(cooked);
+        } else if (c == KILL) {
+            // TODO shrink the rbuffer
         } else {
             goto keep;
         }
@@ -145,18 +132,19 @@ lcntl_transform_seq(struct term* tdev, struct linebuffer* lbuf, bool out)
         }
 
     put_char:
-        allow_more = rbuffer_put(cooked, c);
-    }
-
-    if (out || (_lf & _IEXTEN)) {
-        line_flip(lbuf);
-        lcntl_invoke_slaves(tdev, lbuf, c);
+        if (!out && (_lf & _IEXTEN) && lcntl_slave_put) {
+            allow_more = lcntl_slave_put(tdev, lbuf, c);
+        } else {
+            allow_more = rbuffer_put(cooked, c);
+        }
     }
 
     if (should_flush && !(_lf & _NOFLSH)) {
         term_flush(tdev);
     }
 
+    line_flip(lbuf);
+
     return i;
 }