Jump to content
  • Advertisement
Sign in to follow this  
Afr0m@n

Filling in an fd_set array

This topic is 4607 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 fill in an fd_set array because I'm trying to learn how to build a simple select() based server for my MMO (I'll change it to IOCP later on). Here's my code:
#include "Global.h"

bool AccountLogIn(int id, SOCKET s_arr[64])
{
	JPlayer p;
	fd_set socket_set;
	
	p.id = id;

	socket_set.fd_count = id;
	socket_set.fd_array = s_arr[64];

	return true;
}
}

Doing this gives me this error:
--------------------Configuration: Server - Win32 Debug--------------------
Compiling...
AccountLogIn.cpp
C:\Programs\C++\WinSock\Server\AccountLogIn.cpp(11) : error C2440: '=' : cannot convert from 'unsigned int' to 'unsigned int [64]'
        There are no conversions to array types, although there are conversions to references or pointers to arrays
main.cpp
C:\Programs\C++\WinSock\Server\main.cpp(76) : error C2660: 'AccountLogIn' : function does not take 2 parameters
Error executing cl.exe.

Server.exe - 2 error(s), 0 warning(s)


What I'm wondering about is the first error, because I'm positive that the latter one will go away when the first one does. I need a way to pass an array to this function, it seems. How would I do that? Passing it this way, which seems to be the correct one, gives me this error. Passing it as "s_arr[]" gives me yet another error complaining about the function itself and so on. :( Edit: Also, is there a way to pass, for example, all the sockets but the first one (the zero'th element in the s_arr array) to the fd_set array?

Share this post


Link to post
Share on other sites
Advertisement
You shouldn't manipulate fd_set structures like that. Instead you should use the FD_SET(), FD_CLR(), FD_ISSET() and FD_ZERO() macros.

Share this post


Link to post
Share on other sites
Thanks!

Any information on how to do this? Parameters etc..

Doesn't seem to be any info on this in MSDN?

Share this post


Link to post
Share on other sites
Ok, I've only really got one question now so I couldn't be bothered to create a new thread for it;

Is there a way to convert from char[] to std::str? I really need to know, because quite frankly I'm fed up with using char[]. Everything works well so far, I just need to know this because WinSocks's recv() function takes a char[] as a parameter for a buffer.

Here's the code so far:

#include "Global.h"

bool AccountLogIn(int id, SOCKET s)
{
JPlayer p;
std::string buf;

p.id = id;

recv(s, (char) buf, sizeof(buf), MSG_PEEK);
if(buf == "ACCOUNTEXISTS")
{
std::cout << "Recieved message!";
}

return true;
}


This is the error that I'm getting:

--------------------Configuration: Server - Win32 Debug--------------------
Compiling...
AccountLogIn.cpp
C:\Programs\C++\WinSock\Server\AccountLogIn.cpp(10) : error C2440: 'type cast' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

Server.exe - 1 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
First, please post this in the appropriate forum; something like General Programming.

Second, if you read the error message, it explains exactly what the problem is.

Share this post


Link to post
Share on other sites

This topic is 4607 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.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!