Jump to content
  • Advertisement
Sign in to follow this  
Fourty_Two

(solved) Treating sockets like files in win32?

This topic is 5398 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to create a log system that can output to any stream source; files, console, com ports, sockets, or whatever else the user wants. For the first three its no big deal, they can all be accessed using handles, but I don't know about sockets. Is there anyway to make the socket act just like a file handle and send raw text using ReadFile and WriteFile? MSDN had it in there, just hidden. Like always.

Share this post


Link to post
Share on other sites
Advertisement
Out of interest, what did you do? I just tried casting the SOCKET to a HANDLE, and I got Error 87; "The parameter is incorrect." Perhaps because it needs to be an async write?

EDIT: Yup, it works fine if you do an overlapped write and just wait for it to finish immediately.

Share this post


Link to post
Share on other sites
IIRC one incurs a big performance hit by treating sockets like handles in Win32. IIRC it has to make a transition that goes something like user (your code) -> kernel (ReadFile) -> user (winsock) -> kernel (TDI) -> user (your code), versus Winsock calls which go user (your code) -> user (winsock) -> kernel (TDI) -> user (your code).

Share this post


Link to post
Share on other sites
I got around this by creating a new iostream which simply sends to a socket instead of writing to a file.

Question is; what programming language are you using?

Share this post


Link to post
Share on other sites
Quote:
Original post by JY
Question is; what programming language are you using?
C++ going by the references to the MSDN, ReadFile() and WriteFile().

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!