I'm new with winapi and have problem with pipes. I'm creating pipes with
wVersionRequested = MAKEWORD(2, 2);
_pipe(&fd, 65536, 0);
FD_SET((unsigned int) (fd), (&set));
time.tv_sec = 1;
time.tv_usec = 0;
int kua = select(0, &set, NULL, NULL, &time);
printf("last ->%d\n", WSAGetLastError());
_pipe(fd, 65536, 0);
On most platforms, pipes and sockets are both represented using file descriptors, and as such both can be used with file I/O functions that operate on file descriptors, including
However, on Windows, sockets and pipes are distinct object types, and are not represented using file descriptors at all.
select() only supports sockets, not files or pipes. That is why you are getting error 10038, aka
Socket operation on nonsocket.
An operation was attempted on something that is not a socket. Either the socket handle parameter did not reference a valid socket, or for select, a member of an fd_set was not valid.
There is no equivalent of
select() for pipe objects created by
_pipe(). All you can do is read and write.
If you need to detect when data arrives on a pipe before reading it, use
PeekNamedPipe() instead of
_pipe(). Otherwise, consider using Overlapped I/O or an I/O Completion Port instead. That will allow you to start an asynchronous read operation in the background and let it notify you when it has received data.