diff --git a/windows/winhandl.c b/windows/winhandl.c index 7a3cce35..222e5b93 100644 --- a/windows/winhandl.c +++ b/windows/winhandl.c @@ -102,6 +102,7 @@ static DWORD WINAPI handle_input_threadfunc(void *param) struct handle_input *ctx = (struct handle_input *) param; OVERLAPPED ovl, *povl; HANDLE oev; + int readlen; if (ctx->flags & HANDLE_FLAG_OVERLAPPED) { povl = &ovl; @@ -110,12 +111,17 @@ static DWORD WINAPI handle_input_threadfunc(void *param) povl = NULL; } + if (ctx->flags & HANDLE_FLAG_UNITBUFFER) + readlen = 1; + else + readlen = sizeof(ctx->buffer); + while (1) { if (povl) { memset(povl, 0, sizeof(OVERLAPPED)); povl->hEvent = oev; } - ctx->readret = ReadFile(ctx->h, ctx->buffer, sizeof(ctx->buffer), + ctx->readret = ReadFile(ctx->h, ctx->buffer, readlen, &ctx->len, povl); if (povl && !ctx->readret && GetLastError() == ERROR_IO_PENDING) { WaitForSingleObject(povl->hEvent, INFINITE); diff --git a/windows/winser.c b/windows/winser.c index f50eea13..21ff9a24 100644 --- a/windows/winser.c +++ b/windows/winser.c @@ -241,7 +241,8 @@ static const char *serial_init(void *frontend_handle, void **backend_handle, HANDLE_FLAG_OVERLAPPED); serial->in = handle_input_new(serport, serial_gotdata, serial, HANDLE_FLAG_OVERLAPPED | - HANDLE_FLAG_IGNOREEOF); + HANDLE_FLAG_IGNOREEOF | + HANDLE_FLAG_UNITBUFFER); *realhost = dupstr(cfg->serline); diff --git a/windows/winstuff.h b/windows/winstuff.h index 9244c75c..08ebb043 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -410,6 +410,7 @@ void init_ucs(Config *, struct unicode_data *); */ #define HANDLE_FLAG_OVERLAPPED 1 #define HANDLE_FLAG_IGNOREEOF 2 +#define HANDLE_FLAG_UNITBUFFER 3 struct handle; typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len); typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);