I can use WSASend()
in blocking mode if I do not supply an overlapped structure or a completion routine when I call it. But my question is: does a blocking WSASend()
call causes a notification packet to be placed in the completion port?
Asked
Active
Viewed 184 times
0

John
- 1,049
- 1
- 14
- 34
2 Answers
3
The question is ill-formed. We've been over all this several times in your previous questions, such as here. Either there is no completion routine and no overlapped structure, in which case there is no completion packet either, or there is, in which case you're not in blocking mode at all, you're in asynchronous mode.

Community
- 1
- 1

user207421
- 305,947
- 44
- 307
- 483
-
3This is not related to my previous question! I am talking about a socket that is associated with a completion port, but which I want to use `WSASend()` in blocking mode, while using `WSARecv()` in Overlapped mode. – John Feb 25 '15 at 22:25
-
1So if there is no completion routine/overlapped structure there is no completion packet. Surely this is obvious?. – user207421 Feb 25 '15 at 22:43
-
Yes I know, but I thought that the socket has recorded information that it is associated with a completion port. – John Feb 25 '15 at 22:43
-
Anyway, I guess that this is not documented. – John Feb 25 '15 at 22:45
-
1Because there is nothing to document. See the extract that was posted in previous answers. – user207421 Feb 25 '15 at 22:46
-
1Is there a problem in calling `WSASend()` in blocking mode while using `WSARecv()` in overlapped mode? – John Feb 25 '15 at 22:47
-
I don't see why, and there is no documentation to suggest that. But mixing modes is a strange thing to be doing. – user207421 Feb 25 '15 at 22:51
-
There is no reason for me to use `WSASend()` in overlapped mode, it will just complicate things (for example sending of files will be much more complicated to implement). – John Feb 25 '15 at 22:54
-
If you are using a completion port, you should be using `WSASend()` asynchronously. If you need a synchronous send without a completion packet, use `send()` instead. – Remy Lebeau Feb 26 '15 at 02:26
-
@Remy Lebeau What I want is to use a completion port for the receiving and a blocking mode for the sending. So are you telling me that I can do that with `send()` and `WSARecv()` at the same time? (Note: I heard that it is not a good idea to mix the WSA functions with the original Winsock functions, as they were not meant to work together). – John Feb 26 '15 at 02:39
-
@John: You really should not be mixing methodologies. Either do everything in blocking, or everything in IOCP. Not both. If you really want the calling thread to wait until `WSASend()` finishes, use a `WSAOVERLAPPED` with an event object and no completion routine: "If the lpCompletionRoutine parameter is NULL, the hEvent parameter of lpOverlapped is signaled when the overlapped operation completes if it contains a valid event object handle. An application can use WSAWaitForMultipleEvents or WSAGetOverlappedResult to wait or poll on the event object." – Remy Lebeau Feb 26 '15 at 03:04
2
If your socket is registered with a completion port, you can still make blocking calls by passing NULL
to the completion routine and the OVERLAPPED
structure parameters. And you will not receive a notification (even though your socket is registered with a completion port). However I do not know if it is recommended to use WSASend()
in blocking mode and WSARecv()
in overlapped mode at the same time.
-
How can you receive notification if you have not provided a completion routine OR an `OVERLAPPED` structure. One or the other is REQUIRED to provide notification. So your answer is correct, you will NOT receive a notification. – Len Holgate Feb 27 '15 at 12:08
-
It's useful to use blocking calls to `WSARecv()` as part of a design which minimises the number of locked pages which can be useful in maximising the number of concurrent connections that you can support (more so on older operating systems). In this scenario you would post "zero byte" overlapped `WSARecv()`s and then when these complete you could post a blocking `WSARecv()` to retrieve the data that you KNOW will be immediately available. See Network Programming for Microsoft Windows (2nd Ed) for more details. – Len Holgate Feb 27 '15 at 12:11
-
-
I refer you to my first comment. The edit doesn't make your question any less strange. How do you expect a completion to be reported to you via the IOCP if you haven't supplied an `OVERLAPPED` structure? Since the overlapped structure is the only "per operation" data for overlapped I/O operations there is NO WAY to match an API call that initiated an operation to a completion for that operation if you don't have an overlapped structure for it. So it's impossible to have a completion if you don't have an overlapped structure passed to the original API call. – Len Holgate Feb 27 '15 at 15:59