views:

535

answers:

2

There is a multiplayer card game which I had first programmed as a non-forking socket server in C (using poll() call).

Then it was too difficult for me to add new features and I've switched to Perl (using IO::Poll module).

As Perl doesn't support readv()/writev(), requires more memory/CPU and also isn't very commercial (I'd like to sell my game later), I would like to port my server back to C++ in future - once my features stabilize. (C++ this time because there are few objects in my server).

Could anyone please supply me with an example, how to use readv(), writev() and poll() or select() under C++? I know how to use those under Perl and C, but I haven't found any examples for C++ yet.

My environment: I'm using OpenBSD with its gcc/g++ and I'd like my server to run under Linux as well. I'd prefer not to use any unusual libraries (like libevent?) unless they work under Windows too - because maybe in the future I want to port my server to Windows too (for that I think I'll have to switch back from poll() to select() and add few Winsock functions?).

Please let me add that I like both Perl and C and I respect C++ very much, so this question is not about which language or OS is better. My question is: how to use poll() with C++

Thank you! Alex

+1  A: 

The functions readv(), writev(), and poll() work the same way in C++ as they do in C.

mark4o
There isn't any difference between the C functions and the C++ functions in this case. You'll often find that's the case (not always) but very often.
Daniel Bingham
+1  A: 

C++ handles them exactly the same as C -- Here's a tutorial to get you started.

However, since you're writing it in C++, I'd strongly advise you to take a look at the powerful alternatives, like the Boost.Asio framework. Believe me, you'll save a lot of time and nerves in implementing a server using Asio.

Kornel Kisielewicz