mirror of
https://github.com/mintty/wsltty.git
synced 2025-01-18 20:10:58 +00:00
fix rebased patch; restore backend patch part
This commit is contained in:
parent
74dad091ce
commit
07aa6c692d
@ -1,5 +1,124 @@
|
|||||||
--- a/src/wslbridge2.cpp 2020-10-18 15:03:06.000000000 +0000
|
diff -rup old/src/wslbridge2-backend.cpp new/src/wslbridge2-backend.cpp
|
||||||
+++ b/src/wslbridge2.cpp 2021-02-26 17:45:28.437040700 +0000
|
--- old/src/wslbridge2-backend.cpp 2020-10-18 15:03:06.000000000 +0000
|
||||||
|
+++ new/src/wslbridge2-backend.cpp 2021-03-18 18:31:35.684184400 +0000
|
||||||
|
@@ -21,6 +21,7 @@
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <wordexp.h>
|
||||||
|
+#include <limits.h> // PIPE_BUF
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
@@ -321,6 +322,9 @@ int main(int argc, char *argv[])
|
||||||
|
/* Use dupped master fd to read OR write */
|
||||||
|
const int mfd_dp = dup(mfd);
|
||||||
|
assert(mfd_dp > 0);
|
||||||
|
+#ifdef debug_to_input
|
||||||
|
+ FILE * debug = fdopen(mfd_dp, "w"); // for fprintf
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
struct pollfd fds[] = {
|
||||||
|
{ ioSockets.inputSock, POLLIN, 0 },
|
||||||
|
@@ -330,6 +334,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
|
ssize_t readRet = 0, writeRet = 0;
|
||||||
|
char data[1024]; /* Buffer to hold raw data from pty */
|
||||||
|
+ assert(sizeof data <= PIPE_BUF);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
@@ -340,8 +345,86 @@ int main(int argc, char *argv[])
|
||||||
|
if (fds[0].revents & POLLIN)
|
||||||
|
{
|
||||||
|
readRet = recv(ioSockets.inputSock, data, sizeof data, 0);
|
||||||
|
- if (readRet > 0)
|
||||||
|
- writeRet = write(mfd_dp, data, readRet);
|
||||||
|
+
|
||||||
|
+ char * s = data;
|
||||||
|
+ int len = readRet;
|
||||||
|
+ writeRet = 1;
|
||||||
|
+ while (writeRet > 0 && len > 0)
|
||||||
|
+ {
|
||||||
|
+ if (!*s)
|
||||||
|
+ {
|
||||||
|
+ // dispatch NUL escaped inband information
|
||||||
|
+ s++;
|
||||||
|
+ len--;
|
||||||
|
+
|
||||||
|
+ if (len < 9 && s + 9 >= data + sizeof data)
|
||||||
|
+ {
|
||||||
|
+ // make room for additional loading
|
||||||
|
+ memcpy(data, s, len);
|
||||||
|
+ s = data;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ // ensure 1 more byte is loaded to dispatch on
|
||||||
|
+ if (!len)
|
||||||
|
+ {
|
||||||
|
+ readRet = recv(ioSockets.inputSock, s, 1, 0);
|
||||||
|
+ if (readRet > 0)
|
||||||
|
+ {
|
||||||
|
+ len += readRet;
|
||||||
|
+ }
|
||||||
|
+ else
|
||||||
|
+ {
|
||||||
|
+ writeRet = -1;
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ if (*s == 2)
|
||||||
|
+ {
|
||||||
|
+ // STX: escaped NUL
|
||||||
|
+ s++;
|
||||||
|
+ len--;
|
||||||
|
+ writeRet = write(mfd_dp, "", 1);
|
||||||
|
+ }
|
||||||
|
+ else if (*s == 16)
|
||||||
|
+ {
|
||||||
|
+ // DLE: terminal window size change
|
||||||
|
+ s++;
|
||||||
|
+ len--;
|
||||||
|
+ // ensure 8 more bytes are loaded for winsize
|
||||||
|
+ while (readRet > 0 && len < 8)
|
||||||
|
+ {
|
||||||
|
+ readRet = recv(ioSockets.inputSock, s + len, 8 - len, 0);
|
||||||
|
+ if (readRet > 0)
|
||||||
|
+ {
|
||||||
|
+ len += readRet;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ if (readRet <= 0)
|
||||||
|
+ {
|
||||||
|
+ writeRet = -1;
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ struct winsize * winsp = (struct winsize *)s;
|
||||||
|
+ s += 8;
|
||||||
|
+ len -= 8;
|
||||||
|
+ winsp->ws_xpixel = 0;
|
||||||
|
+ winsp->ws_ypixel = 0;
|
||||||
|
+ ret = ioctl(mfd, TIOCSWINSZ, winsp);
|
||||||
|
+ if (ret != 0)
|
||||||
|
+ perror("ioctl(TIOCSWINSZ)");
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ else
|
||||||
|
+ {
|
||||||
|
+ int n = strnlen(s, len);
|
||||||
|
+ writeRet = write(mfd_dp, s, n);
|
||||||
|
+ if (writeRet > 0)
|
||||||
|
+ {
|
||||||
|
+ s += writeRet;
|
||||||
|
+ len -= writeRet;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Resize window when buffer received in control socket */
|
||||||
|
diff -rup old/src/wslbridge2.cpp new/src/wslbridge2.cpp
|
||||||
|
--- old/src/wslbridge2.cpp 2020-10-18 15:03:06.000000000 +0000
|
||||||
|
+++ new/src/wslbridge2.cpp 2021-02-26 17:45:28.437040700 +0000
|
||||||
@@ -57,32 +57,85 @@ union IoSockets
|
@@ -57,32 +57,85 @@ union IoSockets
|
||||||
/* global variable */
|
/* global variable */
|
||||||
static union IoSockets g_ioSockets = { 0, 0, 0 };
|
static union IoSockets g_ioSockets = { 0, 0, 0 };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user