开发者

Does TransmitFile work on pipes?

The docs for the TransmitFile winsock function do say "file" and not "file descriptor", so maybe the answer is no? If I can't use TransmitFile to se开发者_JAVA百科nd data from a pipe over a socket, is there some other zero-copy technique I can use?


To do a manual zero copy transmission you need to open both the socket and the file in overlapped mode and associate them with an IO completion port. You then issue a read on the file and when the file read completes you pass the buffer that was filled to a write on the socket. You can then probably tune this by adjusting the send buffer size on the socket to prevent copying and by selecting the correct flags when you open the file.

Be aware that you should probably use the subsequent socket write completion to drive your file reads. That is, don't keep issuing a new read when the old one completes as the TCP stack will likely end up doing flow control due to the TCP window becoming full and at that point you'll be using up non paged pool as your socket writes take longer and longer to complete (see here for more details). So decide on the number of outstanding socket writes that you'll allow per connection and throttle your reads when that number is reached, that is, switch from read on read completion to read on write completion...

Note that this isn't as effective as using TransmitFile() itself as that avoids the kernel to user transitions that occur to notify you of the read completion and to issue the write call.

In answer to the first part of your question, what happens if you try?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜