Created
January 28, 2018 05:36
-
-
Save randy3k/c2de86cf23312c0fdd505522c73240b2 to your computer and use it in GitHub Desktop.
use PeekNamedPipe to check bytes available
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <windows.h> | |
| #include <stdio.h> | |
| #include <stdbool.h> | |
| #define BUFSIZE 1024 | |
| int main(int ac, char** av) { | |
| HANDLE h = GetStdHandle(STD_INPUT_HANDLE); | |
| DWORD rd; | |
| CHAR chBuf[BUFSIZE]; | |
| DWORD dwRead; | |
| bool bSuccess = FALSE; | |
| while(1) { | |
| if (!PeekNamedPipe(h, NULL, 0, NULL, &rd, NULL)) { | |
| printf("eof\n"); | |
| return 1; | |
| } | |
| if (rd > 0) { | |
| ReadFile(h, chBuf, BUFSIZE, &dwRead, NULL); | |
| chBuf[dwRead] = '\0'; | |
| printf("dwRead: %d\n", dwRead); | |
| printf("read: %s\n", chBuf); | |
| Sleep(1000); | |
| } else { | |
| Sleep(1000); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment