Commit 087f4ae0786948e83429f0a3dc062436da433c0f
1 parent
b63891a0
Clean up serial code for Win 32, by Kazu.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2409 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
33 additions
and
30 deletions
vl.c
... | ... | @@ -1874,7 +1874,6 @@ static CharDriverState *qemu_chr_open_pty(void) |
1874 | 1874 | |
1875 | 1875 | #ifdef _WIN32 |
1876 | 1876 | typedef struct { |
1877 | - CharDriverState *chr; | |
1878 | 1877 | int max_size; |
1879 | 1878 | HANDLE hcom, hrecv, hsend; |
1880 | 1879 | OVERLAPPED orecv, osend; |
... | ... | @@ -1890,8 +1889,10 @@ typedef struct { |
1890 | 1889 | static int win_chr_poll(void *opaque); |
1891 | 1890 | static int win_chr_pipe_poll(void *opaque); |
1892 | 1891 | |
1893 | -static void win_chr_close2(WinCharState *s) | |
1892 | +static void win_chr_close(CharDriverState *chr) | |
1894 | 1893 | { |
1894 | + WinCharState *s = chr->opaque; | |
1895 | + | |
1895 | 1896 | if (s->hsend) { |
1896 | 1897 | CloseHandle(s->hsend); |
1897 | 1898 | s->hsend = NULL; |
... | ... | @@ -1905,19 +1906,14 @@ static void win_chr_close2(WinCharState *s) |
1905 | 1906 | s->hcom = NULL; |
1906 | 1907 | } |
1907 | 1908 | if (s->fpipe) |
1908 | - qemu_del_polling_cb(win_chr_pipe_poll, s); | |
1909 | + qemu_del_polling_cb(win_chr_pipe_poll, chr); | |
1909 | 1910 | else |
1910 | - qemu_del_polling_cb(win_chr_poll, s); | |
1911 | + qemu_del_polling_cb(win_chr_poll, chr); | |
1911 | 1912 | } |
1912 | 1913 | |
1913 | -static void win_chr_close(CharDriverState *chr) | |
1914 | +static int win_chr_init(CharDriverState *chr, const char *filename) | |
1914 | 1915 | { |
1915 | 1916 | WinCharState *s = chr->opaque; |
1916 | - win_chr_close2(s); | |
1917 | -} | |
1918 | - | |
1919 | -static int win_chr_init(WinCharState *s, CharDriverState *chr, const char *filename) | |
1920 | -{ | |
1921 | 1917 | COMMCONFIG comcfg; |
1922 | 1918 | COMMTIMEOUTS cto = { 0, 0, 0, 0, 0}; |
1923 | 1919 | COMSTAT comstat; |
... | ... | @@ -1974,12 +1970,11 @@ static int win_chr_init(WinCharState *s, CharDriverState *chr, const char *filen |
1974 | 1970 | fprintf(stderr, "Failed ClearCommError\n"); |
1975 | 1971 | goto fail; |
1976 | 1972 | } |
1977 | - s->chr = chr; | |
1978 | - qemu_add_polling_cb(win_chr_poll, s); | |
1973 | + qemu_add_polling_cb(win_chr_poll, chr); | |
1979 | 1974 | return 0; |
1980 | 1975 | |
1981 | 1976 | fail: |
1982 | - win_chr_close2(s); | |
1977 | + win_chr_close(chr); | |
1983 | 1978 | return -1; |
1984 | 1979 | } |
1985 | 1980 | |
... | ... | @@ -2017,14 +2012,17 @@ static int win_chr_write(CharDriverState *chr, const uint8_t *buf, int len1) |
2017 | 2012 | return len1 - len; |
2018 | 2013 | } |
2019 | 2014 | |
2020 | -static int win_chr_read_poll(WinCharState *s) | |
2015 | +static int win_chr_read_poll(CharDriverState *chr) | |
2021 | 2016 | { |
2022 | - s->max_size = qemu_chr_can_read(s->chr); | |
2017 | + WinCharState *s = chr->opaque; | |
2018 | + | |
2019 | + s->max_size = qemu_chr_can_read(chr); | |
2023 | 2020 | return s->max_size; |
2024 | 2021 | } |
2025 | 2022 | |
2026 | -static void win_chr_readfile(WinCharState *s) | |
2023 | +static void win_chr_readfile(CharDriverState *chr) | |
2027 | 2024 | { |
2025 | + WinCharState *s = chr->opaque; | |
2028 | 2026 | int ret, err; |
2029 | 2027 | uint8_t buf[1024]; |
2030 | 2028 | DWORD size; |
... | ... | @@ -2040,31 +2038,34 @@ static void win_chr_readfile(WinCharState *s) |
2040 | 2038 | } |
2041 | 2039 | |
2042 | 2040 | if (size > 0) { |
2043 | - qemu_chr_read(s->chr, buf, size); | |
2041 | + qemu_chr_read(chr, buf, size); | |
2044 | 2042 | } |
2045 | 2043 | } |
2046 | 2044 | |
2047 | -static void win_chr_read(WinCharState *s) | |
2045 | +static void win_chr_read(CharDriverState *chr) | |
2048 | 2046 | { |
2047 | + WinCharState *s = chr->opaque; | |
2048 | + | |
2049 | 2049 | if (s->len > s->max_size) |
2050 | 2050 | s->len = s->max_size; |
2051 | 2051 | if (s->len == 0) |
2052 | 2052 | return; |
2053 | 2053 | |
2054 | - win_chr_readfile(s); | |
2054 | + win_chr_readfile(chr); | |
2055 | 2055 | } |
2056 | 2056 | |
2057 | 2057 | static int win_chr_poll(void *opaque) |
2058 | 2058 | { |
2059 | - WinCharState *s = opaque; | |
2059 | + CharDriverState *chr = opaque; | |
2060 | + WinCharState *s = chr->opaque; | |
2060 | 2061 | COMSTAT status; |
2061 | 2062 | DWORD comerr; |
2062 | 2063 | |
2063 | 2064 | ClearCommError(s->hcom, &comerr, &status); |
2064 | 2065 | if (status.cbInQue > 0) { |
2065 | 2066 | s->len = status.cbInQue; |
2066 | - win_chr_read_poll(s); | |
2067 | - win_chr_read(s); | |
2067 | + win_chr_read_poll(chr); | |
2068 | + win_chr_read(chr); | |
2068 | 2069 | return 1; |
2069 | 2070 | } |
2070 | 2071 | return 0; |
... | ... | @@ -2087,7 +2088,7 @@ static CharDriverState *qemu_chr_open_win(const char *filename) |
2087 | 2088 | chr->chr_write = win_chr_write; |
2088 | 2089 | chr->chr_close = win_chr_close; |
2089 | 2090 | |
2090 | - if (win_chr_init(s, chr, filename) < 0) { | |
2091 | + if (win_chr_init(chr, filename) < 0) { | |
2091 | 2092 | free(s); |
2092 | 2093 | free(chr); |
2093 | 2094 | return NULL; |
... | ... | @@ -2098,21 +2099,23 @@ static CharDriverState *qemu_chr_open_win(const char *filename) |
2098 | 2099 | |
2099 | 2100 | static int win_chr_pipe_poll(void *opaque) |
2100 | 2101 | { |
2101 | - WinCharState *s = opaque; | |
2102 | + CharDriverState *chr = opaque; | |
2103 | + WinCharState *s = chr->opaque; | |
2102 | 2104 | DWORD size; |
2103 | 2105 | |
2104 | 2106 | PeekNamedPipe(s->hcom, NULL, 0, NULL, &size, NULL); |
2105 | 2107 | if (size > 0) { |
2106 | 2108 | s->len = size; |
2107 | - win_chr_read_poll(s); | |
2108 | - win_chr_read(s); | |
2109 | + win_chr_read_poll(chr); | |
2110 | + win_chr_read(chr); | |
2109 | 2111 | return 1; |
2110 | 2112 | } |
2111 | 2113 | return 0; |
2112 | 2114 | } |
2113 | 2115 | |
2114 | -static int win_chr_pipe_init(WinCharState *s, const char *filename) | |
2116 | +static int win_chr_pipe_init(CharDriverState *chr, const char *filename) | |
2115 | 2117 | { |
2118 | + WinCharState *s = chr->opaque; | |
2116 | 2119 | OVERLAPPED ov; |
2117 | 2120 | int ret; |
2118 | 2121 | DWORD size; |
... | ... | @@ -2164,11 +2167,11 @@ static int win_chr_pipe_init(WinCharState *s, const char *filename) |
2164 | 2167 | CloseHandle(ov.hEvent); |
2165 | 2168 | ov.hEvent = NULL; |
2166 | 2169 | } |
2167 | - qemu_add_polling_cb(win_chr_pipe_poll, s); | |
2170 | + qemu_add_polling_cb(win_chr_pipe_poll, chr); | |
2168 | 2171 | return 0; |
2169 | 2172 | |
2170 | 2173 | fail: |
2171 | - win_chr_close2(s); | |
2174 | + win_chr_close(chr); | |
2172 | 2175 | return -1; |
2173 | 2176 | } |
2174 | 2177 | |
... | ... | @@ -2190,7 +2193,7 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename) |
2190 | 2193 | chr->chr_write = win_chr_write; |
2191 | 2194 | chr->chr_close = win_chr_close; |
2192 | 2195 | |
2193 | - if (win_chr_pipe_init(s, filename) < 0) { | |
2196 | + if (win_chr_pipe_init(chr, filename) < 0) { | |
2194 | 2197 | free(s); |
2195 | 2198 | free(chr); |
2196 | 2199 | return NULL; | ... | ... |