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
This commit is contained in:
parent
2828b8ef9e
commit
44b44a751d
60
lib/telnet.c
60
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user