1

I was reading this post where someone mentions the ability to get notifications when a socket is ready to read instead of getting a notification when reading is finished - by submitting a 0 sized buffer.

...
WSABUF DataBuf;
DataBuf.len = 0;
DataBuf.buf = NULL;
...
rc = WSARecv(ConnSocket, &DataBuf, 1, &RecvBytes, &Flags, &RecvOverlapped, NULL);

However, I couldn't find anything in the documentation about that so I am a bit worried. Is this common practice and safe to do?

Julius
  • 1,155
  • 9
  • 19
  • Check [ IO completion ports](https://learn.microsoft.com/en-us/windows/win32/fileio/i-o-completion-ports) – Victor Gubin Jul 31 '19 at 11:43
  • @VictorGubin Thanks! I was looking at that but I couldn't find any related information – Julius Jul 31 '19 at 11:50
  • what sense at all pass zero size buffer ? just pass not empty buffer – RbMm Jul 31 '19 at 14:51
  • and anyway in all case you only got notify when I/O complete. no any sense in 0 buffer – RbMm Jul 31 '19 at 14:53
  • @RbMm mostly for portability (compatibility with epoll and the like) – Julius Jul 31 '19 at 15:01
  • i nothing understand in portability and are exist sense in this, but all this absolute unrelated to IOCP. *IOCP can sort of emulate readiness notification* - absolute senseless and wrong assumption. iocp nothing emulate. never. simply when I/O on file object complete and file object is bind to IOCP - packet queued to this IOCP. if you begin asynchronous I/O via `WSARecv` - when it finished - you got notification to IOCP. are you pass 0 or not 0 buffer - how here related at all ?! notification will be when io finished (if it not synchronous fail do invalid parameter/handle) – RbMm Jul 31 '19 at 15:19
  • you confuse completely different and unrelated things. if file is bind to IOCP and I/O operation finished on this file - you got notification via IOCP. all. what is I/O operation, what buffers you pass, are I/O operation at all have buffers - unrelate here at all. pass emprty buffers i sure no sense - because in this case you need again call recv with not empty buffers. what sense do this, when you from begin can begin I/O operation with not empty buffers ? it will complete at the same time, if you use empty buffers. simply if case empty buffers need 2 I/O operation instead 1. – RbMm Jul 31 '19 at 15:27
  • 1
    so in short - readiness notification not exist at all. iocp here unrelated. use empty buffers - have no any sense – RbMm Jul 31 '19 at 15:39
  • I don't know Julius's use case but there are use cases where a readiness indication rather than a completion indication would be useful. My concrete example is trying to us a library which does asynchronous network operations itself but allows hooking in a "readiness provider". Things like `select()`, `poll()`, `epoll()`, and `kqueue()` can do that naturally. io_uring does support `poll` as an operation. On Windows it seems the proper way is to use completion ports but without a readiness signal the library can't be used. – Dietmar Kühl Jul 26 '23 at 18:09

0 Answers0