0

I'm programming a server in Windows. I wanted to accept multiple connections on the server so I figured I could use CygWin's fork(). So I added the call to fork(), but ran into errors.

I realize these errors are caused by the fact that I want to call the Windows Socket API (WSA) socketing functions (e.g. socket, bind, accept) but when I compile with CygWin it's calling its own socketing functions.

My question: How can I use CygWin's fork but still use the WSA's socket, accept, and bind?

DEADBEEF
  • 525
  • 1
  • 5
  • 19
  • 1
    What `fork` is to do with that? You want the `winsock` functions, so include it and use them. – Eugene Sh. Mar 21 '17 at 16:59
  • @EugeneSh. The WSA functions are named the exact same as the CygWin socketing ones. – DEADBEEF Mar 21 '17 at 17:05
  • 2
    If I understand you correctly, you've brought in Cygwin for no other reason than that you want `fork()`. That's a crummy reason. When you are writing for Windows, use Windows idioms, and forking is not among those. Cygwin is most applicable to cases where you're trying to adapt existing POSIX-oriented software written to Windows. – John Bollinger Mar 21 '17 at 17:09
  • @JohnBollinger I can't find another good way to implement a server that accepts multiple clients... – DEADBEEF Mar 21 '17 at 19:24
  • Have you not considered using threads instead of completely separate processes? – John Bollinger Mar 21 '17 at 19:28
  • @JohnBollinger No, actually... could you link to an example/tutorial? – DEADBEEF Mar 22 '17 at 03:59
  • @JohnBollinger Calling WinAPI in Cygwin apps should work. – yugr Mar 22 '17 at 10:28
  • I never said that it wouldn't, @yugr. But that doesn't change the fact that CygWin is the wrong tool for developing Windows-specific programs. – John Bollinger Mar 22 '17 at 14:07
  • @Lͬͬ̓̈́ͧͣ̽Oͭ̇͂͋̊̆͑ͧ͆͆ͫͬLͣͩ͗̾͐̚, requests for references to off-site tutorials are off-topic here. Lest I be too indirect, however, I assert that spawning a separate *thread* to handle interaction with each client is a much more natural approach in Windows than is spawning a whole separate *process* for that purpose. I am sure your Google-fu is strong enough to find resources discussing multi-threaded programming with the Windows API. – John Bollinger Mar 22 '17 at 14:14
  • @JohnBollinger I'm not sure what "Windows-specific program" is. Using WinSock on occasion should not preclude one from using Cygwin (there's even an [entry](http://pipeline.lbl.gov/code/3rd_party/licenses.win/cygwin-doc-1.4/html/faq/index.html#faq.api.winsock) in Cygwin's FAQ about this). – yugr Mar 22 '17 at 16:08
  • @LOL Have you checked [the FAQ](http://pipeline.lbl.gov/code/3rd_party/licenses.win/cygwin-doc-1.4/html/faq/index.html#faq.api.winsock)? – yugr Mar 22 '17 at 16:09

0 Answers0