diff options
author | Daniel Stenberg <daniel@haxx.se> | 2011-08-14 23:26:09 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2011-08-14 23:30:15 +0200 |
commit | 44b44a751d07b42b4546e3d856a6e761f46dbf63 (patch) | |
tree | 5238d732f544116e4c420cd973e436415d4c9305 /lib | |
parent | 2828b8ef9e277e0e57d15f36be9aa95894aacfa1 (diff) |
telnet: allow programatic use on Windows
Summary of the issue can be found at:
http://curl.haxx.se/mail/lib-2010-04/0367.html
That patch only updated the unix sockets code - the winsock code was not
updated and no longer works the same was as the unix code. This change
updates the windows code accordingly.
Bug: http://curl.haxx.se/bug/view.cgi?id=3163118
Diffstat (limited to 'lib')
-rw-r--r-- | lib/telnet.c | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/lib/telnet.c b/lib/telnet.c index 91725a062..ebd47ebae 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -1227,13 +1227,6 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done) return CURLE_FAILED_INIT; } - /* The get the Windows file handle for stdin */ - stdin_handle = GetStdHandle(STD_INPUT_HANDLE); - - /* Create the list of objects to wait for */ - objs[0] = event_handle; - objs[1] = stdin_handle; - /* Tell winsock what events we want to listen to */ if(event_select_func(sockfd, event_handle, FD_READ|FD_CLOSE) == SOCKET_ERROR) { @@ -1242,9 +1235,17 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done) return CURLE_OK; } + /* The get the Windows file handle for stdin */ + stdin_handle = GetStdHandle(STD_INPUT_HANDLE); + + /* Create the list of objects to wait for */ + objs[0] = event_handle; + objs[1] = stdin_handle; + /* If stdin_handle is a pipe, use PeekNamedPipe() method to check it, else use the old WaitForMultipleObjects() way */ - if(GetFileType(stdin_handle) == FILE_TYPE_PIPE) { + if(GetFileType(stdin_handle) == FILE_TYPE_PIPE || + data->set.is_fread_set) { /* Don't wait for stdin_handle, just wait for event_handle */ obj_count = 1; /* Check stdin_handle per 100 milliseconds */ @@ -1262,20 +1263,41 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done) case WAIT_TIMEOUT: { for(;;) { - if(!PeekNamedPipe(stdin_handle, NULL, 0, NULL, &readfile_read, NULL)) { - keepon = FALSE; - code = CURLE_READ_ERROR; - break; + if(obj_count == 1) { + /* read from user-supplied method */ + code = (int)conn->fread_func(buf, 1, BUFSIZE - 1, conn->fread_in); + if(code == CURL_READFUNC_ABORT) { + keepon = FALSE; + code = CURLE_READ_ERROR; + break; + } + + if(code == CURL_READFUNC_PAUSE) + break; + + if(code == 0) /* no bytes */ + break; + + readfile_read = code; /* fall thru with number of bytes read */ } + else { + /* read from stdin */ + if(!PeekNamedPipe(stdin_handle, NULL, 0, NULL, + &readfile_read, NULL)) { + keepon = FALSE; + code = CURLE_READ_ERROR; + break; + } - if(!readfile_read) - break; + if(!readfile_read) + break; - if(!ReadFile(stdin_handle, buf, sizeof(data->state.buffer), - &readfile_read, NULL)) { - keepon = FALSE; - code = CURLE_READ_ERROR; - break; + if(!ReadFile(stdin_handle, buf, sizeof(data->state.buffer), + &readfile_read, NULL)) { + keepon = FALSE; + code = CURLE_READ_ERROR; + break; + } } code = send_telnet_data(conn, buf, readfile_read); |